Debian Codegraph @

debian/init

raw
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides: istgt
4 # Required-Start: $network $local_fs $remote_fs
5 # Required-Stop: $remote_fs
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: iSCSI userspace target for kFreeBSD systems
9 # Description: iSCSI userspace target for kFreeBSD systems
10 ### END INIT INFO
11
12 # Author: Arno Töll <[email protected]>
13
14 PATH=/sbin:/usr/sbin:/bin:/usr/bin
15 DESC="istgt iSCSI target"
16 NAME=istgt
17 DAEMON=/usr/sbin/istgt
18 ISTGTCONTROL=/usr/sbin/istgtcontrol
19 PIDFILE=/var/run/$NAME.pid
20 DAEMON_ARGS="-c /etc/istgt/istgt.conf -p $PIDFILE"
21 SCRIPTNAME=/etc/init.d/$NAME
22 CONFIG=/etc/istgt/istgt.conf
23
24 # Exit if the package is not installed
25 [ -x $DAEMON ] || exit 0
26
27 # Read configuration variable file if it is present
28 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
29
30 # Load the VERBOSE setting and other rcS variables
31 . /lib/init/vars.sh
32
33 # Define LSB log_* functions.
34 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
35 . /lib/lsb/init-functions
36
37 if [ ! -r $CONFIG ] ; then
38 [ "$VERBOSE" != no ] && log_warning_msg "Not Starting $DESC: $CONFIG does not exit"
39 exit 0
40 fi
41
42 #
43 # Function that starts the daemon/service
44 #
45 do_start()
46 {
47 # Return
48 # 0 if daemon has been started
49 # 1 if daemon was already running
50 # 2 if daemon could not be started
51 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
52 || return 1
53 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
54 $DAEMON_ARGS 2>&1 | logger -p daemon.info \
55 || return 2
56
57 RETVAL=0
58 for i in 1 2 3 4 5 ; do
59 sleep 1
60 pidofproc -p $PIDFILE "$DAEMON" "$NAME" > /dev/null || RETVAL=$?
61 [ "$RETVAL" = 0 ] && return 0
62 done
63
64 [ "$RETVAL" != 0 ] && return 2
65 }
66
67 #
68 # Function that stops the daemon/service
69 #
70 do_stop()
71 {
72 # Return
73 # 0 if daemon has been stopped
74 # 1 if daemon was already stopped
75 # 2 if daemon could not be stopped
76 # other if a failure occurred
77 start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
78 RETVAL="$?"
79 [ "$RETVAL" = 2 ] && return 2
80 # Wait for children to finish too if this is a daemon that forks
81 # and if the daemon is only ever run from this initscript.
82 start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
83 [ "$?" = 2 ] && return 2
84 # Many daemons don't delete their pidfiles when they exit.
85 rm -f $PIDFILE
86 return "$RETVAL"
87 }
88
89 #
90 # Function that sends a SIGHUP to the daemon/service
91 #
92 do_reload() {
93 [ -x $ISTGTCONTROL ] || return 127
94 pidofproc -p $PIDFILE $NAME > /dev/null || return 2
95 $ISTGTCONTROL refresh > /dev/null 2>&1
96 return $?
97 }
98
99 case "$1" in
100 start)
101 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
102 do_start
103 case "$?" in
104 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
105 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
106 esac
107 ;;
108 stop)
109 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
110 do_stop
111 case "$?" in
112 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
113 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
114 esac
115 ;;
116 reload)
117 [ "$VERBOSE" != no ] && log_daemon_msg "Reloading $DESC " "$NAME"
118 do_reload
119 case "$?" in
120 0)
121 [ "$VERBOSE" != no ] && log_end_msg 0
122 ;;
123 2)
124 [ "$VERBOSE" != no ] && log_end_msg 1
125 [ "$VERBOSE" != no ] && log_warning_msg "$NAME is not running"
126 ;;
127 127)
128 [ "$VERBOSE" != no ] && log_end_msg 1
129 [ "$VERBOSE" != no ] && log_warning_msg "$ISTGTCONTROL not found"
130 ;;
131 *)
132 [ "$VERBOSE" != no ] && log_end_msg 1
133 ;;
134 esac
135 ;;
136 status)
137 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
138 ;;
139 restart)
140 log_daemon_msg "Restarting $DESC" "$NAME"
141 do_stop
142 case "$?" in
143 0|1)
144 do_start
145 case "$?" in
146 0) log_end_msg 0 ;;
147 1) log_end_msg 1 ;; # Old process is still running
148 *) log_end_msg 1 ;; # Failed to start
149 esac
150 ;;
151 *)
152 # Failed to stop
153 log_end_msg 1
154 ;;
155 esac
156 ;;
157 *)
158 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
159 exit 3
160 ;;
161 esac
162
163 :