From 9c6808d3bdd3c9e359f9d84843488d85c4555288 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sun, 20 Jun 2021 02:19:39 -0500 Subject: [PATCH] Reload resources on SIGHUP --- rowbot | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/rowbot b/rowbot index b9c3028..15eee05 100755 --- a/rowbot +++ b/rowbot @@ -106,6 +106,8 @@ while (( $# )); do shift done +prog_args=( "$@" ) + ### # default config ## @@ -125,7 +127,7 @@ for file do # shellcheck disable=SC1090 . "$file" # ha, dot file else - die 'could not locate config file %s' "$file" + die "could not locate config file %s" "$file" fi done @@ -203,7 +205,7 @@ if [[ $reload = yes ]]; then fi ### -# process management +# process/resource management ### cleanup() { @@ -244,6 +246,30 @@ alarm-handler() { trap alarm-handler ALRM +config-reload() { + local file + info "received HUP signal" + + for file in "${prog_args[@]}"; do + if [[ -f $file ]]; then + debug "loading config file %s" "$file" + # These files are provided dynamically at run-time. + # shellcheck disable=SC1090 + . "$file" + else + die "could not locate config file %s" "$file" + fi + done + + if (( log_fd != 1 )); then + debug "closing and re-opening log" + exec {log_fd}>&- + exec {log_fd}>"$log" + fi +} + +trap config-reload HUP + ### # net code ###