Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit f283d48

Browse files
committed
code cleanup and ditch redundant shutdown steps
1 parent 7af66e7 commit f283d48

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

entrypoint.sh

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ log_error() {
8282

8383
log_header() {
8484

85-
echo "\
86-
85+
echo "
8786
==================================================================
8887
$(echo "$1" | awk '{print toupper($0)}')
8988
=================================================================="
@@ -169,18 +168,28 @@ stop_nfsd() {
169168
stop_exportfs() {
170169

171170
log 'un-exporting filesystem(s)'
172-
$PATH_BIN_EXPORTFS -ua
171+
$PATH_BIN_EXPORTFS -uav
173172
on_failure warn 'unable to un-export filesystem(s)'
174173
}
175174

176175
stop() {
177176

178177
log_header 'terminating ...'
179178

180-
kill_process_if_running "$PATH_BIN_RPC_SVCGSSD"
179+
if is_kerberos_enabled; then
180+
kill_process_if_running "$PATH_BIN_RPC_SVCGSSD"
181+
fi
182+
181183
stop_nfsd
182-
kill_process_if_running "$PATH_BIN_IDMAPD"
183-
kill_process_if_running "$PATH_BIN_STATD"
184+
185+
if is_idmapd_enabled; then
186+
kill_process_if_running "$PATH_BIN_IDMAPD"
187+
fi
188+
189+
if is_nfs3_enabled; then
190+
kill_process_if_running "$PATH_BIN_STATD"
191+
fi
192+
184193
kill_process_if_running "$PATH_BIN_MOUNTD"
185194
stop_exportfs
186195
kill_process_if_running "$PATH_BIN_RPCBIND"
@@ -230,15 +239,28 @@ get_requested_port_statd_out() {
230239
is_kerberos_enabled() {
231240

232241
if [[ -n "${!ENV_VAR_NFS_ENABLE_KERBEROS}" ]]; then
233-
echo 1
242+
return 0
234243
fi
244+
245+
return 1
235246
}
236247

237248
is_nfs3_enabled() {
238249

239250
if [[ -z "${!ENV_VAR_NFS_DISABLE_VERSION_3}" ]]; then
240-
echo 1
251+
return 0
241252
fi
253+
254+
return 1
255+
}
256+
257+
is_idmapd_enabled() {
258+
259+
if [[ "$(get_requested_nfs_version)" != '3' && -f "$PATH_FILE_ETC_IDMAPD_CONF" ]]; then
260+
return 0
261+
fi
262+
263+
return 1
242264
}
243265

244266

@@ -276,21 +298,19 @@ assert_port() {
276298

277299
assert_nfs_version() {
278300

279-
local -r version="$(get_requested_nfs_version)"
301+
local -r requested_version="$(get_requested_nfs_version)"
280302

281-
echo "$version" | grep -Eq '^(3|4|4\.1|4\.2)$'
303+
echo "$requested_version" | grep -Eq '^3|4(?:\.[1-2])?$'
282304
on_failure bail "please set $ENV_VAR_NFS_VERSION to one of: 4.2, 4.1, 4, 3"
283305

284-
if [[ -z "$(is_nfs3_enabled)" && "$version" = '3' ]]; then
306+
if [[ ( ! $(is_nfs3_enabled) ) && "$requested_version" = '3' ]]; then
285307
bail 'you cannot simultaneously enable and disable NFS version 3'
286308
fi
287309
}
288310

289311
assert_nfsd_threads() {
290312

291-
local -r reqd_thread_count=$(get_requested_count_nfsd_threads)
292-
293-
if [[ "$reqd_thread_count" -lt 1 ]]; then
313+
if [[ "$(get_requested_count_nfsd_threads)" -lt 1 ]]; then
294314
bail "please set $ENV_VAR_NFS_SERVER_THREAD_COUNT to a positive integer"
295315
fi
296316
}
@@ -407,7 +427,7 @@ init_assertions() {
407427
assert_linux_capabilities
408428

409429
# perform Kerberos assertions
410-
if [[ -n "$(is_kerberos_enabled)" ]]; then
430+
if is_kerberos_enabled; then
411431

412432
assert_file_provided "$PATH_FILE_ETC_IDMAPD_CONF"
413433
assert_file_provided "$PATH_FILE_ETC_KRB5_KEYTAB"
@@ -435,14 +455,14 @@ boot_helper_mount() {
435455

436456
boot_helper_get_version_flags() {
437457

438-
local -r reqd_version="$(get_requested_nfs_version)"
439-
local flags=('--nfs-version' "$reqd_version" '--no-nfs-version' 2)
458+
local -r requested_version="$(get_requested_nfs_version)"
459+
local flags=('--nfs-version' "$requested_version" '--no-nfs-version' 2)
440460

441-
if [[ -z "$(is_nfs3_enabled)" ]]; then
461+
if ! is_nfs3_enabled; then
442462
flags+=('--no-nfs-version' 3)
443463
fi
444464

445-
if [[ "$reqd_version" = '3' ]]; then
465+
if [[ "$requested_version" = '3' ]]; then
446466
flags+=('--no-nfs-version' 4)
447467
fi
448468

@@ -493,7 +513,7 @@ boot_main_rpcbind() {
493513

494514
boot_main_idmapd() {
495515

496-
if [[ "$(get_requested_nfs_version)" != '3' && -f "$PATH_FILE_ETC_IDMAPD_CONF" ]]; then
516+
if is_idmapd_enabled; then
497517
log 'starting idmapd'
498518
$PATH_BIN_IDMAPD -v -S
499519
on_failure stop 'idmapd failed'
@@ -502,7 +522,7 @@ boot_main_idmapd() {
502522

503523
boot_main_statd() {
504524

505-
if [[ -z "$(is_nfs3_enabled)" ]]; then
525+
if ! is_nfs3_enabled; then
506526
return
507527
fi
508528

@@ -527,14 +547,14 @@ boot_main_nfsd() {
527547
$PATH_BIN_NFSD "${args[@]}"
528548
on_failure stop 'rpc.nfsd failed'
529549

530-
if [ -z "$(is_nfs3_enabled)" ]; then
550+
if ! is_nfs3_enabled; then
531551
kill_process_if_running "$PATH_BIN_RPCBIND"
532552
fi
533553
}
534554

535555
boot_main_svcgssd() {
536556

537-
if [[ -z "$(is_kerberos_enabled)" ]]; then
557+
if ! is_kerberos_enabled; then
538558
return
539559
fi
540560

@@ -568,7 +588,7 @@ summarize_nfs_versions() {
568588
;;
569589
esac
570590

571-
if [[ -n "$(is_nfs3_enabled)" && "$reqd_version" =~ ^4 ]]; then
591+
if [[ $(is_nfs3_enabled) && "$reqd_version" =~ ^4 ]]; then
572592
versions="$versions, 3"
573593
fi
574594

@@ -598,7 +618,7 @@ summarize_ports() {
598618
local -r port_mountd="$(get_requested_port_mountd)"
599619
local -r port_statd_in="$(get_requested_port_statd_in)"
600620

601-
if [[ -z "$(is_nfs3_enabled)" ]]; then
621+
if ! is_nfs3_enabled; then
602622
log "list of container ports that should be exposed: $port_nfsd (TCP)"
603623
else
604624
log 'list of container ports that should be exposed:'

0 commit comments

Comments
 (0)