@@ -34,7 +34,6 @@ readonly ENV_VAR_NFS_PORT_STATD_OUT='NFS_PORT_STATD_OUT'
34
34
readonly ENV_VAR_NFS_VERSION=' NFS_VERSION'
35
35
readonly ENV_VAR_NFS_LOG_LEVEL=' NFS_LOG_LEVEL'
36
36
37
- readonly DEFAULT_NFS_SERVER_THREAD_COUNT=" $( grep -Ec ^processor /proc/cpuinfo) "
38
37
readonly DEFAULT_NFS_PORT=2049
39
38
readonly DEFAULT_NFS_PORT_MOUNTD=32767
40
39
readonly DEFAULT_NFS_PORT_STATD_IN=32765
@@ -225,11 +224,6 @@ get_requested_nfs_version() {
225
224
echo " ${! ENV_VAR_NFS_VERSION:- $DEFAULT_NFS_VERSION } "
226
225
}
227
226
228
- get_requested_count_nfsd_threads () {
229
-
230
- echo " ${! ENV_VAR_NFS_SERVER_THREAD_COUNT:- $DEFAULT_NFS_SERVER_THREAD_COUNT } "
231
- }
232
-
233
227
get_requested_port_mountd () {
234
228
235
229
echo " ${! ENV_VAR_NFS_PORT_MOUNTD:- $DEFAULT_NFS_PORT_MOUNTD } "
@@ -308,6 +302,17 @@ is_debug_requested() {
308
302
return 1
309
303
}
310
304
305
+ get_requested_count_nfsd_threads () {
306
+
307
+ if [[ -n " ${! ENV_VAR_NFS_SERVER_THREAD_COUNT} " ]]; then
308
+ echo " ${! ENV_VAR_NFS_SERVER_THREAD_COUNT} "
309
+ else
310
+ local -r cpu_count=" $( grep -Ec ^processor /proc/cpuinfo) "
311
+ on_failure bail ' unable to detect CPU count. set NFS_SERVER_THREAD_COUNT environment variable'
312
+ echo " $cpu_count " ;
313
+ fi
314
+ }
315
+
311
316
# #####################################################################################
312
317
# ## runtime configuration assertions
313
318
# #####################################################################################
@@ -383,6 +388,13 @@ assert_cap_sysadmin() {
383
388
fi
384
389
}
385
390
391
+ assert_log_level () {
392
+
393
+ if ! echo " ${! ENV_VAR_NFS_LOG_LEVEL} " | grep -Eqi " ^$|^DEBUG$" ; then
394
+ bail " the only acceptable value for $ENV_VAR_NFS_LOG_LEVEL is DEBUG"
395
+ fi
396
+ }
397
+
386
398
387
399
# #####################################################################################
388
400
# ## initialization
@@ -470,6 +482,7 @@ init_assertions() {
470
482
assert_port " $ENV_VAR_NFS_PORT_STATD_OUT "
471
483
assert_nfs_version
472
484
assert_nfsd_threads
485
+ assert_log_level
473
486
474
487
# check kernel modules
475
488
assert_kernel_mod nfs
@@ -527,15 +540,35 @@ boot_helper_get_version_flags() {
527
540
echo " ${flags[@]} "
528
541
}
529
542
530
- boot_helper_check_backgrounded_process () {
543
+ boot_helper_start_daemon () {
544
+
545
+ local -r msg=" $1 "
546
+ local -r daemon=" $2 "
547
+ shift 2
548
+ local -r daemon_args=(" $@ " )
549
+
550
+ log " $msg "
551
+ " $daemon " " ${daemon_args[@]} "
552
+ on_failure stop " $daemon failed"
553
+ }
554
+
555
+ boot_helper_start_non_daemon () {
556
+
557
+ local -r msg=" $1 "
558
+ local -r process=" $2 "
559
+ shift 2
560
+ local -r process_args=(" $@ " )
561
+
562
+ log " $msg "
563
+ " $process " " ${process_args[@]} " &
531
564
532
565
local -r bg_pid=$!
533
566
534
567
# somewhat arbitrary assumption that if the process isn't dead already, it will die within 1/20 of a second. for our
535
568
# purposes this works just fine, but if someone has a better solution please open a PR.
536
569
sleep .05
537
570
kill -0 $bg_pid 2> /dev/null
538
- on_failure stop " $1 failed"
571
+ on_failure stop " $process failed"
539
572
}
540
573
541
574
# #####################################################################################
@@ -556,9 +589,7 @@ boot_main_exportfs() {
556
589
args+=(' -v' )
557
590
fi
558
591
559
- log ' exporting filesystem(s)'
560
- $PATH_BIN_EXPORTFS " ${args[@]} "
561
- on_failure stop ' exportfs failed'
592
+ boot_helper_start_daemon ' exporting filesystem(s)' $PATH_BIN_EXPORTFS " ${args[@]} "
562
593
}
563
594
564
595
boot_main_mountd () {
@@ -572,19 +603,16 @@ boot_main_mountd() {
572
603
fi
573
604
574
605
# yes, rpc.mountd is required even for NFS v4: https://forums.gentoo.org/viewtopic-p-7724856.html#7724856
575
- log " starting rpc.mountd on port $port "
576
- $PATH_BIN_MOUNTD " ${args[@]} "
577
- on_failure stop ' rpc.mountd failed'
606
+ boot_helper_start_daemon " starting rpc.mountd on port $port " $PATH_BIN_MOUNTD " ${args[@]} "
578
607
}
579
608
580
609
boot_main_rpcbind () {
581
610
582
611
# rpcbind isn't required for NFSv4, but if it's not running then nfsd takes over 5 minutes to start up.
583
612
# it's a bug in either nfs-utils or the kernel, and the code of both is over my head.
584
613
# so as a workaround we start rpcbind now and (in v4-only scenarios) kill it after nfsd starts up
585
- log ' starting rpcbind'
586
- $PATH_BIN_RPCBIND -ds
587
- on_failure stop ' rpcbind failed'
614
+ local -r args=(' -ds' )
615
+ boot_helper_start_daemon ' starting rpcbind' $PATH_BIN_RPCBIND " ${args[@]} "
588
616
}
589
617
590
618
boot_main_idmapd () {
@@ -593,14 +621,14 @@ boot_main_idmapd() {
593
621
return
594
622
fi
595
623
596
- local args=(' -f -S' )
624
+ local args=(' -S' )
625
+ local func=boot_helper_start_daemon
597
626
if is_debug_requested; then
598
- args+=(' -vvv' )
627
+ args+=(' -vvv' ' -f' )
628
+ func=boot_helper_start_non_daemon
599
629
fi
600
630
601
- log ' starting idmapd'
602
- $PATH_BIN_IDMAPD " ${args[@]} " &
603
- boot_helper_check_backgrounded_process $PATH_BIN_IDMAPD
631
+ $func ' starting idmapd' $PATH_BIN_IDMAPD " ${args[@]} "
604
632
}
605
633
606
634
boot_main_statd () {
@@ -613,9 +641,7 @@ boot_main_statd() {
613
641
local -r port_out=$( get_requested_port_statd_out)
614
642
local -r args=(' --no-notify' ' --port' " $port_in " ' --outgoing-port' " $port_out " )
615
643
616
- log " starting statd on port $port_in (outgoing connections from port $port_out )"
617
- $PATH_BIN_STATD " ${args[@]} "
618
- on_failure stop ' statd failed'
644
+ boot_helper_start_daemon " starting statd on port $port_in (outgoing from port $port_out )" $PATH_BIN_STATD " ${args[@]} "
619
645
}
620
646
621
647
boot_main_nfsd () {
@@ -630,9 +656,7 @@ boot_main_nfsd() {
630
656
args+=(' --debug' )
631
657
fi
632
658
633
- log " starting rpc.nfsd on port $port with $threads server thread(s)"
634
- $PATH_BIN_NFSD " ${args[@]} "
635
- on_failure stop ' rpc.nfsd failed'
659
+ boot_helper_start_daemon " starting rpc.nfsd on port $port with $threads server thread(s)" $PATH_BIN_NFSD " ${args[@]} "
636
660
637
661
if ! is_nfs3_enabled; then
638
662
kill_process_if_running " $PATH_BIN_RPCBIND "
@@ -650,9 +674,7 @@ boot_main_svcgssd() {
650
674
args+=(' -vvv' )
651
675
fi
652
676
653
- log ' starting rpc.svcgssd'
654
- $PATH_BIN_RPC_SVCGSSD " ${args[@]} " &
655
- boot_helper_check_backgrounded_process $PATH_BIN_RPC_SVCGSSD
677
+ boot_helper_start_non_daemon ' starting rpc.svcgssd' $PATH_BIN_RPC_SVCGSSD " ${args[@]} "
656
678
}
657
679
658
680
0 commit comments