mirror of
https://github.com/hackacad/bastille.git
synced 2025-12-20 01:02:36 +01:00
restart: Pass only options that are allowed to stop
This commit is contained in:
@@ -15,6 +15,5 @@ Stop jail(s).
|
|||||||
Usage: bastille stop [option(s)] TARGET
|
Usage: bastille stop [option(s)] TARGET
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
-b | --boot Respect jail boot setting.
|
|
||||||
-v | --verbose Print every action on jail stop.
|
-v | --verbose Print every action on jail stop.
|
||||||
-x | --debug Enable debug mode.
|
-x | --debug Enable debug mode.
|
||||||
|
|||||||
@@ -48,35 +48,48 @@ EOF
|
|||||||
|
|
||||||
# Handle options.
|
# Handle options.
|
||||||
# We pass these to start and stop.
|
# We pass these to start and stop.
|
||||||
_options=""
|
_start_options=""
|
||||||
|
_stop_options=""
|
||||||
while [ "$#" -gt 0 ]; do
|
while [ "$#" -gt 0 ]; do
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
-h|--help|help)
|
-h|--help|help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
-b|--boot)
|
-b|--boot)
|
||||||
_options="${_options} -b"
|
_start_options="${_start_options} -b"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-d|--delay)
|
-d|--delay)
|
||||||
_options="${_options} -d ${2}"
|
_start_options="${_start_options} -d ${2}"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-v|--verbose)
|
-v|--verbose)
|
||||||
_options="${_options} -v"
|
_start_options="${_start_options} -v"
|
||||||
|
_stop_options="${_stop_options} -v"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-x|--debug)
|
-x|--debug)
|
||||||
_options="${_options} -x"
|
_start_options="${_start_options} -x"
|
||||||
|
_stop_options="${_stop_options} -x"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do
|
for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do
|
||||||
case ${_opt} in
|
case ${_opt} in
|
||||||
b) _options="${_options} -b" ;;
|
b)
|
||||||
v) _options="${_options} -v" ;;
|
_start_options="${_start_options} -b"
|
||||||
x) _options="${_options} -x" ;;
|
;;
|
||||||
*) error_exit "Unknown Option: \"${1}\"" ;;
|
v)
|
||||||
|
_start_options="${_start_options} -v"
|
||||||
|
_stop_options="${_stop_options} -v"
|
||||||
|
;;
|
||||||
|
x)
|
||||||
|
_start_options="${_start_options} -x"
|
||||||
|
_stop_options="${_stop_options} -x"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
error_exit "Unknown Option: \"${1}\""
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift
|
shift
|
||||||
@@ -100,8 +113,8 @@ for _jail in ${JAILS}; do
|
|||||||
|
|
||||||
# Only restart running jails
|
# Only restart running jails
|
||||||
if check_target_is_running "${_jail}"; then
|
if check_target_is_running "${_jail}"; then
|
||||||
bastille stop ${_options} ${_jail}
|
bastille stop ${_stop_options} ${_jail}
|
||||||
bastille start ${_options} ${_jail}
|
bastille start ${_start_options} ${_jail}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ usage() {
|
|||||||
cat << EOF
|
cat << EOF
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
-b | --boot Respect jail boot setting.
|
|
||||||
-v | --verbose Print every action on jail stop.
|
-v | --verbose Print every action on jail stop.
|
||||||
-x | --debug Enable debug mode.
|
-x | --debug Enable debug mode.
|
||||||
|
|
||||||
@@ -46,26 +45,12 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Handle options.
|
# Handle options.
|
||||||
BOOT=0
|
|
||||||
DELAY_TIME=0
|
|
||||||
OPTION=""
|
OPTION=""
|
||||||
while [ "$#" -gt 0 ]; do
|
while [ "$#" -gt 0 ]; do
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
-h|--help|help)
|
-h|--help|help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
-b|--boot)
|
|
||||||
BOOT=1
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-d|--delay)
|
|
||||||
if [ -z "${2}" ] && ! echo "${2}" | grep -Eq '^[0-9]+$'; then
|
|
||||||
error_exit "[-d|--delay] requires a value."
|
|
||||||
else
|
|
||||||
DELAY_TIME="${2}"
|
|
||||||
fi
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-v|--verbose)
|
-v|--verbose)
|
||||||
OPTION="-v"
|
OPTION="-v"
|
||||||
shift
|
shift
|
||||||
@@ -77,7 +62,6 @@ while [ "$#" -gt 0 ]; do
|
|||||||
-*)
|
-*)
|
||||||
for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do
|
for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do
|
||||||
case ${_opt} in
|
case ${_opt} in
|
||||||
b) BOOT="1" ;;
|
|
||||||
v) OPTION="-v" ;;
|
v) OPTION="-v" ;;
|
||||||
x) enable_debug ;;
|
x) enable_debug ;;
|
||||||
*) error_exit "Unknown Option: \"${1}\"" ;;
|
*) error_exit "Unknown Option: \"${1}\"" ;;
|
||||||
@@ -102,14 +86,6 @@ set_target "${TARGET}" "reverse"
|
|||||||
|
|
||||||
for _jail in ${JAILS}; do
|
for _jail in ${JAILS}; do
|
||||||
|
|
||||||
# Continue if '-b|--boot' is set and 'boot=off'
|
|
||||||
if [ "${BOOT}" -eq 1 ]; then
|
|
||||||
BOOT_ENABLED="$(sysrc -f ${bastille_jailsdir}/${_jail}/boot.conf -n boot)"
|
|
||||||
if [ "${BOOT_ENABLED}" = "off" ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
info "[${_jail}]:"
|
info "[${_jail}]:"
|
||||||
check_target_is_running "${_jail}" || error_continue "Jail is already stopped."
|
check_target_is_running "${_jail}" || error_continue "Jail is already stopped."
|
||||||
|
|
||||||
@@ -156,7 +132,4 @@ for _jail in ${JAILS}; do
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Delay between jail action
|
|
||||||
sleep "${DELAY_TIME}"
|
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user