summaryrefslogtreecommitdiffstats
path: root/init-script/dnbd2
blob: e9a67abeff05c3b881597f5120de4e8f7243ed0e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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