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