#!/bin/sh
#
# PROVIDE: fail2ban
# REQUIRE: DAEMON
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable fail2ban:
# fail2ban_enable="YES"
# fail2ban_flags="<set as needed>"
# fail2ban_pidfile="<same as in fail2ban.local>"

# Make sure pidfile and socket point to the same directory

. /etc/rc.subr

PATH=${PATH}:%%PREFIX%%/sbin:%%PREFIX%%/bin

name="fail2ban"
rcvar=fail2ban_enable

start_precmd="fail2ban_prestart"
command="%%PREFIX%%/bin/fail2ban-server"
command_interpreter="%%PYTHON_CMD%%"
client="%%PREFIX%%/bin/fail2ban-client"

extra_commands="reload jailstatus"

fail2ban_prestart()
{
   install -d -m 0755 "$(dirname ${pidfile})"
}

load_rc_config ${name}

#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
# SET THEM IN THE /etc/rc.conf FILE
#

fail2ban_enable=${fail2ban_enable-"NO"}
pidfile=${fail2ban_pidfile-"/var/run/fail2ban/fail2ban.pid"}

start_cmd="${client} ${fail2ban_flags} start"
stop_cmd="${client} ${fail2ban_flags} stop"
reload_cmd="${client} ${fail2ban_flags} reload"
jailstatus_cmd="${client} ${fail2ban_flags} status"

run_rc_command "$1"
