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