#!/bin/sh
#
# PROVIDE: fail2ban
# REQUIRE: NETWORKING syslogd
#
# Add the following lines to /etc/rc.conf to enable fail2ban:
# fail2ban=YES
# fail2ban_flags="<set as needed>"

. /etc/rc.subr

name="fail2ban"
rcvar=${name}
command="/usr/pkg/bin/fail2ban-server"
command_interpreter="/usr/pkg/bin/python3.12"
client="/usr/pkg/bin/fail2ban-client"
pidfile="/var/${name}/${name}.pid"
extra_commands="reload"

load_rc_config ${name}

start_precmd="fail2ban_precmd"
start_cmd="${client} ${fail2ban_flags} start"
stop_cmd="${client} ${fail2ban_flags} stop"
status_cmd="${client} ${fail2ban_flags} status"
reload_cmd="${client} ${fail2ban_flags} reload"

fail2ban_precmd () {
    mkdir -p /var/run/fail2ban
}

run_rc_command "$1"
