evobackup/server/lib/bkctld-is-on

33 lines
846 B
Plaintext
Raw Normal View History

#!/bin/sh
#
# Description: Check if a SSH server is on (exit 0) or not (exit 100)
# 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"
2020-04-02 13:44:13 +02:00
jail_name="${1:?}"
2020-04-02 01:07:12 +02:00
if [ -z "${jail_name}" ]; then
show_help && exit 1
fi
2020-04-02 01:07:12 +02:00
jail_path=$(jail_path "${jail_name}")
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}"
# 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}")
ps -p "${pid}" > /dev/null && return=0
fi
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"
fi
exit "${return}"