bastille: clean up rc script

This commit is contained in:
tschettervictor
2025-03-18 16:23:57 -06:00
parent 963c13a047
commit 8d6f7c9e28
4 changed files with 40 additions and 37 deletions

View File

@@ -33,38 +33,12 @@ restart_cmd="bastille_stop && bastille_start"
bastille_start()
{
local _jailsdir=$(. $bastille_conf; echo $bastille_jailsdir)
# Sort jails by priority value
local _priority_list=$(${command} list priority | sort -k2 -n | awk '{print $1}')
for _jail in ${_priority_list}; do
local _boot_file=${_jailsdir}/${_jail}/boot.conf
# Set defaults if boot file does not exist
if [ ! -f ${_boot_file} ]; then
sysrc -f ${_boot_file} boot=on
sysrc -f ${_boot_file} priority=99
fi
local _boot="$(sysrc -f ${_boot_file} -n boot)"
if [ "${_boot}" = "on" ]; then
echo "Starting Bastille Container: ${_jail}"
${command} start ${_jail}
sleep ${bastille_startup_delay}
else
continue
fi
done
${command} start --boot --delay ${bastille_startup_delay} ALL
}
bastille_stop()
{
local _jailsdir=$(. $bastille_conf; echo $bastille_jailsdir)
# Sort jails by priority value, in reverse order
local _priority_list=$(${command} list priority | sort -k2 -nr | awk '{print $1}')
for _jail in ${_priority_list_rev}; do
echo "Stopping Bastille Container: ${_jail}"
${command} stop ${_jail}
done
${command} stop ALL
}
load_rc_config ${name}

View File

@@ -35,9 +35,10 @@ usage() {
cat << EOF
Options:
-b | --boot Respect jail boot setting.
-v | --verbose Print every action on jail start.
-x | --debug Enable debug mode.
-b | --boot Respect jail boot setting.
-d | --delay VALUE Time to wait between starting/stopping each jail.
-v | --verbose Print every action on jail start.
-x | --debug Enable debug mode.
EOF
exit 1

View File

@@ -38,9 +38,10 @@ usage() {
cat << EOF
Options:
-b | --boot Respect jail boot setting.
-v | --verbose Print every action on jail start.
-x | --debug Enable debug mode.
-b | --boot Respect jail boot setting.
-d | --delay VALUE Time to wait between starting each jail.
-v | --verbose Print every action on jail start.
-x | --debug Enable debug mode.
EOF
exit 1
@@ -48,6 +49,7 @@ EOF
# Handle options.
BOOT=0
DELAY_TIME=0
OPTION=""
while [ "$#" -gt 0 ]; do
case "${1}" in
@@ -58,6 +60,14 @@ while [ "$#" -gt 0 ]; do
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)
OPTION="-v"
shift
@@ -173,4 +183,8 @@ for _jail in ${JAILS}; do
bastille rdr ${_jail} ${_rules}
done < "${bastille_jailsdir}/${_jail}/rdr.conf"
fi
# Delay between jail action
sleep "${DELAY_TIME}"
done

View File

@@ -38,9 +38,10 @@ usage() {
cat << EOF
Options:
-b | --boot Respect jail boot setting.
-v | --verbose Print every action on jail stop.
-x | --debug Enable debug mode.
-b | --boot Respect jail boot setting.
-d | --delay VALUE Time to wait between stopping each jail.
-v | --verbose Print every action on jail stop.
-x | --debug Enable debug mode.
EOF
exit 1
@@ -48,6 +49,7 @@ EOF
# Handle options.
BOOT=0
DELAY_TIME=0
OPTION=""
while [ "$#" -gt 0 ]; do
case "${1}" in
@@ -58,6 +60,14 @@ while [ "$#" -gt 0 ]; do
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)
OPTION="-v"
shift
@@ -149,4 +159,8 @@ for _jail in ${JAILS}; do
pfctl -q -t "${bastille_network_pf_table}" -T delete "${_ip}"
done
fi
# Delay between jail action
sleep "${DELAY_TIME}"
done