80 lines
2.0 KiB
Bash
Executable File
80 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
### BEGIN INIT INFO
|
|
# Provides: fail2ban-p2p
|
|
# Required-Start: $remote_fs $network $syslog
|
|
# Required-Stop: $remote_fs $network $syslog
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 0 1 6
|
|
# Short-Description: exchange fail2ban ban information between trusted peers
|
|
# Description: Starts the fail2ban-p2p daemon that exchanges attacker
|
|
# information between trusted nodes.
|
|
### END INIT INFO
|
|
|
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
|
DESC="fail2ban-p2p daemon"
|
|
NAME=fail2ban-p2p
|
|
DAEMON=/usr/bin/fail2ban-p2p.py
|
|
DAEMON_USER=fail2ban-p2p
|
|
DAEMON_GROUP=fail2ban-p2p
|
|
PIDFILE=/run/$NAME.pid
|
|
SCRIPTNAME=/etc/init.d/$NAME
|
|
DAEMON_ARGS=""
|
|
|
|
[ -x "$DAEMON" ] || exit 0
|
|
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
|
|
|
if [ "$START_DAEMON" != "true" ]; then
|
|
echo "fail2ban-p2p is disabled in /etc/default/$NAME"
|
|
exit 0
|
|
fi
|
|
|
|
. /lib/init/vars.sh
|
|
. /lib/lsb/init-functions
|
|
|
|
do_start() {
|
|
start-stop-daemon --start --quiet --background --make-pidfile \
|
|
--pidfile "$PIDFILE" --chuid "$DAEMON_USER:$DAEMON_GROUP" \
|
|
--exec "$DAEMON" --test > /dev/null || return 1
|
|
|
|
start-stop-daemon --start --quiet --background --make-pidfile \
|
|
--pidfile "$PIDFILE" --chuid "$DAEMON_USER:$DAEMON_GROUP" \
|
|
--exec "$DAEMON" -- $DAEMON_ARGS || return 2
|
|
}
|
|
|
|
do_stop() {
|
|
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
|
|
--pidfile "$PIDFILE" --name "$(basename "$DAEMON")"
|
|
RETVAL="$?"
|
|
[ "$RETVAL" = 2 ] && return 2
|
|
rm -f "$PIDFILE"
|
|
return "$RETVAL"
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
log_daemon_msg "Starting $DESC" "$NAME"
|
|
do_start
|
|
log_end_msg $?
|
|
;;
|
|
stop)
|
|
log_daemon_msg "Stopping $DESC" "$NAME"
|
|
do_stop
|
|
log_end_msg $?
|
|
;;
|
|
status)
|
|
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
|
|
;;
|
|
restart|force-reload)
|
|
log_daemon_msg "Restarting $DESC" "$NAME"
|
|
do_stop || true
|
|
do_start
|
|
log_end_msg $?
|
|
;;
|
|
*)
|
|
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
|
|
exit 3
|
|
;;
|
|
esac
|
|
|
|
exit 0
|