blob: 0f5747cc6db97d8c14100c170e2fa53f30b6e2b4 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/bin/sh
2### BEGIN INIT INFO
3# Provides: nfs-kernel-server
4# Required-Start: $remote_fs nfs-common $portmap hwclock
5# Required-Stop: $remote_fs nfs-common $portmap hwclock
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8# Short-Description: Kernel NFS server support
9# Description: NFS is a popular protocol for file sharing across
10# TCP/IP networks. This service provides NFS server
11# functionality, which is configured via the
12# /etc/exports file.
13### END INIT INFO
14#
15# Startup script for nfs-utils
16#
17# Source function library.
18. /etc/init.d/functions
19#
20# The environment variable NFS_SERVERS may be set in /etc/default/nfsd
21# Other control variables may be overridden here too
22test -r /etc/default/nfsd && . /etc/default/nfsd
23#
24# Location of executables:
25test -x "$NFS_MOUNTD" || NFS_MOUNTD=/usr/sbin/rpc.mountd
26test -x "$NFS_NFSD" || NFS_NFSD=/usr/sbin/rpc.nfsd
27#
28# The user mode program must also exist (it just starts the kernel
29# threads using the kernel module code).
30test -x "$NFS_MOUNTD" || exit 0
31test -x "$NFS_NFSD" || exit 0
32#
33# Default is 8 threads, value is settable between 1 and the truely
34# ridiculous 99
35test "$NFS_SERVERS" != "" && test "$NFS_SERVERS" -gt 0 && test "$NFS_SERVERS" -lt 100 || NFS_SERVERS=8
36#
37#----------------------------------------------------------------------
38# Startup and shutdown functions.
39# Actual startup/shutdown is at the end of this file.
40#mountd
41start_mountd(){
42 echo -n 'starting mountd: '
Brad Bishop6e60e8b2018-02-01 10:27:11 -050043 start-stop-daemon --start --exec "$NFS_MOUNTD" -- "$@"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044 echo done
45}
46stop_mountd(){
47 echo -n 'stopping mountd: '
48 start-stop-daemon --stop --quiet --exec "$NFS_MOUNTD"
49 echo done
50}
51#
52#nfsd
53start_nfsd(){
54 modprobe -q nfsd
55 grep -q nfsd /proc/filesystems || {
56 echo NFS daemon support not enabled in kernel
57 exit 1
58 }
59 grep -q nfsd /proc/mounts || mount -t nfsd nfsd /proc/fs/nfsd
60 grep -q nfsd /proc/mounts || {
61 echo nfsd filesystem could not be mounted at /proc/fs/nfsd
62 exit 1
63 }
64
65 echo -n "starting $1 nfsd kernel threads: "
66 start-stop-daemon --start --exec "$NFS_NFSD" -- "$@"
67 echo done
68}
69delay_nfsd(){
70 for delay in 0 1 2 3 4 5 6 7 8 9
71 do
72 if pidof nfsd >/dev/null
73 then
74 echo -n .
75 sleep 1
76 else
77 return 0
78 fi
79 done
80 return 1
81}
82stop_nfsd(){
83 # WARNING: this kills any process with the executable
84 # name 'nfsd'.
85 echo -n 'stopping nfsd: '
86 start-stop-daemon --stop --quiet --signal 1 --name nfsd
87 if delay_nfsd || {
88 echo failed
89 echo ' using signal 9: '
90 start-stop-daemon --stop --quiet --signal 9 --name nfsd
91 delay_nfsd
92 }
93 then
94 echo done
95 else
96 echo failed
97 fi
98}
99
100#----------------------------------------------------------------------
101#
102# supported options:
103# start
104# stop
105# reload: reloads the exports file
106# restart: stops and starts mountd
107#FIXME: need to create the /var/lib/nfs/... directories
108case "$1" in
109 start)
Brad Bishop64c979e2019-11-04 13:55:29 -0500110 test -r /etc/exports && exportfs -r
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111 start_nfsd "$NFS_SERVERS"
112 start_mountd
113 test -r /etc/exports && exportfs -a;;
114 stop) exportfs -ua
115 stop_mountd
116 stop_nfsd;;
117 status)
118 status /usr/sbin/rpc.mountd
119 RETVAL=$?
120 status nfsd
121 rval=$?
122 [ $RETVAL -eq 0 ] && exit $rval
123 exit $RETVAL;;
124 reload) test -r /etc/exports && exportfs -r;;
125 restart)
126 $0 stop
127 $0 start;;
128 *) echo "Usage: $0 {start|stop|status|reload|restart}"
129 exit 1;;
130esac