]> git.decadent.org.uk Git - nfs-utils.git/blob - debian/nfs-common.init
little debian bits
[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 if [ -f $DEFAULTFILE ]; then
23     . $DEFAULTFILE
24 fi
25
26 # Determine whether lockd daemon is required.
27 case "$NEED_LOCKD" in
28 yes|no) ;;
29 *)  case `uname -r` in
30     '' | [01].* | 2.[0123].* )
31         # Older kernels may or may not need a lockd daemon.
32         # We must assume they do, unless we can prove otherwise.
33         # (A false positive here results only in a harmless message.)
34         NEED_LOCKD=yes
35         if test -f /proc/ksyms
36         then
37             grep -q lockdctl /proc/ksyms || NEED_LOCKD=no
38         fi
39         ;;
40
41     *)  # Modern kernels (>= 2.4) start a lockd thread automatically.
42         NEED_LOCKD=no
43         ;;
44     esac
45     ;;
46 esac
47
48 # Exit if required binaries are missing.
49 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
50 [ -x $PREFIX/sbin/rpc.lockd ] || [ "$NEED_LOCKD" = no ] || exit 0
51 [ -x /usr/sbin/rpc.idmapd ] || [ "$NEED_IDMAPD" = no ] || exit 0
52
53 # See how we were called.
54 case "$1" in
55   start)
56         cd /    # daemons should have root dir as cwd
57         printf "Starting $DESC:"
58         printf " statd"
59         start-stop-daemon --start --quiet \
60             --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
61         if [ "$NEED_LOCKD" = yes ]
62         then
63             printf " lockd"
64             start-stop-daemon --start --quiet \
65                 --exec $PREFIX/sbin/rpc.lockd  || true
66         fi
67         if [ "$NEED_IDMAPD" = yes ]
68         then
69             printf " idmapd"
70             start-stop-daemon --start --quiet \
71                 --exec /usr/sbin/rpc.idmapd
72         fi
73         echo "."
74         ;;
75
76   stop)
77         printf "Stopping $DESC:"
78         if [ "$NEED_IDMAPD" = yes ]
79         then
80             printf " idmapd"
81             start-stop-daemon --stop --oknodo --quiet \
82                 --name rpc.idmapd --user 0
83         fi
84         if [ "$NEED_LOCKD" = yes ]
85         then
86             printf " lockd"
87             start-stop-daemon --stop --oknodo --quiet \
88                 --name rpc.lockd --user 0  || true
89         fi
90         printf " statd"
91         start-stop-daemon --stop --oknodo --quiet \
92             --name rpc.statd --user 0
93         echo "."
94         ;;
95
96   restart | force-reload)
97         $0 stop
98         sleep 1
99         $0 start
100         ;;
101
102   *)
103         echo "Usage: nfs-common {start|stop|restart}"
104         exit 1
105         ;;
106 esac
107
108 exit 0