2006-10-14 14:35:46 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# chkconfig: 345 92 08
|
2013-06-03 11:29:36 +00:00
|
|
|
# processname: fail2ban-server
|
|
|
|
# config: /etc/fail2ban/fail2ban.conf
|
|
|
|
# pidfile: /var/run/fail2ban/fail2ban.pid
|
|
|
|
# description: fail2ban is a daemon to ban hosts that cause multiple authentication errors
|
2006-10-14 14:35:46 +00:00
|
|
|
#
|
2013-06-03 11:29:36 +00:00
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: fail2ban
|
2013-06-03 16:34:47 +00:00
|
|
|
# Required-Start: $local_fs $remote_fs
|
|
|
|
# Required-Stop: $local_fs $remote_fs
|
|
|
|
# Should-Start: $time $network $syslog iptables firehol shorewall ferm
|
|
|
|
# Should-Stop: $network $syslog iptables firehol shorewall ferm
|
2013-06-03 11:29:36 +00:00
|
|
|
# Default-Start: 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
2013-06-03 16:34:47 +00:00
|
|
|
# Short-Description: Start/Stop fail2ban
|
|
|
|
# Description: Start/Stop fail2ban, a daemon to ban hosts that cause multiple authentication errors
|
2013-06-03 11:29:36 +00:00
|
|
|
### END INIT INFO
|
2006-10-14 14:35:46 +00:00
|
|
|
|
|
|
|
# Source function library.
|
2013-06-03 11:29:36 +00:00
|
|
|
. /etc/rc.d/init.d/functions
|
2006-10-14 14:35:46 +00:00
|
|
|
|
|
|
|
# Check that the config file exists
|
|
|
|
[ -f /etc/fail2ban/fail2ban.conf ] || exit 0
|
|
|
|
|
|
|
|
FAIL2BAN="/usr/bin/fail2ban-client"
|
2013-06-03 11:29:36 +00:00
|
|
|
prog=fail2ban-server
|
|
|
|
lockfile=${LOCKFILE-/var/lock/subsys/fail2ban}
|
|
|
|
socket=${SOCKET-/var/run/fail2ban/fail2ban.sock}
|
|
|
|
pidfile=${PIDFILE-/var/run/fail2ban/fail2ban.pid}
|
2006-10-14 14:35:46 +00:00
|
|
|
RETVAL=0
|
|
|
|
|
|
|
|
start() {
|
|
|
|
echo -n $"Starting fail2ban: "
|
2013-06-03 16:34:47 +00:00
|
|
|
${FAIL2BAN} -x start > /dev/null
|
2013-06-03 11:29:36 +00:00
|
|
|
RETVAL=$?
|
|
|
|
if [ $RETVAL = 0 ]; then
|
|
|
|
touch ${lockfile}
|
2006-10-14 14:35:46 +00:00
|
|
|
echo_success
|
|
|
|
else
|
|
|
|
echo_failure
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
echo -n $"Stopping fail2ban: "
|
2013-06-03 11:29:36 +00:00
|
|
|
${FAIL2BAN} stop > /dev/null
|
2006-10-14 14:35:46 +00:00
|
|
|
RETVAL=$?
|
2013-06-03 11:29:36 +00:00
|
|
|
if [ $RETVAL = 0 ]; then
|
|
|
|
rm -f ${lockfile} ${pidfile}
|
2006-10-14 14:35:46 +00:00
|
|
|
echo_success
|
|
|
|
else
|
|
|
|
echo_failure
|
|
|
|
fi
|
2013-06-03 11:29:36 +00:00
|
|
|
echo
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
reload() {
|
|
|
|
echo "Reloading fail2ban: "
|
|
|
|
${FAIL2BAN} reload
|
|
|
|
RETVAL=$?
|
2006-10-14 14:35:46 +00:00
|
|
|
echo
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
# See how we were called.
|
|
|
|
case "$1" in
|
2013-06-03 11:29:36 +00:00
|
|
|
start)
|
|
|
|
status -p ${pidfile} ${prog} >/dev/null 2>&1 && exit 0
|
2006-10-14 14:35:46 +00:00
|
|
|
start
|
|
|
|
;;
|
2013-06-03 11:29:36 +00:00
|
|
|
stop)
|
2006-10-14 14:35:46 +00:00
|
|
|
stop
|
|
|
|
;;
|
2013-06-03 11:29:36 +00:00
|
|
|
reload)
|
|
|
|
reload
|
2006-10-14 14:35:46 +00:00
|
|
|
;;
|
2013-06-03 11:29:36 +00:00
|
|
|
restart)
|
2007-05-01 22:42:10 +00:00
|
|
|
stop
|
2006-10-14 14:35:46 +00:00
|
|
|
start
|
|
|
|
;;
|
2013-06-03 11:29:36 +00:00
|
|
|
status)
|
|
|
|
status -p ${pidfile} ${prog}
|
|
|
|
RETVAL=$?
|
|
|
|
[ $RETVAL = 0 ] && ${FAIL2BAN} status
|
2006-10-14 14:35:46 +00:00
|
|
|
;;
|
2013-06-03 11:29:36 +00:00
|
|
|
*)
|
|
|
|
echo $"Usage: fail2ban {start|stop|restart|reload|status}"
|
|
|
|
RETVAL=2
|
2006-10-14 14:35:46 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|