]> git.proxmox.com Git - pve-sheepdog.git/blame - debian/pve-sheepdog.sheepdog.init.d
new init.d script, now scans /var/lib/sheepdog/disk[0-9]/startup
[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
07e2d38c
DM
24DISKLIST=$(echo /var/lib/sheepdog/disc[0123456789])
25RDISKLIST=
26for dir in ${DISKLIST}; do
27 RDISKLIST="${dir} ${RDISKLIST}"
28done
75a10ce5 29
ff62b221
DM
30# Read configuration variable file if it is present
31[ -r /etc/default/$NAME ] && . /etc/default/$NAME
32
33if [ "$START" != "yes" ]; then
34 exit 0
35fi
36
ff62b221
DM
37. /lib/lsb/init-functions
38
39#
40# Function that starts the daemon/service
41#
42do_start()
43{
ff62b221
DM
44 mkdir -p /var/run
45
a30f86c5 46 # Return
ff62b221
DM
47 # 0 if daemon has been started
48 # 1 if daemon was already running
49 # 2 if daemon could not be started
75a10ce5 50
07e2d38c
DM
51 for dir in ${DISKLIST}; do
52 test -f "${dir}/startup" || continue
53 DAEMON_ARGS=$(head -n1 "${dir}/startup");
54 DISKID=${dir##/var/lib/sheepdog/disc}
55 PIDFILE="$dir/sheep.pid"
56 DAEMON_ARGS="${DAEMON_ARGS} --pidfile ${PIDFILE}"
57 if ! test "$(echo ${DAEMON_ARGS}|grep -c '\-p ')" -eq 1 ; then
58 DAEMON_ARGS="${DAEMON_ARGS} -p $((7000 + ${DISKID}))"
59 fi
a30f86c5 60
07e2d38c 61 status_of_proc -p ${PIDFILE} $DAEMON "$NAME" >/dev/null && continue
a30f86c5 62
07e2d38c
DM
63 start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec $DAEMON -- $DAEMON_ARGS ${dir} || return 2
64 sleep 1
a30f86c5
DM
65 done
66
67 return 0
ff62b221
DM
68}
69
70#
71# Function that stops the daemon/service
72#
73do_stop()
74{
75 # Return
76 # 0 if daemon has been stopped
77 # 1 if daemon was already stopped
78 # 2 if daemon could not be stopped
79 # other if a failure occurred
ff62b221 80
a30f86c5 81 RETVAL=0
07e2d38c
DM
82 for dir in ${RDISKLIST}; do
83 test -f "${dir}/startup" || continue
84 PIDFILE="$dir/sheep.pid"
85 start-stop-daemon --stop --oknodo --retry=TERM/20/KILL/5 --quiet --pidfile ${PIDFILE} --exec $DAEMON || RETVAL=2
86 sleep 1
a30f86c5 87 done
75a10ce5 88
ff62b221
DM
89 return "$RETVAL"
90}
91
92case "$1" in
75a10ce5
DM
93 start)
94 log_daemon_msg "Starting $DESC " "$NAME"
95 do_start
96 case "$?" in
97 0|1) log_end_msg 0 ;;
98 2) log_end_msg 1 ;;
ff62b221 99 esac
75a10ce5
DM
100 ;;
101 stop)
102 log_daemon_msg "Stopping $DESC" "$NAME"
ff62b221
DM
103 do_stop
104 case "$?" in
75a10ce5
DM
105 0|1) log_end_msg 0 ;;
106 2) log_end_msg 1 ;;
ff62b221 107 esac
a30f86c5 108
ff62b221 109 ;;
75a10ce5 110 status)
3b5296eb 111 RETVAL=0
07e2d38c
DM
112 for dir in ${DISKLIST}; do
113 test -f "${dir}/startup" || continue
114 PIDFILE="$dir/sheep.pid"
115 status_of_proc -p ${PIDFILE} $DAEMON "$NAME ${dir}" || RETVAL=1
a30f86c5 116 done
3b5296eb 117 exit $RETVAL
75a10ce5
DM
118 ;;
119 restart|force-reload)
ff62b221
DM
120 log_daemon_msg "Restarting $DESC" "$NAME"
121 do_stop
122 case "$?" in
75a10ce5 123 0|1)
ff62b221
DM
124 do_start
125 case "$?" in
75a10ce5
DM
126 0) log_end_msg 0 ;;
127 1) log_end_msg 1 ;; # Old process is still running
128 *) log_end_msg 1 ;; # Failed to start
ff62b221
DM
129 esac
130 ;;
75a10ce5 131 *)
ff62b221
DM
132 # Failed to stop
133 log_end_msg 1
134 ;;
135 esac
136 ;;
75a10ce5 137 *)
ff62b221
DM
138 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
139 exit 3
140 ;;
141esac
142
143:
144