evobackup/lib/bkctld-start

44 lines
988 B
Bash
Executable file

#!/bin/sh
#
# Start jail <jailname> or all
# Usage: start <jailname>|all
#
# 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."
"${LIBDIR}/bkctld-is-on" "${jail_name}" && exit 0
# Prepare the chroot
mount_jail_fs "${jail_name}"
# Start SSH in the chroot
chroot "${jail_path}" /usr/sbin/sshd -E /var/log/authlog || error "${jail_name}: failed to start SSH."
pidfile="${jail_path}/${SSHD_PID}"
# Wait for SSH to be up
# shellcheck disable=SC2034
for try in $(seq 1 10); do
if [ -f "${pidfile}" ]; then
pid=$(cat "${pidfile}")
break
else
pid=""
sleep 0.3
fi
done
if [ -n "${pid}" ]; then
notice "${jail_name}: jail has been started [${pid}]"
else
error "${jail_name}: failed to fetch SSH pid within 3 sec."
fi