diff --git a/.env.example b/.env.example index e3089e7..f2b213e 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ ENABLE_REAPER=false -REAPER_TIMEOUT=3600 +REAPER_TIMEOUT=0 SSH_AUTHORIZED_KEYS= SSH_AUTOSTART_SSHD=true SSH_AUTOSTART_SSHD_BOOTSTRAP=true diff --git a/CHANGELOG.md b/CHANGELOG.md index 730225a..6a22210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ Summary of release changes for Version 2 - CentOS-7 - Adds improved `clean` Makefile target; includes exited containers and dangling images. - Adds feature to optionally exit the container after a specified timout period. - Adds `ENABLE_REAPER` with a default value of `false` to enable the `reaper` service. -- Adds `REAPER_TIMEOUT` with a default value of `3600` seconds (i.e 1 hour). +- Adds `REAPER_TIMEOUT` with a default value of `0` seconds (i.e no timeout delay). - Fixes port incrementation failures when installing systemd units via `scmi`. - Fixes etcd port registration failures when installing systemd units via `scmi` with the `--register` option. - Fixes binary paths in systemd unit files for compatibility with both EL and Ubuntu hosts. diff --git a/Dockerfile b/Dockerfile index d79d8f1..b854df9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -94,7 +94,7 @@ EXPOSE 22 # ------------------------------------------------------------------------------ ENV \ ENABLE_REAPER="false" \ - REAPER_TIMEOUT="3600" \ + REAPER_TIMEOUT="0" \ SSH_AUTHORIZED_KEYS="" \ SSH_AUTOSTART_SSHD="true" \ SSH_AUTOSTART_SSHD_BOOTSTRAP="true" \ diff --git a/environment.mk b/environment.mk index 197b49e..0b59271 100644 --- a/environment.mk +++ b/environment.mk @@ -24,7 +24,7 @@ STARTUP_TIME ?= 2 # Application container configuration # ------------------------------------------------------------------------------ ENABLE_REAPER ?= false -REAPER_TIMEOUT ?= 3600 +REAPER_TIMEOUT ?= 0 SSH_AUTHORIZED_KEYS ?= SSH_AUTOSTART_SSHD ?= true SSH_AUTOSTART_SSHD_BOOTSTRAP ?= true diff --git a/src/etc/supervisord.d/01-reaper.conf b/src/etc/supervisord.d/01-reaper.conf index adaeb25..641262c 100644 --- a/src/etc/supervisord.d/01-reaper.conf +++ b/src/etc/supervisord.d/01-reaper.conf @@ -1,7 +1,7 @@ [program:reaper] autorestart = false autostart = %(ENV_ENABLE_REAPER)s -command = /usr/sbin/reaper --verbose --wall-timeout 30 --wall="Session expiring in 30 seconds." +command = /usr/sbin/reaper --verbose --timeout %(ENV_REAPER_TIMEOUT)s --wall-timeout 30 --wall="Session expiring in 30 seconds." priority = 1 startsecs = 0 stderr_logfile = /dev/stderr diff --git a/src/etc/systemd/system/centos-ssh@.service b/src/etc/systemd/system/centos-ssh@.service index 30d2291..f4554f2 100644 --- a/src/etc/systemd/system/centos-ssh@.service +++ b/src/etc/systemd/system/centos-ssh@.service @@ -57,7 +57,7 @@ Environment="DOCKER_IMAGE_TAG={{RELEASE_VERSION}}" Environment="DOCKER_PORT_MAP_TCP_22=2020" Environment="DOCKER_USER=jdeathe" Environment="ENABLE_REAPER=false" -Environment="REAPER_TIMEOUT=3600" +Environment="REAPER_TIMEOUT=0" Environment="SSH_AUTHORIZED_KEYS=" Environment="SSH_AUTOSTART_SSHD=true" Environment="SSH_AUTOSTART_SSHD_BOOTSTRAP=true" diff --git a/src/opt/scmi/environment.sh b/src/opt/scmi/environment.sh index 836bf6f..93956d0 100644 --- a/src/opt/scmi/environment.sh +++ b/src/opt/scmi/environment.sh @@ -25,7 +25,7 @@ STARTUP_TIME="${STARTUP_TIME:-2}" # Application container configuration # ------------------------------------------------------------------------------ ENABLE_REAPER="${ENABLE_REAPER:-false}" -REAPER_TIMEOUT="${REAPER_TIMEOUT:-3600}" +REAPER_TIMEOUT="${REAPER_TIMEOUT:-0}" SSH_AUTHORIZED_KEYS="${SSH_AUTHORIZED_KEYS:-}" SSH_AUTOSTART_SSHD="${SSH_AUTOSTART_SSHD:-true}" SSH_AUTOSTART_SSHD_BOOTSTRAP="${SSH_AUTOSTART_SSHD_BOOTSTRAP:-true}" diff --git a/src/usr/sbin/reaper b/src/usr/sbin/reaper index bec4928..4d69fd5 100755 --- a/src/usr/sbin/reaper +++ b/src/usr/sbin/reaper @@ -35,20 +35,6 @@ function __delete_lock () fi } -function __get_reaper_timeout () -{ - local -r default_value="${1:-3600}" - - local value="${REAPER_TIMEOUT}" - - if ! __is_valid_reaper_timeout "${value}" - then - value="${default_value}" - fi - - printf -- '%s' "${value}" -} - function __is_valid_get () { local -r get_options='^(end|start|ttl)$' @@ -75,7 +61,7 @@ function __is_valid_positive_integer () return 1 } -function __is_valid_reaper_timeout () +function __is_valid_timeout () { __is_valid_positive_integer "${@}" } @@ -112,6 +98,9 @@ function __usage () If not specified the default is pid 1. -s, --signal SIG Send the signal SIG to the process. If not specified the default is SIGTERM. + -t, --timeout SECONDS Time in seconds to wait before sending the + signal to the process. The default is 0 seconds + which indicates no delay. -v, --verbose Output informational messages. If not specified the default is quiet. -w, --wall MESSAGE Set a wall message to send before session end. @@ -126,9 +115,6 @@ function main () { local -r lock_file="/var/lock/subsys/reaper" local -r state_file="/var/lib/misc/reaper" - local -r timeout="$( - __get_reaper_timeout - )" local current_time local get @@ -137,6 +123,7 @@ function main () local session_start local session_end local state_value + local timeout="0" local verbose="false" local wall_message local wall_timeout="30" @@ -171,6 +158,14 @@ function main () signal="${2}" shift 2 || break ;; + -t|--timeout) + timeout="${2}" + shift 2 || break + ;; + --timeout=*) + timeout="${1#*=}" + shift 1 + ;; -v|--verbose) verbose="true" shift 1 @@ -256,6 +251,13 @@ function main () EXIT INT TERM __create_lock + if ! __is_valid_timeout "${timeout}" + then + >&2 printf -- \ + 'ERROR: Invalid --timeout\n' \ + __usage + fi + if ! __is_valid_wall_timeout "${wall_timeout}" then >&2 printf -- \ @@ -263,23 +265,23 @@ function main () __usage fi - if (( timeout > 0 )) + if [[ -z ${wall_message} ]] \ + || (( timeout <= wall_timeout )) then - trap __reap \ - EXIT INT TERM + wall_timeout="0" + fi - if [[ -z ${wall_message} ]] \ - || (( timeout <= wall_timeout )) - then - wall_timeout="0" - fi + session_start="$( + date -u +%s + )" - session_start="$( - date -u +%s - )" + trap __reap \ + EXIT INT TERM - __create_state + __create_state + if (( timeout > 0 )) + then if coproc read -t "$(( ${timeout} - ${wall_timeout} ))" then wait "${!}" || : @@ -294,13 +296,13 @@ function main () fi fi fi + fi - if [[ ${verbose} == true ]] - then - printf -- \ - 'INFO: %s expiring session.\n' \ - "${0##*/}" - fi + if [[ ${verbose} == true ]] + then + printf -- \ + 'INFO: %s expiring session.\n' \ + "${0##*/}" fi exit 0