evobackup/lib/bkctld-start

44 lines
988 B
Plaintext
Raw Normal View History

2019-01-04 13:51:05 +01:00
#!/bin/sh
#
# Start jail <jailname> or all
# Usage: start <jailname>|all
#
2019-01-04 13:51:05 +01:00
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-04 13:51:05 +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
"${LIBDIR}/bkctld-help" && exit 1
fi
2020-04-02 01:07:12 +02:00
jail_path=$(jail_path "${jail_name}")
2019-01-04 13:51:05 +01:00
2020-04-02 01:07:12 +02:00
test -d "${jail_path}" || error "${jail_name}: jail is missing."
"${LIBDIR}/bkctld-is-on" "${jail_name}" && exit 0
2020-04-02 23:33:54 +02:00
# Prepare the chroot
mount_jail_fs "${jail_name}"
2020-04-02 23:33:54 +02:00
# Start SSH in the chroot
chroot "${jail_path}" /usr/sbin/sshd -E /var/log/authlog || error "${jail_name}: failed to start SSH."
2020-04-02 01:07:12 +02:00
pidfile="${jail_path}/${SSHD_PID}"
2020-04-02 23:33:54 +02:00
# Wait for SSH to be up
# shellcheck disable=SC2034
2020-04-02 01:07:12 +02:00
for try in $(seq 1 10); do
if [ -f "${pidfile}" ]; then
pid=$(cat "${pidfile}")
break
else
pid=""
sleep 0.3
fi
2019-01-04 13:51:05 +01:00
done
2020-04-02 01:07:12 +02:00
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