Touch changelog
[nbd.git] / debian / nbd-client.init.d
blob7b414b98e40945efd4ea581a5953716e6017aa39
1 #!/bin/sh
2 # vim: ft=sh
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>
13 ### BEGIN INIT INFO
14 # Provides: nbd-client
15 # Required-Start: $network $local_fs
16 # Required-Stop: $network
17 # Default-Start: S
18 # Default-Stop: 0 6
19 # X-Start-Before: mountnfs
20 # Short-Description: Network Block Device client
21 ### END INIT INFO
23 # Version: @(#)skeleton 1.8 03-Mar-1998 miquels@cistron.nl
25 PATH=/sbin:/bin:/usr/sbin:/usr/bin
26 DAEMON="/sbin/nbd-client"
27 NAME="nbd-client"
28 DESC="NBD client process"
30 test -f /etc/nbd-client && . /etc/nbd-client
32 test -x $DAEMON || exit 0
34 case "$1" in
35 connect)
36 # I don't use start-stop-daemon: nbd-client only does some setup
37 # for the connection; the 'nbd-client' you see in your ps output
38 # later on is a kernel thread...
39 modprobe nbd
40 echo -n 'Connecting...'
41 for dev in $(awk '/^(( \t)*[^#])/{print $1}' /etc/nbdtab)
43 # cfq deadlocks NBD devices, so switch to something else if cfq is
44 # selected by default
45 # This doesn't take into account non-udev devnames, but since
46 # there's really no other option these days...
47 if grep '\[cfq\]' "/sys/block/${dev}/queue/scheduler" >/dev/null; then
48 echo deadline > "/sys/block/${dev}/queue/scheduler"
50 if nbd-client -c "${dev}" >/dev/null
51 then
52 echo "${dev} already connected, skipping..."
53 else
54 nbd-client ${dev}
56 done
58 start)
59 echo -n "Starting $DESC: "
60 $0 connect
61 if [ ! -f /run/sendsigs.omit.d/nbd-client ]
62 then
63 for x in $(cat /proc/cmdline); do
64 case $x in
65 nbdroot=*,*,*)
66 nbdroot="${x#nbdroot=}"
67 nbdbasedev=$(echo "$nbdroot" | sed -e 's/^.*,//')
68 nbdrootdev=/dev/$nbdbasedev
70 root=/dev/nbd*)
71 nbdrootdev="${x#root=}"
73 esac
74 done
75 OMITKILL="$OMITKILL ${nbdrootdev%p*}"
76 for x in $OMITKILL
78 nbd-client -c $x >> /run/sendsigs.omit.d/nbd-client
79 done
82 stop)
83 echo "Stopping $DESC: "
84 for dev in $(awk '/^(( \t)*[^#])/{print $1}' /etc/nbdtab)
86 nbd-client -d /dev/$dev
87 done
88 rmmod nbd
89 echo "$NAME."
91 restart|force-reload)
92 $0 stop
93 sleep 10
94 $0 start
97 N=/etc/init.d/$NAME
98 echo "Usage: $N {start|connect|stop|restart|force-reload}" >&2
99 exit 1
101 esac
103 exit 0