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

Commit 5e6ec08

Browse files
committed
#695: Adds --timeout parameter to reaper and sets default timeout of 0 (i.e. immediate execution).
1 parent 5447f0c commit 5e6ec08

File tree

8 files changed

+45
-43
lines changed

8 files changed

+45
-43
lines changed

Diff for: .env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ENABLE_REAPER=false
2-
REAPER_TIMEOUT=3600
2+
REAPER_TIMEOUT=0
33
SSH_AUTHORIZED_KEYS=
44
SSH_AUTOSTART_SSHD=true
55
SSH_AUTOSTART_SSHD_BOOTSTRAP=true

Diff for: CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Summary of release changes for Version 2 - CentOS-7
1717
- Adds improved `clean` Makefile target; includes exited containers and dangling images.
1818
- Adds feature to optionally exit the container after a specified timout period.
1919
- Adds `ENABLE_REAPER` with a default value of `false` to enable the `reaper` service.
20-
- Adds `REAPER_TIMEOUT` with a default value of `3600` seconds (i.e 1 hour).
20+
- Adds `REAPER_TIMEOUT` with a default value of `0` seconds (i.e no timeout delay).
2121
- Fixes port incrementation failures when installing systemd units via `scmi`.
2222
- Fixes etcd port registration failures when installing systemd units via `scmi` with the `--register` option.
2323
- Fixes binary paths in systemd unit files for compatibility with both EL and Ubuntu hosts.

Diff for: Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ EXPOSE 22
9494
# ------------------------------------------------------------------------------
9595
ENV \
9696
ENABLE_REAPER="false" \
97-
REAPER_TIMEOUT="3600" \
97+
REAPER_TIMEOUT="0" \
9898
SSH_AUTHORIZED_KEYS="" \
9999
SSH_AUTOSTART_SSHD="true" \
100100
SSH_AUTOSTART_SSHD_BOOTSTRAP="true" \

Diff for: environment.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ STARTUP_TIME ?= 2
2424
# Application container configuration
2525
# ------------------------------------------------------------------------------
2626
ENABLE_REAPER ?= false
27-
REAPER_TIMEOUT ?= 3600
27+
REAPER_TIMEOUT ?= 0
2828
SSH_AUTHORIZED_KEYS ?=
2929
SSH_AUTOSTART_SSHD ?= true
3030
SSH_AUTOSTART_SSHD_BOOTSTRAP ?= true

Diff for: src/etc/supervisord.d/01-reaper.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[program:reaper]
22
autorestart = false
33
autostart = %(ENV_ENABLE_REAPER)s
4-
command = /usr/sbin/reaper --verbose --wall-timeout 30 --wall="Session expiring in 30 seconds."
4+
command = /usr/sbin/reaper --verbose --timeout %(ENV_REAPER_TIMEOUT)s --wall-timeout 30 --wall="Session expiring in 30 seconds."
55
priority = 1
66
startsecs = 0
77
stderr_logfile = /dev/stderr

Diff for: src/etc/systemd/system/[email protected]

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Environment="DOCKER_IMAGE_TAG={{RELEASE_VERSION}}"
5757
Environment="DOCKER_PORT_MAP_TCP_22=2020"
5858
Environment="DOCKER_USER=jdeathe"
5959
Environment="ENABLE_REAPER=false"
60-
Environment="REAPER_TIMEOUT=3600"
60+
Environment="REAPER_TIMEOUT=0"
6161
Environment="SSH_AUTHORIZED_KEYS="
6262
Environment="SSH_AUTOSTART_SSHD=true"
6363
Environment="SSH_AUTOSTART_SSHD_BOOTSTRAP=true"

Diff for: src/opt/scmi/environment.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ STARTUP_TIME="${STARTUP_TIME:-2}"
2525
# Application container configuration
2626
# ------------------------------------------------------------------------------
2727
ENABLE_REAPER="${ENABLE_REAPER:-false}"
28-
REAPER_TIMEOUT="${REAPER_TIMEOUT:-3600}"
28+
REAPER_TIMEOUT="${REAPER_TIMEOUT:-0}"
2929
SSH_AUTHORIZED_KEYS="${SSH_AUTHORIZED_KEYS:-}"
3030
SSH_AUTOSTART_SSHD="${SSH_AUTOSTART_SSHD:-true}"
3131
SSH_AUTOSTART_SSHD_BOOTSTRAP="${SSH_AUTOSTART_SSHD_BOOTSTRAP:-true}"

