33 lines
821 B
Bash
Executable file
33 lines
821 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 not found" 2
|
|
|
|
jail_pid_file="${jail_path}/${SSHD_PID}"
|
|
|
|
# Error codes are references in "includes" file
|
|
return=100
|
|
if [ -f "${jail_pid_file}" ]; then
|
|
pid=$(cat "${jail_pid_file}")
|
|
ps -p "${pid}" > /dev/null && return=0
|
|
fi
|
|
if [ "${return}" -gt 0 ]; 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}"
|