#!/bin/sh

# Bastille jail startup script
#
# PROVIDE: bastille
# REQUIRE: jail
# KEYWORD: shutdown

# Add the following to /etc/rc.conf[.local] to enable this service
#
# bastille_enable (bool):          Set to "NO" by default.
#                                  Set to "YES" to enable bastille.
# bastille_conf (bool):            Set to "/usr/local/etc/bastille/bastille.conf" by default.
#                                  Path to bastile.conf file.
# bastille_startup_delay (bool):   Set to "0" by default.
#                                  Set to a numerical value.
#                                  This is the delay between startup of each jail.
# bastille_parallel_limit (bool):  Set to "1" by default.
#                                  Set to a numerical value.
#                                  Number of processes to run in parallel when starting/stopping/restarting jails.
#

. /etc/rc.subr

name=bastille
rcvar=${name}_enable

: ${bastille_enable:="NO"}
: ${bastille_conf:="/usr/local/etc/bastille/bastille.conf"}
: ${bastille_startup_delay:=0}
: ${bastille_parallel_limit:=1}

command=/usr/local/bin/${name}
start_cmd="bastille_start"
stop_cmd="bastille_stop"
restart_cmd="bastille_restart"

bastille_start()
{
    ${command} -p ${bastille_parallel_limit} start --boot --delay ${bastille_startup_delay} ALL
}

bastille_stop()
{
    ${command} -p ${bastille_parallel_limit} stop ALL
}

bastille_restart()
{
    ${command} -p ${bastille_parallel_limit} restart --boot --delay ${bastille_startup_delay} ALL
}

load_rc_config ${name}
run_rc_command "$1"
