2007-02-20 20:44:47 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# /etc/init.d/fail2ban
|
|
|
|
# and its symbolic link
|
|
|
|
# /usr/sbin/rcfail2ban
|
|
|
|
#
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: fail2ban
|
2007-07-10 20:04:57 +00:00
|
|
|
# Required-Start: $syslog $remote_fs sendmail
|
2007-02-20 20:44:47 +00:00
|
|
|
# Required-Stop: $syslog $remote_fs
|
|
|
|
# Should-Stop: $time ypbind sendmail
|
|
|
|
# Default-Start: 3 5
|
|
|
|
# Default-Stop: 0 1 2 6
|
|
|
|
# Description: startup Fail2Ban
|
|
|
|
### END INIT INFO
|
2007-07-10 20:04:57 +00:00
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/usr/sbin:/usr/bin:/bin
|
2007-02-20 20:44:47 +00:00
|
|
|
FAIL2BAN_BIN=/usr/local/bin/fail2ban-client
|
|
|
|
FAIL2BAN_SERVER=/usr/local/bin/fail2ban-server
|
2008-07-21 14:13:13 +00:00
|
|
|
FAIL2BAN_SOCKET=/var/run/fail2ban/fail2ban.sock
|
2007-07-10 20:04:57 +00:00
|
|
|
test -x $FAIL2BAN_BIN || { echo "$FAIL2BAN_BIN not installed";
|
|
|
|
if [ "$1" = "stop" ]; then exit 0;
|
|
|
|
else exit 5; fi; }
|
2007-02-20 20:44:47 +00:00
|
|
|
|
|
|
|
# Check for existence of needed config file and read it
|
|
|
|
FAIL2BAN_CONFIG=/etc/fail2ban/fail2ban.conf
|
|
|
|
test -r $FAIL2BAN_CONFIG || { echo "$FAIL2BAN_CONFIG not existing";
|
2007-07-10 20:04:57 +00:00
|
|
|
if [ "$1" = "stop" ]; then exit 0;
|
|
|
|
else exit 6; fi; }
|
2007-02-20 20:44:47 +00:00
|
|
|
|
|
|
|
. /etc/rc.status
|
|
|
|
|
|
|
|
# Reset status of this service
|
|
|
|
rc_reset
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2007-07-10 20:04:57 +00:00
|
|
|
echo -n "Starting Fail2Ban "
|
|
|
|
/sbin/startproc $FAIL2BAN_BIN start &>/dev/null
|
|
|
|
rc_status -v
|
|
|
|
;;
|
2007-02-20 20:44:47 +00:00
|
|
|
stop)
|
2007-07-10 20:04:57 +00:00
|
|
|
echo -n "Shutting down Fail2ban "
|
|
|
|
/sbin/startproc $FAIL2BAN_BIN -q stop
|
|
|
|
rc_status -v
|
|
|
|
;;
|
2007-02-20 20:44:47 +00:00
|
|
|
try-restart|condrestart)
|
2007-07-10 20:04:57 +00:00
|
|
|
if test "$1" = "condrestart"; then
|
|
|
|
echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
|
|
|
|
fi
|
|
|
|
$0 status
|
|
|
|
if test $? = 0; then
|
|
|
|
$0 restart
|
|
|
|
else
|
|
|
|
rc_reset # Not running is not a failure.
|
|
|
|
fi
|
|
|
|
rc_status
|
|
|
|
;;
|
2007-02-20 20:44:47 +00:00
|
|
|
restart)
|
2007-07-10 20:04:57 +00:00
|
|
|
$0 stop
|
|
|
|
echo -n "-wait a minute "
|
|
|
|
i=60
|
|
|
|
while [ -e $FAIL2BAN_SOCKET ] && [ $i -gt 0 ]; do
|
|
|
|
sleep 1
|
|
|
|
i=$[$i-1]
|
|
|
|
echo -n "."
|
|
|
|
done
|
|
|
|
echo "."
|
|
|
|
$0 start
|
2007-02-20 20:44:47 +00:00
|
|
|
|
2007-07-10 20:04:57 +00:00
|
|
|
# Remember status and be quiet
|
|
|
|
rc_status
|
|
|
|
;;
|
2007-02-20 20:44:47 +00:00
|
|
|
force-reload)
|
2007-07-10 20:04:57 +00:00
|
|
|
echo -n "Reload service Fail2ban "
|
|
|
|
/sbin/startproc $FAIL2BAN_BIN -q reload
|
|
|
|
rc_status -v
|
|
|
|
;;
|
2007-02-20 20:44:47 +00:00
|
|
|
reload)
|
2007-07-10 20:04:57 +00:00
|
|
|
echo -n "Reload service Fail2ban "
|
|
|
|
/sbin/startproc $FAIL2BAN_BIN -q reload
|
|
|
|
rc_status -v
|
|
|
|
;;
|
2007-02-20 20:44:47 +00:00
|
|
|
status)
|
2007-07-10 20:04:57 +00:00
|
|
|
echo -n "Checking for service Fail2ban "
|
|
|
|
/sbin/checkproc $FAIL2BAN_SERVER
|
|
|
|
rc_status -v
|
|
|
|
;;
|
2007-02-20 20:44:47 +00:00
|
|
|
probe)
|
2007-07-10 20:04:57 +00:00
|
|
|
test /etc/fail2ban/fail2ban.conf -nt /var/run/fail2ban.pid && echo reload
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
rc_exit
|