]>
Commit | Line | Data |
---|---|---|
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 | sleep 1 | |
65 | done | |
66 | ||
67 | return 0 | |
68 | } | |
69 | ||
70 | # | |
71 | # Function that stops the daemon/service | |
72 | # | |
73 | do_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 | |
80 | ||
81 | RETVAL=0 | |
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 | |
87 | done | |
88 | ||
89 | return "$RETVAL" | |
90 | } | |
91 | ||
92 | case "$1" in | |
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 ;; | |
99 | esac | |
100 | ;; | |
101 | stop) | |
102 | log_daemon_msg "Stopping $DESC" "$NAME" | |
103 | do_stop | |
104 | case "$?" in | |
105 | 0|1) log_end_msg 0 ;; | |
106 | 2) log_end_msg 1 ;; | |
107 | esac | |
108 | ||
109 | ;; | |
110 | status) | |
111 | RETVAL=0 | |
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 | |
116 | done | |
117 | exit $RETVAL | |
118 | ;; | |
119 | restart|force-reload) | |
120 | log_daemon_msg "Restarting $DESC" "$NAME" | |
121 | do_stop | |
122 | case "$?" in | |
123 | 0|1) | |
124 | do_start | |
125 | case "$?" in | |
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 | |
129 | esac | |
130 | ;; | |
131 | *) | |
132 | # Failed to stop | |
133 | log_end_msg 1 | |
134 | ;; | |
135 | esac | |
136 | ;; | |
137 | *) | |
138 | echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 | |
139 | exit 3 | |
140 | ;; | |
141 | esac | |
142 | ||
143 | : | |
144 |