aboutsummaryrefslogtreecommitdiff
path: root/daemon/sysv.in
blob: 8e73d0eee01e72c11b7ee42f5cedc2c2bc627072 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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 Hachette
### 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