[c5c522c] | 1 | #!/bin/sh |
---|
| 2 | # Start/stop/restart the NFS server. |
---|
| 3 | # |
---|
| 4 | # This is an init script for the knfsd NFS daemons. |
---|
| 5 | # To use NFS, you must first set up /etc/exports. |
---|
| 6 | # See exports(5) for information on /etc/exports format. |
---|
| 7 | # |
---|
| 8 | # Written for Slackware Linux by Patrick J. Volkerding <volkerdi@slackware.com>. |
---|
| 9 | |
---|
| 10 | nfsd_start() { |
---|
| 11 | # Sanity checks. Exit if there's no /etc/exports, or if there aren't any |
---|
| 12 | # shares defined in it. |
---|
| 13 | if [ ! -r /etc/exports ]; then # no config file, exit: |
---|
| 14 | exit |
---|
| 15 | elif ! grep -v '^#' /etc/exports | grep '/' 1> /dev/null 2> /dev/null ; then |
---|
| 16 | exit # no uncommented shares in /etc/exports |
---|
| 17 | fi |
---|
| 18 | |
---|
| 19 | # If we do not detect nfsd support built into the kernel (or previously |
---|
| 20 | # loaded as a module), we will try to load the nfsd.ko kernel module: |
---|
| 21 | if [ ! -r /proc/1/net/rpc/nfsd ]; then |
---|
| 22 | /sbin/modprobe nfsd |
---|
| 23 | fi |
---|
| 24 | |
---|
| 25 | # For kernels newer than 2.4.x, use the new way of handling nfs client requests. |
---|
| 26 | if [ ! "$(/bin/uname -r | /bin/cut -f 1,2 -d .)" = "2.4" ]; then |
---|
| 27 | if grep -wq nfsd /proc/filesystems 2> /dev/null ; then |
---|
| 28 | if grep -vwq nfsd /proc/mounts 2> /dev/null ; then |
---|
| 29 | /sbin/mount -t nfsd nfsd /proc/fs/nfs 2> /dev/null |
---|
| 30 | fi |
---|
| 31 | fi |
---|
| 32 | fi |
---|
| 33 | |
---|
| 34 | # If basic RPC services are not running, start them: |
---|
| 35 | if ! ps axc | grep -q rpc.statd ; then |
---|
| 36 | if [ -r /etc/rc.d/rc.rpc ]; then |
---|
| 37 | sh /etc/rc.d/rc.rpc start |
---|
| 38 | else |
---|
| 39 | # Sure, we tested for rpc.statd, but this is the probable cause: |
---|
| 40 | echo "FATAL: Can't start NFS server without portmap package." |
---|
| 41 | sleep 5 |
---|
| 42 | exit 1 |
---|
| 43 | fi |
---|
| 44 | fi |
---|
| 45 | |
---|
| 46 | echo "Starting NFS server daemons:" |
---|
| 47 | |
---|
| 48 | if [ -x /usr/sbin/exportfs ]; then |
---|
| 49 | echo " /usr/sbin/exportfs -r" |
---|
| 50 | /usr/sbin/exportfs -r |
---|
| 51 | fi |
---|
| 52 | |
---|
| 53 | if [ -x /usr/sbin/rpc.rquotad ]; then |
---|
| 54 | echo " /usr/sbin/rpc.rquotad" |
---|
| 55 | /usr/sbin/rpc.rquotad |
---|
| 56 | fi |
---|
| 57 | |
---|
| 58 | # Start 8 nfsd servers by default (an old Sun standard): |
---|
| 59 | if [ -x /usr/sbin/rpc.nfsd ]; then |
---|
| 60 | echo " /usr/sbin/rpc.nfsd 8" |
---|
| 61 | /usr/sbin/rpc.nfsd 8 |
---|
| 62 | fi |
---|
| 63 | |
---|
| 64 | if [ -x /usr/sbin/rpc.mountd ]; then |
---|
| 65 | echo " /usr/sbin/rpc.mountd" |
---|
| 66 | /usr/sbin/rpc.mountd |
---|
| 67 | fi |
---|
| 68 | |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | nfsd_stop() { |
---|
| 72 | killall rpc.mountd 2> /dev/null |
---|
| 73 | killall nfsd 2> /dev/null |
---|
| 74 | sleep 1 |
---|
| 75 | killall -9 nfsd 2> /dev/null # make sure :) |
---|
| 76 | killall rpc.rquotad 2> /dev/null |
---|
| 77 | /usr/sbin/exportfs -au 2> /dev/null |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | nfsd_restart() { |
---|
| 81 | nfsd_stop |
---|
| 82 | sleep 1 |
---|
| 83 | nfsd_start |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | case "$1" in |
---|
| 87 | 'start') |
---|
| 88 | nfsd_start |
---|
| 89 | ;; |
---|
| 90 | 'stop') |
---|
| 91 | nfsd_stop |
---|
| 92 | ;; |
---|
| 93 | 'restart') |
---|
| 94 | nfsd_restart |
---|
| 95 | ;; |
---|
| 96 | *) |
---|
| 97 | echo "usage $0 start|stop|restart" |
---|
| 98 | esac |
---|