2019-01-07 16:34:14 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2020-10-11 14:51:39 +02:00
|
|
|
# Description: Check if a SSH server is on (exit 0) or not (exit 100)
|
2019-01-07 16:34:14 +01:00
|
|
|
# Usage: is-on <jailname>
|
|
|
|
#
|
|
|
|
|
2020-04-02 13:44:13 +02:00
|
|
|
# shellcheck source=./includes
|
2020-04-02 00:31:57 +02:00
|
|
|
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
|
2019-01-07 16:34:14 +01:00
|
|
|
|
2020-04-02 13:44:13 +02:00
|
|
|
jail_name="${1:?}"
|
2020-04-02 01:07:12 +02:00
|
|
|
|
|
|
|
if [ -z "${jail_name}" ]; then
|
2020-10-07 20:50:17 +02:00
|
|
|
show_help && exit 1
|
2019-01-07 16:34:14 +01:00
|
|
|
fi
|
2020-04-02 01:07:12 +02:00
|
|
|
jail_path=$(jail_path "${jail_name}")
|
|
|
|
|
2020-05-01 09:51:09 +02:00
|
|
|
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
|
2020-04-02 01:07:12 +02:00
|
|
|
|
|
|
|
jail_pid_file="${jail_path}/${SSHD_PID}"
|
2019-01-07 16:34:14 +01:00
|
|
|
|
2020-05-01 09:51:36 +02:00
|
|
|
# Error codes are references in "includes" file
|
|
|
|
return=100
|
2020-04-02 01:07:12 +02:00
|
|
|
if [ -f "${jail_pid_file}" ]; then
|
|
|
|
pid=$(cat "${jail_pid_file}")
|
2019-01-07 16:34:14 +01:00
|
|
|
ps -p "${pid}" > /dev/null && return=0
|
|
|
|
fi
|
2020-05-01 09:51:36 +02:00
|
|
|
if [ "${return}" -gt 0 ]; then
|
2020-04-02 01:07:12 +02:00
|
|
|
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"
|
2019-01-07 16:34:14 +01:00
|
|
|
fi
|
|
|
|
exit "${return}"
|