diff --git a/usr/local/etc/rc.d/bastille b/usr/local/etc/rc.d/bastille index 88638ff4..b8dd04eb 100755 --- a/usr/local/etc/rc.d/bastille +++ b/usr/local/etc/rc.d/bastille @@ -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} diff --git a/usr/local/share/bastille/restart.sh b/usr/local/share/bastille/restart.sh index 8a4ff32e..ebc70dd7 100644 --- a/usr/local/share/bastille/restart.sh +++ b/usr/local/share/bastille/restart.sh @@ -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 diff --git a/usr/local/share/bastille/start.sh b/usr/local/share/bastille/start.sh index 4e4f3e44..2067875a 100644 --- a/usr/local/share/bastille/start.sh +++ b/usr/local/share/bastille/start.sh @@ -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 diff --git a/usr/local/share/bastille/stop.sh b/usr/local/share/bastille/stop.sh index 29e1bcfa..5fa411cf 100644 --- a/usr/local/share/bastille/stop.sh +++ b/usr/local/share/bastille/stop.sh @@ -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