forked from tcisme/lnmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.d.fail2ban
106 lines (92 loc) · 2.31 KB
/
init.d.fail2ban
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#! /bin/sh
#
# chkconfig: 2345 55 25
# 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
#
### BEGIN INIT INFO
# Provides: fail2ban
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $time $network $syslog $named iptables firehol shorewall ipmasq arno-iptables-firewall iptables-persistent ferm ufw
# Should-Stop: $network $syslog $named iptables firehol shorewall ipmasq arno-iptables-firewall iptables-persistent ferm ufw
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop fail2ban
# Description: Start/stop fail2ban, a daemon scanning the log files and
# banning potential attackers.
### END INIT INFO
# Author: licess
# website: https://lnmp.org
PATH=/usr/sbin:/usr/bin:/sbin:/bin
NAME=fail2ban
# fail2ban-client is not a daemon itself but starts a daemon and
# loads its with configuration
DAEMON=/usr/bin/$NAME-client
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
do_start()
{
# Assure that /var/run/fail2ban exists
[ -d /var/run/fail2ban ] || mkdir -p /var/run/fail2ban
echo -n "Starting fail2ban..."
$DAEMON -x start > /dev/null
if [ $? -eq 0 ]; then
echo " done"
else
echo " failed"
fi
}
do_status()
{
$DAEMON ping > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "fail2ban is running."
else
echo "fail2ban is stop."
fi
}
do_stop()
{
echo -n "Stopping fail2ban..."
$DAEMON stop > /dev/null || return 2
if [ $? -eq 0 ]; then
echo " done"
else
echo " failed"
fi
}
do_reload() {
echo -n "Reloading fail2ban..."
$DAEMON reload > /dev/null
if [ $? -eq 0 ]; then
echo " done"
else
echo " failed"
fi
}
command="$1"
case "$command" in
start|force-start)
do_start "$command"
;;
stop)
do_stop
;;
restart|force-reload)
do_stop
do_start
;;
reload|force-reload)
do_reload
;;
status)
do_status
;;
*)
echo "Usage: $SCRIPTNAME {start|force-start|stop|restart|force-reload|status}" >&2
;;
esac