aboutsummaryrefslogtreecommitdiff
#!/bin/sh
### BEGIN INIT INFO
# Provides:          @hydrilla@
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Hydrilla repository server
# Description:       Provides HTTP service to serve packages for Haketilo
### END INIT INFO

# Copyright (C) 2020 Danny Milosavljevic, 2021 Wojtek Kosior
# Redistribution terms are gathered in the `copyright' file.

# This script has been adapted from:
# https://git.savannah.gnu.org/cgit/guix.git/tree/etc/init.d/guix-daemon.in

set -e
if [ ! -f "@bindir@/@hydrilla@" ]
then
  exit 5
fi

mkdir -p "@runstatedir@"
mkdir -p "@logdir@"

case "$1" in
start)
  if [ -f "@runstatedir@/@hydrilla@.pid" ]
  then
    if pgrep -F "@runstatedir@/@hydrilla@.pid" @hydrilla@
    then
      exit 0
    else
      echo "@hydrilla@ has a stale pid file" >&2
      exit 1
    fi
  else
    daemonize \
      -a \
      -e "@logdir@/@hydrilla@-stderr.log" \
      -o "@logdir@/@hydrilla@-stdout.log" \
      -p "@runstatedir@/@hydrilla@.pid" \
      -E "HYDRILLA_WAIT_SIGTERM=yes" \
      @bindir@/@hydrilla@
  fi
  ;;
stop)
  if [ -f "@runstatedir@/@hydrilla@.pid" ]
  then
    pkill -F "@runstatedir@/@hydrilla@.pid" @hydrilla@ || {
      exit 1
    }
    rm -f "@runstatedir@/@hydrilla@.pid"
    exit 0
  else
    exit 0
  fi
  ;;
status)
  if [ -f "@runstatedir@/@hydrilla@.pid" ]
  then
    if pgrep -F "@runstatedir@/@hydrilla@.pid" @hydrilla@
    then
      echo "@hydrilla@ is running"
      exit 0
    else
      echo "@hydrilla@ has a stale pid file"
      exit 1
    fi
  else
    echo "@hydrilla@ is not running"
    exit 3
  fi
  ;;
restart|force-reload)
  "$0" stop
  "$0" start
  ;;
*)
  echo "Usage: $0 (start|stop|status|restart|force-reload)"
  exit 3
  ;;
esac