2006-10-14 14:35:46 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# chkconfig: 345 92 08
|
|
|
|
# description: Fail2ban daemon
|
|
|
|
# http://fail2ban.sourceforge.net/wiki/index.php/Main_Page
|
|
|
|
# process name: fail2ban-server
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Author: Tyler Owen
|
|
|
|
#
|
|
|
|
|
|
|
|
# Source function library.
|
|
|
|
. /etc/init.d/functions
|
|
|
|
|
|
|
|
# Check that the config file exists
|
|
|
|
[ -f /etc/fail2ban/fail2ban.conf ] || exit 0
|
|
|
|
|
|
|
|
FAIL2BAN="/usr/bin/fail2ban-client"
|
|
|
|
|
|
|
|
RETVAL=0
|
|
|
|
|
|
|
|
getpid() {
|
2007-07-11 22:12:45 +00:00
|
|
|
pid=`ps -eo pid,comm | grep fail2ban- | awk '{ print $1 }'`
|
2006-10-14 14:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
echo -n $"Starting fail2ban: "
|
|
|
|
getpid
|
2006-12-03 21:58:48 +00:00
|
|
|
if [ -z "$pid" ]; then
|
2008-07-21 14:13:13 +00:00
|
|
|
rm -rf /var/run/fail2ban/fail2ban.sock # in case of unclean shutdown
|
2006-10-14 14:35:46 +00:00
|
|
|
$FAIL2BAN start > /dev/null
|
|
|
|
RETVAL=$?
|
|
|
|
fi
|
|
|
|
if [ $RETVAL -eq 0 ]; then
|
|
|
|
touch /var/lock/subsys/fail2ban
|
|
|
|
echo_success
|
|
|
|
else
|
|
|
|
echo_failure
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
echo -n $"Stopping fail2ban: "
|
|
|
|
getpid
|
|
|
|
RETVAL=$?
|
|
|
|
if [ -n "$pid" ]; then
|
|
|
|
$FAIL2BAN stop > /dev/null
|
2006-12-10 16:37:22 +00:00
|
|
|
sleep 1
|
2006-10-14 14:35:46 +00:00
|
|
|
getpid
|
|
|
|
if [ -z "$pid" ]; then
|
|
|
|
rm -f /var/lock/subsys/fail2ban
|
|
|
|
echo_success
|
|
|
|
else
|
|
|
|
echo_failure
|
|
|
|
fi
|
2007-05-01 22:42:10 +00:00
|
|
|
else
|
|
|
|
echo_failure
|
|
|
|
fi
|
2006-10-14 14:35:46 +00:00
|
|
|
echo
|
|
|
|
return $RETVAL
|
|
|
|
}
|
|
|
|
|
|
|
|
# See how we were called.
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
getpid
|
|
|
|
if [ -n "$pid" ]; then
|
|
|
|
echo "Fail2ban (pid $pid) is running..."
|
2007-05-01 22:42:10 +00:00
|
|
|
$FAIL2BAN status
|
2006-10-14 14:35:46 +00:00
|
|
|
else
|
|
|
|
RETVAL=1
|
|
|
|
echo "Fail2ban is stopped"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
restart)
|
2007-05-01 22:42:10 +00:00
|
|
|
stop
|
2006-10-14 14:35:46 +00:00
|
|
|
start
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo $"Usage: $0 {start|stop|status|restart}"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $RETVAL
|