error() function accepts an optional return code

This commit is contained in:
Jérémy Lecour 2020-05-01 09:51:09 +02:00 committed by Jérémy Lecour
parent 807dd44408
commit 64ec60428d
12 changed files with 17 additions and 13 deletions

View File

@ -15,7 +15,7 @@ if [ ! -n "${jail_name}" ]; then
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
jail_sshd_config="${jail_path}/${SSHD_CONFIG}"

View File

@ -14,7 +14,7 @@ if [ -z "${jail_name}" ]; then
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
jail_pid_file="${jail_path}/${SSHD_PID}"

View File

@ -15,7 +15,7 @@ if [ ! -n "${jail_name}" ]; then
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
if [ -z "${keyfile}" ]; then
if [ -f "${jail_path}/${AUTHORIZED_KEYS}" ]; then

View File

@ -15,7 +15,7 @@ if [ ! -n "${jail_name}" ]; then
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
jail_sshd_config="${jail_path}/${SSHD_CONFIG}"

View File

@ -13,7 +13,7 @@ if [ -z "${jail_name}" ]; then
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
"${LIBDIR}/bkctld-is-on" "${jail_name}" || exit 0

View File

@ -14,7 +14,7 @@ fi
jail_path=$(jail_path "${jail_name}")
incs_path=$(incs_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
"${LIBDIR}/bkctld-is-on" "${jail_name}" && "${LIBDIR}/bkctld-stop" "${jail_name}"

View File

@ -15,7 +15,7 @@ if [ -z "${jail_name}" ]; then
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
"${LIBDIR}/bkctld-is-on" "${jail_name}" && "${LIBDIR}/bkctld-stop" "${jail_name}"
"${LIBDIR}/bkctld-start" "${jail_name}"

View File

@ -13,7 +13,7 @@ if [ -z "${jail_name}" ]; then
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
"${LIBDIR}/bkctld-is-on" "${jail_name}" && exit 0

View File

@ -13,7 +13,7 @@ if [ -z "${jail_name}" ]; then
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
"${LIBDIR}/bkctld-is-on" "${jail_name}" || exit 0

View File

@ -14,7 +14,7 @@ fi
jail_path=$(jail_path "${jail_name}")
jail_config_dir=$(jail_config_dir "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
[ -n "${NODE}" ] || error "Sync need config of \$NODE in /etc/default/bkctld !"

View File

@ -13,7 +13,7 @@ if [ ! -n "${jail_name}" ]; then
fi
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail not found"
test -d "${jail_path}" || error "${jail_name}: jail not found" 2
"${LIBDIR}/bkctld-is-on" "${jail_name}" && "${LIBDIR}/bkctld-stop" "${jail_name}"

View File

@ -59,15 +59,19 @@ warning() {
logger -t bkctld -p daemon.warning "$(process_name) ${msg}"
fi
}
# Return codes
# 1 : generic error
# 2 : jail not found
# > 100 : subcommands specific errors
error() {
msg="${1:-$(cat /dev/stdin)}"
rc="${2:-1}"
tty -s && echo "$(log_date) ERROR $(process_name) ${msg}" >&2
if [ "${LOGLEVEL}" -ge 5 ]; then
tty -s || echo "$(log_date) ERROR $(process_name) ${msg}" >&2
logger -t bkctld -p daemon.error "$(process_name) ${msg}"
fi
exit 1
exit ${rc}
}
dry_run() {