evobackup/server/lib/bkctld-start

44 lines
995 B
Bash
Executable file

#!/bin/sh
#
# Description: Start SSH Server
# Usage: start <jailname>|all
#
# 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
"${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 "Failed to start SSH for jail \`${jail_name}'"
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 "Start jail \`${jail_name}' : OK [${pid}]"
else
error "Failed to fetch SSH PID for jail \`${jail_name}' within 3 seconds"
fi