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

Commit

Permalink
#695: Adds parameters for wall and wall timeout to reaper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeathe committed Jun 15, 2019
1 parent 86ff3c4 commit 5447f0c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
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
command = /usr/sbin/reaper --verbose --wall-timeout 30 --wall="Session expiring in 30 seconds."
priority = 1
startsecs = 0
stderr_logfile = /dev/stderr
Expand Down
50 changes: 41 additions & 9 deletions src/usr/sbin/reaper
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ function __is_valid_reaper_timeout ()
__is_valid_positive_integer "${@}"
}

function __is_valid_wall_timeout ()
{
__is_valid_positive_integer "${@}"
}

function __reap ()
{
kill \
Expand Down Expand Up @@ -109,6 +114,10 @@ function __usage ()
If not specified the default is SIGTERM.
-v, --verbose Output informational messages.
If not specified the default is quiet.
-w, --wall MESSAGE Set a wall message to send before session end.
-T, --wall-timeout SECONDS Set the time before session end to send the
wall message. The default is 30 seconds.
Set to 0 to disable sending a wall message.
EOF
exit 1
}
Expand All @@ -129,7 +138,8 @@ function main ()
local session_end
local state_value
local verbose="false"
local warning_timeout="30"
local wall_message
local wall_timeout="30"

while [[ "${#}" -gt 0 ]]
do
Expand Down Expand Up @@ -165,6 +175,22 @@ function main ()
verbose="true"
shift 1
;;
-w|--wall)
wall_message="${2}"
shift 2 || break
;;
--wall=*)
wall_message="${1#*=}"
shift 1
;;
--wall-timeout)
wall_timeout="${2}"
shift 2 || break
;;
--wall-timeout=*)
wall_timeout="${1#*=}"
shift 1
;;
*)
>&2 printf -- \
'ERROR: Unknown option %s\n' \
Expand Down Expand Up @@ -230,14 +256,22 @@ function main ()
EXIT INT TERM
__create_lock

if ! __is_valid_wall_timeout "${wall_timeout}"
then
>&2 printf -- \
'ERROR: Invalid --wall-timeout\n' \
__usage
fi

if (( timeout > 0 ))
then
trap __reap \
EXIT INT TERM

if (( timeout <= warning_timeout ))
if [[ -z ${wall_message} ]] \
|| (( timeout <= wall_timeout ))
then
warning_timeout="0"
wall_timeout="0"
fi

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

__create_state

if coproc read -t "$(( ${timeout} - ${warning_timeout} ))"
if coproc read -t "$(( ${timeout} - ${wall_timeout} ))"
then
wait "${!}" || :

if (( warning_timeout > 0 ))
if (( wall_timeout > 0 ))
then
wall "Session expires in ${warning_timeout} seconds." || :
wall "${wall_message}" || :

if coproc read -t "${warning_timeout}"
if coproc read -t "${wall_timeout}"
then
wait "${!}" || :
fi
else
wall "Session expired." || :
fi
fi

Expand Down

0 comments on commit 5447f0c

Please sign in to comment.