Skip to content

Commit

Permalink
Add check for when the jail is gone in healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
DtxdF committed Jun 1, 2023
1 parent 2e6d2b6 commit 87dc020
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion share/appjail/cmd/healthcheck
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ _healthcheck_run()
sleep "${start_period}" || exit $?
fi

_healthcheck_jail_exists "${jail}"

local retries=`healthcheck_get -In "${nro}" "${jail}" retries`
local interval=`healthcheck_get -In "${nro}" "${jail}" interval`

Expand Down Expand Up @@ -469,6 +471,8 @@ _healthcheck_run()
lib_debug "Sleeping (nro = ${nro}, context = health, type = ${health_type}, cmd = ${health_cmd}, interval = ${interval}) ..."
sleep "${interval}" || exit $?

_healthcheck_jail_exists "${jail}"

lib_debug "Executing (nro = ${nro}, context = health, type = ${health_type}, cmd = ${health_cmd}) ..."

if [ "${health_type}" = "${HEALTHCHECK_HEALTH_HOST_TYPE}" ]; then
Expand Down Expand Up @@ -525,18 +529,36 @@ _healthcheck_run()
done
}

_healthcheck_jail_exists()
{
local jail="$1"

if [ -z "${jail}" ]; then
lib_err ${EX_USAGE} "usage: _healthcheck_jail_exists jail"
fi

if [ ! -d "${JAILDIR}/${jail_name}" ]; then
lib_warn -- "${jail_name}: the jail is gone. Closing..."
exit 0
fi
}

_healthcheck_set_status()
{
local jail="$1" nro="$2" status="$3"
if [ -z "${jail}" -o -z "${nro}" -o -z "${status}" ]; then
lib_err ${EX_USAGE} "_healthcheck_set_status jail nro status"
fi

_healthcheck_jail_exists "${jail}"

local jail_path="${JAILDIR}/${jail}"
local basedir="${jail_path}/conf/boot/health"
local nrodir="${basedir}/${nro}"

echo "${status}" > "${nrodir}/status"
if ! echo "${status}" > "${nrodir}/status"; then
lib_err ${EX_IOERR} "Error writing ${status} to ${nrodir}/status"
fi
}

healthcheck_set()
Expand Down

0 comments on commit 87dc020

Please sign in to comment.