548b5e057ffc0a78879617a3494c7a205f13cdd6
[nfs-utils.git] / debian / nfs-kernel-server.init
1 #!/bin/sh
2 #
3 # nfs-kernel-server
4 #               This shell script takes care of starting and stopping
5 #               the kernel-mode NFS server.
6 #
7 # chkconfig: 345 60 20
8 # description: NFS is a popular protocol for file sharing across TCP/IP \
9 #              networks. This service provides NFS server functionality, \
10 #              which is configured via the /etc/exports file.
11 #
12
13 PREFIX=/usr
14 [ -x $PREFIX/sbin/rpc.nfsd ] || exit 0
15 [ -x $PREFIX/sbin/rpc.mountd ] || exit 0
16 [ -x $PREFIX/sbin/exportfs ] || exit 0
17
18 # What is this?
19 DESC="NFS kernel daemon"
20
21 RPCNFSDCOUNT=8  # Number of servers to be started up by default
22 RPCMOUNTDOPTS=
23
24 # See how we were called.
25 case "$1" in
26   start)
27         cd /    # daemons should have root dir as cwd
28         if grep -q '^/' /etc/exports
29         then
30                 printf "Exporting directories for $DESC..."
31                 $PREFIX/sbin/exportfs -r
32                 echo "done."
33
34                 printf "Starting $DESC:"
35                 printf " nfsd"
36                 start-stop-daemon --start --quiet \
37                     --exec $PREFIX/sbin/rpc.nfsd -- $RPCNFSDCOUNT
38                 printf " mountd"
39                 $PREFIX/bin/rpcinfo -u localhost nfs 3 >/dev/null 2>&1 ||
40                     RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3"
41                 start-stop-daemon --start --quiet \
42                     --exec $PREFIX/sbin/rpc.mountd -- $RPCMOUNTDOPTS
43                 echo "."
44         else
45                 echo "Not starting $DESC: No exports."
46         fi
47         ;;
48
49   stop)
50         printf "Stopping $DESC: mountd"
51         start-stop-daemon --stop --oknodo --quiet \
52             --name rpc.mountd --user 0
53         printf " nfsd"
54         start-stop-daemon --stop --oknodo --quiet \
55             --name nfsd --user 0 --signal 2
56         echo "."
57
58         printf "Unexporting directories for $DESC..."
59         $PREFIX/sbin/exportfs -au
60         echo "done."
61         ;;
62
63   reload | force-reload)
64         printf "Re-exporting directories for $DESC..."
65         $PREFIX/sbin/exportfs -r
66         echo "done."
67         ;;
68
69   restart)
70         $0 stop
71         sleep 1
72         $0 start
73         ;;
74
75   *)
76         echo "Usage: nfs-kernel-server {start|stop|reload|force-reload|restart}"
77         exit 1
78         ;;
79 esac
80
81 exit 0
82