]> git.pld-linux.org Git - packages/nfs-utils.git/blob - nfs.init
- rel 5
[packages/nfs-utils.git] / nfs.init
1 #!/bin/sh
2 #
3 # nfs           This shell script takes care of starting and stopping
4 #               the NFS services.
5 #
6 # chkconfig:    345 13 81
7 # description:  NFS is a popular protocol for file sharing across TCP/IP \
8 #               networks. This service provides NFS server functionality, \
9 #               which is configured via the /etc/exports file.
10 # probe:        true
11
12 # Source function library
13 . /etc/rc.d/init.d/functions
14
15 # Get network config
16 . /etc/sysconfig/network
17
18 # Get service configs
19 [ -f /etc/sysconfig/nfslock ] && . /etc/sysconfig/nfslock
20 [ -f /etc/sysconfig/nfsd ] && . /etc/sysconfig/nfsd
21
22 [ -n "$NFSv2" ] || NFSv2="yes"
23 [ -n "$NFSv3" ] || NFSv3="yes"
24 [ -n "$NFSv4" ] || NFSv4="yes"
25
26 # Check that networking is up.
27 if is_yes "${NETWORKING}"; then
28         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
29                 msg_network_down "NFS daemon"
30                 exit 1
31         fi
32 else
33         exit 0
34 fi
35
36 if [ "$1" != "stop" ]; then
37         check_portmapper || { nls "Error: portmap isn't running" && exit 0; }
38 fi
39
40 start() {
41         # Check if the service is already running?
42         if [ -f /var/lock/subsys/nfs ]; then
43                 msg_already_running "NFS daemon"
44                 return
45         fi
46
47         if ! grep -q nfsd /proc/mounts ; then
48                 modprobe -s nfsd > /dev/null 2>&1
49                 run_cmd "Mounting /proc/fs/nfsd filesystem" mount -t nfsd nfsd /proc/fs/nfsd
50         fi
51
52         # Set the ports lockd should listen on
53         if [ -n "$LOCKD_TCPPORT" ]; then
54                 /sbin/sysctl -w fs.nfs.nlm_tcpport=$LOCKD_TCPPORT >/dev/null 2>&1
55         fi
56         if [ -n "$LOCKD_UDPPORT" ]; then
57                 /sbin/sysctl -w fs.nfs.nlm_udpport=$LOCKD_UDPPORT >/dev/null 2>&1
58         fi
59
60         for vers in 2 3 4 ; do
61                 is_yes $(eval echo \$NFSv$vers) || \
62                         RPCMOUNTOPTIONS="$RPCMOUNTOPTIONS --no-nfs-version $vers"
63         done
64
65         [ -n "$MOUNTD_PORT" ] && RPCMOUNTOPTIONS="$RPCMOUNTOPTIONS -p $MOUNTD_PORT"
66
67         # Start daemons.
68         msg_starting "NFS exportfs"
69         daemon /usr/sbin/exportfs -r
70         msg_starting "NFS mountd"
71         daemon /usr/sbin/rpc.mountd $RPCMOUNTOPTIONS
72         msg_starting "NFS daemon"
73         daemon /usr/sbin/rpc.nfsd $RPCNFSDCOUNT
74         touch /var/lock/subsys/nfs
75 }
76
77 stop() {
78         if [ ! -f /var/lock/subsys/nfs ]; then
79                 msg_not_running "NFS"
80                 return
81         fi
82
83         # Stop daemons.
84         msg_stopping "NFS daemon"
85         killproc nfsd -QUIT
86         msg_stopping "NFS mountd"
87         killproc rpc.mountd
88         msg_stopping "NFS exportfs"
89         daemon /usr/sbin/exportfs -au
90         rm -f /var/lock/subsys/nfs
91 }
92
93 RETVAL=0
94 # See how we were called.
95 case "$1" in
96   start)
97         start
98         ;;
99   stop)
100         stop
101         ;;
102   restart)
103         stop
104         start
105         /sbin/service idmapd status >/dev/null && /sbin/service idmapd reload
106         /sbin/service svcgssd status >/dev/null && /sbin/service svcgssd restart
107         ;;
108   reload|force-reload)
109         if [ -f /var/lock/subsys/nfs ]; then
110                 msg_reloading "NFS"
111                 busy
112                 /usr/sbin/exportfs -r
113                 [ $? -ne 0 ] && RETVAL=7
114                 if [ $RETVAL -eq 0 ]; then
115                         ok
116                         /sbin/service idmapd status >/dev/null && /sbin/service idmapd reload
117                         /sbin/service svcgssd status >/dev/null && /sbin/service svcgssd restart
118                 else
119                         died
120                 fi
121         else
122                 msg_not_running "NFS"
123                 exit 7
124         fi
125         ;;
126   probe)
127         if [ ! -f /var/lock/subsys/nfs ]; then
128                 echo start
129                 exit 0
130         fi
131         /sbin/pidof rpc.mountd >/dev/null 2>&1; MOUNTD="$?"
132         /sbin/pidof nfsd >/dev/null 2>&1; NFSD="$?"
133         if [ $MOUNTD = 1 -o $NFSD = 1 ]; then
134                 echo restart
135                 exit 0
136         fi
137         if [ /etc/exports -nt /var/lock/subsys/nfs ]; then
138                 echo reload
139                 exit 0
140         fi
141         ;;
142   status)
143         echo "Configured NFS exports:"
144         grep -v "^#" /etc/exports
145         echo
146         echo "Active NFS exports:"
147         /usr/sbin/exportfs -v
148         echo
149         status rpc.mountd
150         RETVAL=$?
151         status nfsd
152         RET=$?
153         [ $RETVAL -eq 0 ] && RETVAL=$RET
154         ;;
155   *)
156         msg_usage "$0 {start|stop|restart|reload|force-reload|probe|status}"
157         exit 3
158 esac
159
160 exit $RETVAL
This page took 0.12161 seconds and 3 git commands to generate.