Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
#695: Adds --timeout parameter to reaper and sets default timeout of …
Browse files Browse the repository at this point in the history
…0 (i.e. immediate execution).
  • Loading branch information
jdeathe committed Jun 17, 2019
1 parent 5447f0c commit 5e6ec08
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
2 changes: 1 addition & 1 deletion environment.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/etc/supervisord.d/01-reaper.conf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/etc/systemd/system/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/opt/scmi/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
74 changes: 38 additions & 36 deletions src/usr/sbin/reaper
Original file line number Diff line number Diff line change
Expand Up @@ -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)$'
Expand All @@ -75,7 +61,7 @@ function __is_valid_positive_integer ()
return 1
}

function __is_valid_reaper_timeout ()
function __is_valid_timeout ()
{
__is_valid_positive_integer "${@}"
}
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -256,30 +251,37 @@ 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 -- \
'ERROR: Invalid --wall-timeout\n' \
__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 "${!}" || :
Expand All @@ -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
Expand Down

0 comments on commit 5e6ec08

Please sign in to comment.