]> git.proxmox.com Git - pve-sheepdog.git/blob - debian/pve-sheepdog.sheepdog.init.d
fix PKGREL
[pve-sheepdog.git] / debian / pve-sheepdog.sheepdog.init.d
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
15 PATH=/sbin:/usr/sbin:/bin:/usr/bin
16 DESC="Sheepdog Server" # Introduce a short description here
17 NAME=sheepdog # Introduce the short server's name here
18 DAEMON=/usr/sbin/sheep # Introduce the server's location here
19 SCRIPTNAME=/etc/init.d/$NAME
20
21 # Exit if the package is not installed
22 [ -x $DAEMON ] || exit 0
23
24 DISKLIST=$(echo /var/lib/sheepdog/disc[0123456789])
25 RDISKLIST=
26 for dir in ${DISKLIST}; do
27 RDISKLIST="${dir} ${RDISKLIST}"
28 done
29
30 # Read configuration variable file if it is present
31 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
32
33 if [ "$START" != "yes" ]; then
34 exit 0
35 fi
36
37 . /lib/lsb/init-functions
38
39 #
40 # Function that starts the daemon/service
41 #
42 do_start()
43 {
44 mkdir -p /var/run
45
46 # Return
47 # 0 if daemon has been started
48 # 1 if daemon was already running
49 # 2 if daemon could not be started
50
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
60
61 status_of_proc -p ${PIDFILE} $DAEMON "$NAME" >/dev/null && continue
62
63 start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec $DAEMON -- $DAEMON_ARGS ${dir} || return 2
64 done
65
66 return 0
67 }
68
69 #
70 # Function that stops the daemon/service
71 #
72 do_stop()
73 {
74 # Return
75 # 0 if daemon has been stopped
76 # 1 if daemon was already stopped
77 # 2 if daemon could not be stopped
78 # other if a failure occurred
79
80 RETVAL=0
81 for dir in ${RDISKLIST}; do
82 test -f "${dir}/startup" || continue
83 PIDFILE="$dir/sheep.pid"
84 start-stop-daemon --stop --oknodo --retry=TERM/20/KILL/5 --quiet --pidfile ${PIDFILE} --exec $DAEMON || RETVAL=2
85 done
86
87 return "$RETVAL"
88 }
89
90 case "$1" in
91 start)
92 log_daemon_msg "Starting $DESC " "$NAME"
93 do_start
94 case "$?" in
95 0|1) log_end_msg 0 ;;
96 2) log_end_msg 1 ;;
97 esac
98 ;;
99 stop)
100 log_daemon_msg "Stopping $DESC" "$NAME"
101 do_stop
102 case "$?" in
103 0|1) log_end_msg 0 ;;
104 2) log_end_msg 1 ;;
105 esac
106
107 ;;
108 status)
109 RETVAL=0
110 for dir in ${DISKLIST}; do
111 test -f "${dir}/startup" || continue
112 PIDFILE="$dir/sheep.pid"
113 status_of_proc -p ${PIDFILE} $DAEMON "$NAME ${dir}" || RETVAL=1
114 done
115 exit $RETVAL
116 ;;
117 restart|force-reload)
118 log_daemon_msg "Restarting $DESC" "$NAME"
119 do_stop
120 case "$?" in
121 0|1)
122 do_start
123 case "$?" in
124 0) log_end_msg 0 ;;
125 1) log_end_msg 1 ;; # Old process is still running
126 *) log_end_msg 1 ;; # Failed to start
127 esac
128 ;;
129 *)
130 # Failed to stop
131 log_end_msg 1
132 ;;
133 esac
134 ;;
135 *)
136 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
137 exit 3
138 ;;
139 esac
140
141 :
142