evobackup/server/lib/bkctld-is-on

33 lines
846 B
Bash
Executable file

#!/bin/sh
#
# Description: Check if a SSH server is on (exit 0) or not (exit 100)
# Usage: is-on <jailname>
#
# shellcheck source=./includes
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
jail_name="${1:?}"
if [ -z "${jail_name}" ]; then
show_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}"