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

Commit 5447f0c

Browse files
committed
#695: Adds parameters for wall and wall timeout to reaper.
1 parent 86ff3c4 commit 5447f0c

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

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
4+
command = /usr/sbin/reaper --verbose --wall-timeout 30 --wall="Session expiring in 30 seconds."
55
priority = 1
66
startsecs = 0
77
stderr_logfile = /dev/stderr

Diff for: src/usr/sbin/reaper

+41-9
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ function __is_valid_reaper_timeout ()
8080
__is_valid_positive_integer "${@}"
8181
}
8282

83+
function __is_valid_wall_timeout ()
84+
{
85+
__is_valid_positive_integer "${@}"
86+
}
87+
8388
function __reap ()
8489
{
8590
kill \
@@ -109,6 +114,10 @@ function __usage ()
109114
If not specified the default is SIGTERM.
110115
-v, --verbose Output informational messages.
111116
If not specified the default is quiet.
117+
-w, --wall MESSAGE Set a wall message to send before session end.
118+
-T, --wall-timeout SECONDS Set the time before session end to send the
119+
wall message. The default is 30 seconds.
120+
Set to 0 to disable sending a wall message.
112121
EOF
113122
exit 1
114123
}
@@ -129,7 +138,8 @@ function main ()
129138
local session_end
130139
local state_value
131140
local verbose="false"
132-
local warning_timeout="30"
141+
local wall_message
142+
local wall_timeout="30"
133143

134144
while [[ "${#}" -gt 0 ]]
135145
do
@@ -165,6 +175,22 @@ function main ()
165175
verbose="true"
166176
shift 1
167177
;;
178+
-w|--wall)
179+
wall_message="${2}"
180+
shift 2 || break
181+
;;
182+
--wall=*)
183+
wall_message="${1#*=}"
184+
shift 1
185+
;;
186+
--wall-timeout)
187+
wall_timeout="${2}"
188+
shift 2 || break
189+
;;
190+
--wall-timeout=*)
191+
wall_timeout="${1#*=}"
192+
shift 1
193+
;;
168194
*)
169195
>&2 printf -- \
170196
'ERROR: Unknown option %s\n' \
@@ -230,14 +256,22 @@ function main ()
230256
EXIT INT TERM
231257
__create_lock
232258

259+
if ! __is_valid_wall_timeout "${wall_timeout}"
260+
then
261+
>&2 printf -- \
262+
'ERROR: Invalid --wall-timeout\n' \
263+
__usage
264+
fi
265+
233266
if (( timeout > 0 ))
234267
then
235268
trap __reap \
236269
EXIT INT TERM
237270

238-
if (( timeout <= warning_timeout ))
271+
if [[ -z ${wall_message} ]] \
272+
|| (( timeout <= wall_timeout ))
239273
then
240-
warning_timeout="0"
274+
wall_timeout="0"
241275
fi
242276

243277
session_start="$(
@@ -246,20 +280,18 @@ function main ()
246280

247281
__create_state
248282

249-
if coproc read -t "$(( ${timeout} - ${warning_timeout} ))"
283+
if coproc read -t "$(( ${timeout} - ${wall_timeout} ))"
250284
then
251285
wait "${!}" || :
252286

253-
if (( warning_timeout > 0 ))
287+
if (( wall_timeout > 0 ))
254288
then
255-
wall "Session expires in ${warning_timeout} seconds." || :
289+
wall "${wall_message}" || :
256290

257-
if coproc read -t "${warning_timeout}"
291+
if coproc read -t "${wall_timeout}"
258292
then
259293
wait "${!}" || :
260294
fi
261-
else
262-
wall "Session expired." || :
263295
fi
264296
fi
265297

0 commit comments

Comments
 (0)