evobackup/lib/bkctld-is-on

32 lines
771 B
Bash
Executable file

#!/bin/sh
#
# Check if a jail is on or not
# Usage: is-on <jailname>
#
# shellcheck source=./includes
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
jail_name="${1:?}"
if [ -z "${jail_name}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail is missing."
jail_pid_file="${jail_path}/${SSHD_PID}"
return=1
if [ -f "${jail_pid_file}" ]; then
pid=$(cat "${jail_pid_file}")
ps -p "${pid}" > /dev/null && return=0
fi
if [ "${return}" -eq 1 ]; then
rm -f "${jail_pid_file}"
grep -q "${jail_path}/proc" /proc/mounts && umount --lazy "${jail_path}/proc/"
grep -q "${jail_path}/dev" /proc/mounts && umount --lazy --recursive "${jail_path}/dev"
fi
exit "${return}"