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

Commit

Permalink
#695: Adds lock file feature to reaper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeathe committed Jun 14, 2019
1 parent 1358399 commit b8de2bf
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/usr/sbin/reaper
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

set -e

function __cleanup ()
{
__delete_lock
}

function __create_lock ()
{
if [[ -n ${lock_file} ]]
then
touch "${lock_file}"
fi
}

function __create_state ()
{
if [[ -n ${state_file} ]]
Expand All @@ -14,6 +27,14 @@ function __create_state ()
fi
}

function __delete_lock ()
{
if [[ -e ${lock_file} ]]
then
rm -f "${lock_file}"
fi
}

function __get_reaper_timeout ()
{
local -r default_value="${1:-3600}"
Expand Down Expand Up @@ -51,10 +72,13 @@ function __reap ()
kill \
-s "${signal:-TERM}" \
"${pid:-1}"

__cleanup
}

function main ()
{
local -r lock_file="/var/lock/subsys/reaper"
local -r state_file="/var/lib/misc/reaper"
local -r timeout="$(
__get_reaper_timeout
Expand Down Expand Up @@ -93,6 +117,18 @@ function main ()
esac
done

if [[ -e ${lock_file} ]]
then
>&2 printf -- \
'ERROR: %s lock detected - aborting\n' \
"${0##*/}"
exit 1
fi

trap __cleanup \
EXIT INT TERM
__create_lock

if (( timeout > 0 ))
then
trap __reap \
Expand Down

0 comments on commit b8de2bf

Please sign in to comment.