4 # skeleton example file to build /etc/init.d/ scripts.
5 # This file should be used to construct scripts for /etc/init.d.
7 # Written by Miquel van Smoorenburg <miquels@cistron.nl>.
8 # Modified for Debian GNU/Linux
9 # by Ian Murdock <imurdock@gnu.ai.mit.edu>.
10 # Modified for the nbd-client package
11 # by Wouter Verhelst <wouter@debian.org>
14 # Provides: nbd-client
15 # Required-Start: $network $local_fs
16 # Required-Stop: $network
19 # X-Start-Before: mountnfs
20 # Short-Description: Network Block Device client
23 # Version: @(#)skeleton 1.8 03-Mar-1998 miquels@cistron.nl
25 PATH
=/sbin
:/bin
:/usr
/sbin
:/usr
/bin
26 DAEMON
="/sbin/nbd-client"
28 DESC
="NBD client process"
30 test -f /etc
/nbd-client
&& .
/etc
/nbd-client
32 test -x $DAEMON ||
exit 0
37 while [ ! -z "${NBD_TYPE[$i]}" ]
39 if [ "${NBD_TYPE[$i]}" == "$1" ]
41 DEVICES
="$DEVICES ${NBD_DEVICE[$i]}"
48 if [ "$KILLALL" == "false" ]
50 DEVICES
=${NBD_DEVICE[*]}
62 if [ "$KILLALL" == "false" ]
68 DEVICES
=`grep '^/dev/nb' /proc/swaps | cut -d ' ' -f1`
76 if [ "$KILLALL" == "false" ]
80 DEVICES
=`mount | cut -d " " -f 1 | grep /dev/nbd`
87 # I don't use start-stop-daemon: nbd-client only does some setup
88 # for the connection; the 'nbd-client' you see in your ps output
89 # later on is a kernel thread...
91 echo -n 'Connecting...'
93 while [ ! -z "${NBD_TYPE[$i]}" ]
95 # cfq deadlocks NBD devices, so switch to something else if cfq is
97 # This doesn't take into account non-udev devnames, but since
98 # there's really no other option these days...
99 if grep '\[cfq\]' "/sys/block/${NBD_DEVICE[$i]/\/dev\//}/queue/scheduler" >/dev
/null
; then
100 echo deadline
> "/sys/block/${NBD_DEVICE[$i]/\/dev\//}/queue/scheduler"
102 if nbd-client
-c "${NBD_DEVICE[$i]}" >/dev
/null
104 echo "${NBD_DEVICE[$i]} already connected, skipping..."
106 if [ ! -z "${NBD_NAME[$i]}" ]
108 name
="-N ${NBD_NAME[$i]}"
112 if $DAEMON "${NBD_HOST[$i]}" $name "${NBD_PORT[$i]}" "${NBD_DEVICE[$i]}" ${NBD_EXTRA[$i]}
114 echo "connected
${NBD_DEVICE[$i]}"
116 echo "could not connect
${NBD_DEVICE[$i]}"
123 echo -n "Starting
$DESC: "
126 if [ ! -f /run/sendsigs.omit.d/nbd-client ]
128 for x in $(cat /proc/cmdline); do
131 nbdroot="${x#nbdroot=}"
132 nbdbasedev=$(echo "$nbdroot" | sed -e 's/^.*,//')
133 nbdrootdev=/dev/$nbdbasedev
136 nbdrootdev="${x#root=}"
140 OMITKILL="$OMITKILL ${nbdrootdev%p*}"
143 nbd-client -c $x >> /run/sendsigs.omit.d/nbd-client
150 while [ ! -z "${NBD_TYPE[$i]}" -a nbd-client -c "${NBD_DEVICE[$i]}" ]
152 case "${NBD_TYPE[$i]}" in
154 /sbin/mkswap "${NBD_DEVICE[$i]}"
155 /sbin/swapon "${NBD_DEVICE[$i]}"
156 echo "${NBD_DEVICE[$i]}: swap activated.
"
159 line=$(grep "${NBD_DEVICE[$i]}" /etc/fstab | grep "_netdev
")
162 # sysvinit takes care of these.
165 dumb|network|unknown|"") spinner="" ;;
167 /sbin/fsck $spinner -a "${NBD_DEVICE[$i]}"
170 /bin/mount "${NBD_DEVICE[$i]}"
171 echo "${NBD_DEVICE[$i]}: filesystem mounted.
"
173 echo "fsck of
${NBD_DEVICE[$i]} failed. Not mounting.
"
178 # Nothing needs to be done
179 echo "${NBD_DEVICE[$i]}: raw selected. doing nothing.
"
182 echo "Error
: NBD_TYPE
[$i] contains unknown value
${NBD_TYPE[$i]}"
190 echo "Stopping
$DESC: "
194 # Ignore devices with _netdev option (sysvinit takes care of those)
195 line=$(grep $dev /etc/fstab | grep "_netdev
")
198 echo "umounting filesystem from
$dev...
"
199 umount $dev 2>/dev/null
202 echo -n "umount of
$dev failed
! Data loss may occur
! will
continue in 10 seconds...
"
204 for i in 9 8 7 6 5 4 3 2 1
209 echo "ok
, going on...
"
217 echo "Invoking swapoff on
$DEVICES...
"
218 swapoff $DEVICES 2>/dev/null
223 echo "Disconnecting
$i"
224 $DAEMON -d $i 2>/dev/null >/dev/null
229 restart|force-reload)
230 if dpkg --compare-versions "$
(uname
-r)" gt "2.4"
236 echo "Need
2.4-kernel for disconnect. As such
, restart won
't work"
237 echo "Either upgrade to a 2.4-kernel, or use $0 stop, restart the server,"
238 echo "and do $0 start."
243 echo "Usage: $N {start|connect|stop|restart|force-reload|activate}" >&2