]> git.pld-linux.org Git - packages/nfs-utils.git/blob - nfs.init
- updated to 2.3.4
[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 # Check that networking is up.
23 if is_yes "${NETWORKING}"; then
24         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
25                 msg_network_down "NFS daemon"
26                 exit 1
27         fi
28 else
29         exit 0
30 fi
31
32 if [ "$1" != "stop" ]; then
33         check_portmapper || { nls "Error: portmap isn't running" && exit 0; }
34 fi
35
36 start() {
37         # Check if the service is already running?
38         if [ -f /var/lock/subsys/nfs ]; then
39                 msg_already_running "NFS daemon"
40                 return
41         fi
42
43         if ! grep -q nfsd /proc/mounts ; then
44                 modprobe -s nfsd > /dev/null 2>&1
45                 run_cmd "Mounting /proc/fs/nfsd filesystem" mount -t nfsd nfsd /proc/fs/nfsd
46         fi
47
48         # Set the ports lockd should listen on
49         if [ -n "$LOCKD_TCPPORT" ]; then
50                 /sbin/sysctl -w fs.nfs.nlm_tcpport=$LOCKD_TCPPORT >/dev/null 2>&1
51         fi
52         if [ -n "$LOCKD_UDPPORT" ]; then
53                 /sbin/sysctl -w fs.nfs.nlm_udpport=$LOCKD_UDPPORT >/dev/null 2>&1
54         fi
55
56         # Start daemons.
57         msg_starting "NFS exportfs"
58         daemon /usr/sbin/exportfs -r
59         msg_starting "NFS mountd"
60         daemon /usr/sbin/rpc.mountd $RPCMOUNTDOPTIONS
61         msg_starting "NFS daemon"
62         daemon /usr/sbin/rpc.nfsd $RPCNFSDCOUNT
63         touch /var/lock/subsys/nfs
64 }
65
66 stop() {
67         if [ ! -f /var/lock/subsys/nfs ]; then
68                 msg_not_running "NFS"
69                 return
70         fi
71
72         # Stop daemons.
73         msg_stopping "NFS daemon"
74         killproc nfsd -QUIT
75         msg_stopping "NFS mountd"
76         killproc rpc.mountd
77         msg_stopping "NFS exportfs"
78         daemon /usr/sbin/exportfs -au
79         rm -f /var/lock/subsys/nfs
80 }
81
82 RETVAL=0
83 # See how we were called.
84 case "$1" in
85   start)
86         start
87         ;;
88   stop)
89         stop
90         ;;
91   restart)
92         stop
93         start
94         /sbin/service idmapd status >/dev/null && /sbin/service idmapd reload
95         /sbin/service svcgssd status >/dev/null && /sbin/service svcgssd restart
96         ;;
97   reload|force-reload)
98         if [ -f /var/lock/subsys/nfs ]; then
99                 msg_reloading "NFS"
100                 busy
101                 /usr/sbin/exportfs -r
102                 [ $? -ne 0 ] && RETVAL=7
103                 if [ $RETVAL -eq 0 ]; then
104                         ok
105                         /sbin/service idmapd status >/dev/null && /sbin/service idmapd reload
106                         /sbin/service svcgssd status >/dev/null && /sbin/service svcgssd restart
107                 else
108                         died
109                 fi
110         else
111                 msg_not_running "NFS"
112                 exit 7
113         fi
114         ;;
115   probe)
116         if [ ! -f /var/lock/subsys/nfs ]; then
117                 echo start
118                 exit 0
119         fi
120         /sbin/pidof rpc.mountd >/dev/null 2>&1; MOUNTD="$?"
121         /sbin/pidof nfsd >/dev/null 2>&1; NFSD="$?"
122         if [ $MOUNTD = 1 -o $NFSD = 1 ]; then
123                 echo restart
124                 exit 0
125         fi
126         if [ /etc/exports -nt /var/lock/subsys/nfs ]; then
127                 echo reload
128                 exit 0
129         fi
130         ;;
131   status)
132         echo "Configured NFS exports:"
133         grep -v "^#" /etc/exports
134         echo
135         echo "Active NFS exports:"
136         /usr/sbin/exportfs -v
137         echo
138         status rpc.mountd
139         RETVAL=$?
140         status nfsd
141         RET=$?
142         [ $RETVAL -eq 0 ] && RETVAL=$RET
143         ;;
144   *)
145         msg_usage "$0 {start|stop|restart|reload|force-reload|probe|status}"
146         exit 3
147 esac
148
149 exit $RETVAL
This page took 0.072087 seconds and 3 git commands to generate.