diff options
Diffstat (limited to 'init-script/dnbd2')
-rwxr-xr-x | init-script/dnbd2 | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/init-script/dnbd2 b/init-script/dnbd2 new file mode 100755 index 0000000..e9a67ab --- /dev/null +++ b/init-script/dnbd2 @@ -0,0 +1,84 @@ +#! /bin/bash +# +### BEGIN INIT INFO +# Provides: dnbd2 +# Required-Start: $local_fs $network +# Required-Stop: $local_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts and stops the DNBD2 server. +# Description: DNDB2 is a Distributed Network Block Device for +# diskless clients in unicast networks. +### END INIT INFO +# +# Author: Vito Di Leo <dileo@informatik.uni-freiburg.de> + +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +USER=dnbd2 +SERVER_NAME=dnbd2-server +SERVER_DESC="DNBD2 Server" + +[ -x "`which $SERVER_NAME`" ] || exit 0 + +. /lib/lsb/init-functions + +if ! (id $USER >/dev/null 2>&1) ; then + log_failure_msg "Please create system user $USER." + exit 0 +fi + +if [ ! -x /usr/bin/pkill ] ; then + log_failure_msg "Please install pkill." + exit 0 +fi + +if [ ! -x /usr/bin/sudo ] ; then + log_failure_msg "Please install sudo." + exit 0 +fi + + +case "$1" in + start) + for FILE in `ls /etc/dnbd2/servers/* 2>/dev/null` ; do + log_begin_msg "Starting $SERVER_DESC ($FILE)..." + sudo -u $USER $SERVER_NAME $FILE + log_end_msg $? + done + ;; + + stop) + log_begin_msg "Stoping $SERVER_DESC"s... + pkill -u $USER $SERVER_NAME + log_end_msg 0 + ;; + + reload|force-reload) + log_begin_msg "Reloading $SERVER_DESC"s... + pkill -SIGHUP -u $USER $SERVER_NAME + log_end_msg 0 + ;; + + restart) + $0 stop + sleep 1 + $0 start + ;; + + status) + PIDS=`pgrep -u $USER $SERVER_NAME` + if [ -n "$PIDS" ] ; then + echo $SERVER_NAME running on pids $PIDS + exit 0 + fi + echo $SERVER_NAME not running. + exit 3 + ;; + + *) + echo "Usage: dnbd2 {start|stop|restart|reload|force-reload}" >&2 + exit 3 + ;; +esac + +exit 0 |