Diff for: src/usr/sbin/reaper

+38-36
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,6 @@ function __delete_lock ()
3535
fi
3636
}
3737

38-
function __get_reaper_timeout ()
39-
{
40-
local -r default_value="${1:-3600}"
41-
42-
local value="${REAPER_TIMEOUT}"
43-
44-
if ! __is_valid_reaper_timeout "${value}"
45-
then
46-
value="${default_value}"
47-
fi
48-
49-
printf -- '%s' "${value}"
50-
}
51-
5238
function __is_valid_get ()
5339
{
5440
local -r get_options='^(end|start|ttl)$'
@@ -75,7 +61,7 @@ function __is_valid_positive_integer ()
7561
return 1
7662
}
7763

78-
function __is_valid_reaper_timeout ()
64+
function __is_valid_timeout ()
7965
{
8066
__is_valid_positive_integer "${@}"
8167
}
@@ -112,6 +98,9 @@ function __usage ()
11298
If not specified the default is pid 1.
11399
-s, --signal SIG Send the signal SIG to the process.
114100
If not specified the default is SIGTERM.
101+
-t, --timeout SECONDS Time in seconds to wait before sending the
102+
signal to the process. The default is 0 seconds
103+
which indicates no delay.
115104
-v, --verbose Output informational messages.
116105
If not specified the default is quiet.
117106
-w, --wall MESSAGE Set a wall message to send before session end.
@@ -126,9 +115,6 @@ function main ()
126115
{
127116
local -r lock_file="/var/lock/subsys/reaper"
128117
local -r state_file="/var/lib/misc/reaper"
129-
local -r timeout="$(
130-
__get_reaper_timeout
131-
)"
132118

133119
local current_time
134120
local get
@@ -137,6 +123,7 @@ function main ()
137123
local session_start
138124
local session_end
139125
local state_value
126+
local timeout="0"
140127
local verbose="false"
141128
local wall_message
142129
local wall_timeout="30"
@@ -171,6 +158,14 @@ function main ()
171158
signal="${2}"
172159
shift 2 || break
173160
;;
161+
-t|--timeout)
162+
timeout="${2}"
163+
shift 2 || break
164+
;;
165+
--timeout=*)
166+
timeout="${1#*=}"
167+
shift 1
168+
;;
174169
-v|--verbose)
175170
verbose="true"
176171
shift 1
@@ -256,30 +251,37 @@ function main ()
256251
EXIT INT TERM
257252
__create_lock
258253

254+
if ! __is_valid_timeout "${timeout}"
255+
then
256+
>&2 printf -- \
257+
'ERROR: Invalid --timeout\n' \
258+
__usage
259+
fi
260+
259261
if ! __is_valid_wall_timeout "${wall_timeout}"
260262
then
261263
>&2 printf -- \
262264
'ERROR: Invalid --wall-timeout\n' \
263265
__usage
264266
fi
265267

266-
if (( timeout > 0 ))
268+
if [[ -z ${wall_message} ]] \
269+
|| (( timeout <= wall_timeout ))
267270
then
268-
trap __reap \
269-
EXIT INT TERM
271+
wall_timeout="0"
272+
fi
270273

271-
if [[ -z ${wall_message} ]] \
272-
|| (( timeout <= wall_timeout ))
273-
then
274-
wall_timeout="0"
275-
fi
274+
session_start="$(
275+
date -u +%s
276+
)"
276277

277-
session_start="$(
278-
date -u +%s
279-
)"
278+
trap __reap \
279+
EXIT INT TERM
280280

281-
__create_state
281+
__create_state
282282

283+
if (( timeout > 0 ))
284+
then
283285
if coproc read -t "$(( ${timeout} - ${wall_timeout} ))"
284286
then
285287
wait "${!}" || :
@@ -294,13 +296,13 @@ function main ()
294296
fi
295297
fi
296298
fi
299+
fi
297300

298-
if [[ ${verbose} == true ]]
299-
then
300-
printf -- \
301-
'INFO: %s expiring session.\n' \
302-
"${0##*/}"
303-
fi
301+
if [[ ${verbose} == true ]]
302+
then
303+
printf -- \
304+
'INFO: %s expiring session.\n' \
305+
"${0##*/}"
304306
fi
305307

306308
exit 0

0 commit comments

Comments
 (0)