]> git.decadent.org.uk Git - nfs-utils.git/blob - debian/nfs-common.init
misc debian fixed from trond
[nfs-utils.git] / debian / nfs-common.init
1 #!/bin/sh
2 #
3 # nfs-common    This shell script takes care of starting and stopping
4 #               common daemons required for NFS clients and servers.
5 #
6 # chkconfig: 345 20 80
7 # description: NFS is a popular protocol for file sharing across \
8 #              TCP/IP networks. This service provides NFS file \
9 #              locking functionality.
10 #
11
12 set -e
13
14 # What is this?
15 DESC="NFS common utilities"
16
17 # Read config
18 DEFAULTFILE=/etc/default/nfs-common
19 PREFIX=
20 NEED_LOCKD=
21 NEED_IDMAPD=yes
22 IDMAPD_PIDFILE=/var/run/rpc.idmapd.pid
23 PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
24 if [ -f $DEFAULTFILE ]; then
25     . $DEFAULTFILE
26 fi
27
28 # Determine whether lockd daemon is required.
29 case "$NEED_LOCKD" in
30 yes|no) ;;
31 *)  case `uname -r` in
32     '' | [01].* | 2.[0123].* )
33         # Older kernels may or may not need a lockd daemon.
34         # We must assume they do, unless we can prove otherwise.
35         # (A false positive here results only in a harmless message.)
36         NEED_LOCKD=yes
37         if test -f /proc/ksyms
38         then
39             grep -q lockdctl /proc/ksyms || NEED_LOCKD=no
40         fi
41         ;;
42
43     *)  # Modern kernels (>= 2.4) start a lockd thread automatically.
44         NEED_LOCKD=no
45         ;;
46     esac
47     ;;
48 esac
49
50 # Exit if required binaries are missing.
51 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
52 [ -x $PREFIX/sbin/rpc.lockd ] || [ "$NEED_LOCKD" = no ] || exit 0
53 [ -x /usr/sbin/rpc.idmapd ] || [ "$NEED_IDMAPD" = no ] || exit 0
54
55 do_modprobe() {
56         modprobe -q $1 || true
57 }
58
59 do_mount() {
60         if ! grep -E -qs "$1\$" /proc/filesystems
61         then
62                 return 1
63         fi
64         if ! mountpoint -q $2
65         then
66                 mount -t $1 $3 $1 $2
67                 return
68         fi
69         return 0
70 }
71
72 # See how we were called.
73 case "$1" in
74   start)
75         cd /    # daemons should have root dir as cwd
76         printf "Starting $DESC:"
77         printf " statd"
78         start-stop-daemon --start --quiet \
79             --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
80         if [ "$NEED_LOCKD" = yes ]
81         then
82             printf " lockd"
83             start-stop-daemon --start --quiet \
84                 --exec $PREFIX/sbin/rpc.lockd  || true
85         fi
86         if [ "$NEED_IDMAPD" = yes ]
87         then
88             do_modprobe nfs
89             if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT;
90             then
91                 printf " idmapd"
92                 start-stop-daemon --start --quiet \
93                         --make-pidfile --pidfile $IDMAPD_PIDFILE \
94                         --exec /usr/sbin/rpc.idmapd
95             fi
96         fi
97         echo "."
98         ;;
99
100   stop)
101         printf "Stopping $DESC:"
102         if [ "$NEED_IDMAPD" = yes ]
103         then
104             printf " idmapd"
105             start-stop-daemon --stop --oknodo --quiet \
106                 --name rpc.idmapd --user 0
107             rm -f $IDMAPD_PIDFILE
108         fi
109         if [ "$NEED_LOCKD" = yes ]
110         then
111             printf " lockd"
112             start-stop-daemon --stop --oknodo --quiet \
113                 --name rpc.lockd --user 0  || true
114         fi
115         printf " statd"
116         start-stop-daemon --stop --oknodo --quiet \
117             --name rpc.statd --user 0
118         echo "."
119         ;;
120
121   restart | force-reload)
122         $0 stop
123         sleep 1
124         $0 start
125         ;;
126
127   *)
128         echo "Usage: nfs-common {start|stop|restart}"
129         exit 1
130         ;;
131 esac
132
133 exit 0