evobackup/server/lib/bkctld-start

44 lines
995 B
Plaintext
Raw Normal View History

2019-01-04 13:51:05 +01:00
#!/bin/sh
#
# Description: Start SSH Server
# 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
show_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
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
2020-04-02 01:07:12 +02:00
"${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
2020-04-20 08:29:21 +02:00
chroot "${jail_path}" /usr/sbin/sshd -E /var/log/authlog || error "Failed to start SSH for jail \`${jail_name}'"
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
2020-04-20 23:30:57 +02:00
notice "Start jail \`${jail_name}' : OK [${pid}]"
else
2020-04-20 08:29:21 +02:00
error "Failed to fetch SSH PID for jail \`${jail_name}' within 3 seconds"
fi