5 # =============================================================================
7 # =============================================================================
10 prefix
='/dev/shm/khatus'
12 sensor
="$(basename $0)"
13 run_in
='foreground' # foreground | background
14 run_as
='poller' # poller | streamer
15 interval
=1 # Only relevant if run_as poller, ignored otherwise.
17 set_common_options
() {
29 printf "Option $1 requires and argument\n" >&2
45 work_dir
="${prefix}/${host}/${sensor}"
46 out_dir
="${work_dir}/out"
47 err_file
="${work_dir}/err"
48 pid_file
="${work_dir}/pid"
57 printf "%s\n" "$val" > "${out_dir}/${key}"
70 pid_file_create_of_parent
() {
71 printf "$$\n" > "$pid_file"
74 pid_file_create_of_child
() {
75 printf "$!\n" > "$pid_file"
79 if test -e "$pid_file"
81 printf "Error - $sensor already running (i.e. PID file exists at $pid_file)\n" 1>&2
91 # TODO: Why do INT and EXIT traps only work in combination?
94 trap pid_file_remove EXIT
98 run_in_background_2nd_fork
() {
99 run_in_foreground
$1 &
100 pid_file_create_of_child
103 run_in_background
() {
104 run_in_background_2nd_fork
$1 &
109 in 'poller' |
'streamer')
112 printf "Error - illegal value for \$run_as: $run_in\n" 1>&2
120 pid_file_create_of_parent
123 printf "Error - illegal value for \$run_in: $run_in\n" 1>&2
128 # =============================================================================
130 # -----------------------------------------------------------------------------
133 # =============================================================================
143 set_common_options $@