]> git.proxmox.com Git - pve-sheepdog.git/blame - debian/pve-sheepdog.sheepdog.init.d
display status of all daemons
[pve-sheepdog.git] / debian / pve-sheepdog.sheepdog.init.d
CommitLineData
ff62b221
DM
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides: sheepdog
4# Required-Start: $network $remote_fs $syslog
5# Required-Stop: $network $remote_fs $syslog
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: Sheepdog server
9# Description: Sheepdog server
10### END INIT INFO
11
12# Author: Proxmox Support Team <support@proxmox.com>
13
14# PATH should only include /usr/* if it runs after the mountnfs.sh script
15PATH=/sbin:/usr/sbin:/bin:/usr/bin
16DESC="Sheepdog Server" # Introduce a short description here
17NAME=sheepdog # Introduce the short server's name here
18DAEMON=/usr/sbin/sheep # Introduce the server's location here
ff62b221
DM
19SCRIPTNAME=/etc/init.d/$NAME
20
21# Exit if the package is not installed
22[ -x $DAEMON ] || exit 0
23
75a10ce5 24# Defaults
a30f86c5
DM
25SHEEPDOG_START_SEQUENCE="_1"
26SHEEPDOG_DEAMON_ARGS_1=""
27SHEEPDOG_PATH_1="/var/lib/sheepdog/disc1"
75a10ce5 28
ff62b221
DM
29# Read configuration variable file if it is present
30[ -r /etc/default/$NAME ] && . /etc/default/$NAME
31
32if [ "$START" != "yes" ]; then
33 exit 0
34fi
35
ff62b221
DM
36. /lib/lsb/init-functions
37
38#
39# Function that starts the daemon/service
40#
41do_start()
42{
ff62b221
DM
43 mkdir -p /var/run
44
a30f86c5 45 # Return
ff62b221
DM
46 # 0 if daemon has been started
47 # 1 if daemon was already running
48 # 2 if daemon could not be started
75a10ce5 49
a30f86c5
DM
50 for SHEEP in $SHEEPDOG_START_SEQUENCE; do
51 eval DAEMON_ARGS=\$SHEEPDOG_DEAMON_ARGS$SHEEP
52 eval SHEEPDOG_PATH=\$SHEEPDOG_PATH$SHEEP
53 eval PIDFILE=/var/run/$NAME$SHEEP.pid
54
55 mkdir -p $SHEEPDOG_PATH
56
57 status_of_proc -p ${PIDFILE} $DAEMON "$NAME" >/dev/null && continue
75a10ce5 58
a30f86c5
DM
59 start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec $DAEMON -- --pidfile ${PIDFILE} $DAEMON_ARGS $SHEEPDOG_PATH || return 2
60 done
61
62 return 0
ff62b221
DM
63}
64
65#
66# Function that stops the daemon/service
67#
68do_stop()
69{
70 # Return
71 # 0 if daemon has been stopped
72 # 1 if daemon was already stopped
73 # 2 if daemon could not be stopped
74 # other if a failure occurred
ff62b221 75
a30f86c5
DM
76 RETVAL=0
77 for SHEEP in $SHEEPDOG_START_SEQUENCE; do
78 eval DAEMON_ARGS=\$SHEEPDOG_DEAMON_ARGS$SHEEP
79 eval SHEEPDOG_PATH=\$SHEEPDOG_PATH$SHEEP
80 eval PIDFILE=/var/run/$NAME$SHEEP.pid
81 start-stop-daemon --stop --oknodo --retry=TERM/20/KILL/5 --quiet --pidfile ${PIDFILE} --exec $DAEMON || RETVAL=2
82 done
75a10ce5 83
ff62b221
DM
84 return "$RETVAL"
85}
86
87case "$1" in
75a10ce5
DM
88 start)
89 log_daemon_msg "Starting $DESC " "$NAME"
90 do_start
91 case "$?" in
92 0|1) log_end_msg 0 ;;
93 2) log_end_msg 1 ;;
ff62b221 94 esac
75a10ce5
DM
95 ;;
96 stop)
97 log_daemon_msg "Stopping $DESC" "$NAME"
ff62b221
DM
98 do_stop
99 case "$?" in
75a10ce5
DM
100 0|1) log_end_msg 0 ;;
101 2) log_end_msg 1 ;;
ff62b221 102 esac
a30f86c5 103
ff62b221 104 ;;
75a10ce5 105 status)
3b5296eb 106 RETVAL=0
a30f86c5
DM
107 for SHEEP in $SHEEPDOG_START_SEQUENCE; do
108 eval DAEMON_ARGS=\$SHEEPDOG_DEAMON_ARGS$SHEEP
109 eval SHEEPDOG_PATH=\$SHEEPDOG_PATH$SHEEP
110 eval PIDFILE=/var/run/$NAME$SHEEP.pid
3b5296eb 111 status_of_proc -p ${PIDFILE} $DAEMON "$NAME${SHEEP}" || RETVAL=1
a30f86c5 112 done
3b5296eb 113 exit $RETVAL
75a10ce5
DM
114 ;;
115 restart|force-reload)
ff62b221
DM
116 log_daemon_msg "Restarting $DESC" "$NAME"
117 do_stop
118 case "$?" in
75a10ce5 119 0|1)
ff62b221
DM
120 do_start
121 case "$?" in
75a10ce5
DM
122 0) log_end_msg 0 ;;
123 1) log_end_msg 1 ;; # Old process is still running
124 *) log_end_msg 1 ;; # Failed to start
ff62b221
DM
125 esac
126 ;;
75a10ce5 127 *)
ff62b221
DM
128 # Failed to stop
129 log_end_msg 1
130 ;;
131 esac
132 ;;
75a10ce5 133 *)
ff62b221
DM
134 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
135 exit 3
136 ;;
137esac
138
139:
140