X-Git-Url: https://git.xandkar.net/?p=khatus.git;a=blobdiff_plain;f=x4%2Fbin%2Fkhatus_x4_lib_common_sensor.sh;h=afb4cdbc8b80d34b73e30f6696f2cc2894938be4;hp=fae1356344c03f12eefe9610ad046c3aed7c1947;hb=HEAD;hpb=4411059d155436af0e80e5e6c3928ac8373093d6 diff --git a/x4/bin/khatus_x4_lib_common_sensor.sh b/x4/bin/khatus_x4_lib_common_sensor.sh index fae1356..afb4cdb 100755 --- a/x4/bin/khatus_x4_lib_common_sensor.sh +++ b/x4/bin/khatus_x4_lib_common_sensor.sh @@ -2,6 +2,10 @@ set -e +# ============================================================================= +# Private +# ============================================================================= + # Defaults prefix='/dev/shm/khatus' host="$(hostname)" @@ -28,6 +32,9 @@ set_common_options() { interval="$2" shift 2 esac + ;; --) + shift 1 + break ;; *) shift 1 esac @@ -85,16 +92,16 @@ run_in_foreground() { trap true INT trap exit TERM trap pid_file_remove EXIT - $run_as + $1 } run_in_background_2nd_fork() { - run_in_foreground & + run_in_foreground $1 & pid_file_create_of_child } run_in_background() { - run_in_background_2nd_fork & + run_in_background_2nd_fork $1 & } run() { @@ -108,15 +115,30 @@ run() { pid_file_test case "$run_in" in 'background') - run_in_background + run_in_background $1 ;; 'foreground') pid_file_create_of_parent - run_in_foreground + run_in_foreground $1 ;; *) printf "Error - illegal value for \$run_in: $run_in\n" 1>&2 exit 1 esac } +# ============================================================================= +# API +# ----------------------------------------------------------------------------- +# run_as_poller +# run_as_streamer +# ============================================================================= + +run_as_poller() { + run 'poller' +} + +run_as_streamer() { + run 'streamer' +} + set_common_options $@ init_dirs