gensec: Fix CID 242642 Unchecked return value
[Samba.git] / ctdb / config / nfs-linux-kernel-callout
blob5e770317679633f22b1fa07321cce7e73a10bbdf
1 #!/bin/sh
3 # Exit on 1st error
4 set -e
6 # Red Hat
7 nfs_service="nfs"
8 nfslock_service="nfslock"
9 nfs_config="/etc/sysconfig/nfs"
11 # SUSE
12 #nfs_service="nfsserver"
13 #nfslock_service=""
14 #nfs_config="/etc/sysconfig/nfs"
16 # Debian
17 #nfs_service="nfs-kernel-server"
18 #nfslock_service=""
19 #nfs_config="/etc/default/nfs-kernel-server"
21 # Override for unit testing
22 if [ -z "$PROCFS_PATH" ] ; then
23 PROCFS_PATH="/proc"
26 ##################################################
28 usage ()
30 _c=$(basename $0)
31 cat <<EOF
32 usage: $_c { shutdown | startup }
33 $_c { stop | start } { nfs | nlockmgr }
34 $_c { monitor-list-shares | monitor-post }
35 $_c { register }
36 EOF
37 exit 1
41 ##################################################
42 # Basic service stop and start
44 basic_stop ()
46 case "$1" in
47 nfs)
48 service "$nfs_service" stop
49 if [ -n "$nfslock_service" ] ; then
50 service "$nfslock_service" stop
53 nfslock)
54 if [ -n "$nfslock_service" ] ; then
55 service "$nfslock_service" stop
56 else
57 service "$nfs_service" stop
61 usage
62 esac
65 basic_start ()
67 case "$1" in
68 nfs)
69 if [ -n "$nfslock_service" ] ; then
70 service "$nfslock_service" start
72 service "$nfs_service" start
74 nfslock)
75 if [ -n "$nfslock_service" ] ; then
76 service "$nfslock_service" start
77 else
78 service "$nfs_service" start
82 usage
83 esac
86 ##################################################
87 # service "stop" and "start" options for restarting
89 service_stop ()
91 case "$1" in
92 nfs)
93 echo 0 >"${PROCFS_PATH}/fs/nfsd/threads"
94 basic_stop "nfs" >/dev/null 2>&1 || true
95 pkill -9 nfsd
97 nlockmgr)
98 basic_stop "nfslock" >/dev/null 2>&1 || true
101 usage
102 esac
105 service_start ()
107 case "$1" in
108 nfs)
109 basic_start "nfs"
111 nlockmgr)
112 basic_start "nfslock"
115 usage
116 esac
119 ##################################################
120 # service init startup and final shutdown
122 nfs_shutdown ()
124 basic_stop "nfs"
127 nfs_startup ()
129 basic_stop "nfs" || true
130 basic_start "nfs"
131 _f="${PROCFS_PATH}/sys/net/ipv4/tcp_tw_recycle"
132 if [ "$_f" ] ; then
133 echo 1 >"$_f"
137 ##################################################
138 # monitor-post support
140 nfs_check_thread_count ()
142 # Load NFS configuration to get desired number of threads.
143 if [ -r "$nfs_config" ] ; then
144 . "$nfs_config"
147 # If $RPCNFSDCOUNT/$USE_KERNEL_NFSD_NUMBER isn't set then we could
148 # guess the default from the initscript. However, let's just
149 # assume that those using the default don't care about the number
150 # of threads and that they have switched on this feature in error.
151 _configured_threads="${RPCNFSDCOUNT:-${USE_KERNEL_NFSD_NUMBER}}"
152 [ -n "$_configured_threads" ] || return 0
154 _threads_file="${PROCFS_PATH}/fs/nfsd/threads"
156 # nfsd should be running the configured number of threads. If
157 # there are a different number of threads then tell nfsd the
158 # correct number.
159 read _running_threads <"$_threads_file"
160 # Intentionally not arithmetic comparison - avoids extra errors
161 # when above fails...
162 if [ "$_running_threads" != "$_configured_threads" ] ; then
163 echo "Attempting to correct number of nfsd threads from ${_running_threads} to ${_configured_threads}"
164 echo "$_configured_threads" >"$_threads_file"
168 ##################################################
169 # list share directories
171 nfs_monitor_list_shares ()
173 exportfs -v |
174 grep '^/' |
175 sed -e 's@[[:space:]][[:space:]]*[^[:space:]()][^[:space:]()]*([^[:space:]()][^[:space:]()]*)$@@' |
176 sort -u
179 ##################################################
181 nfs_register ()
183 cat <<EOF
184 shutdown
185 startup
186 stop
187 start
188 monitor-list-shares
189 monitor-post
193 ##################################################
195 case "$1" in
196 shutdown)
197 nfs_shutdown
199 startup)
200 nfs_startup
202 stop)
203 service_stop "$2"
205 start)
206 service_start "$2"
208 monitor-list-shares)
209 nfs_monitor_list_shares
211 monitor-post)
212 nfs_check_thread_count
214 register)
215 nfs_register
217 monitor-pre|releaseip|takeip)
218 # Not required/implemented
222 usage
223 esac