2014-07-21 14:42:03 +02:00
|
|
|
#! /bin/sh
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
#
|
|
|
|
# Provides: fail2rest
|
|
|
|
# Required-Start: $remote_fs $syslog
|
|
|
|
# Required-Stop: $remote_fs $syslog
|
|
|
|
# Should-Start: fail2ban
|
|
|
|
# Should-Stop: fail2ban
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: fail2rest initscript
|
|
|
|
# Description: fail2rest is a small REST server that aims allow full administration of a fail2ban server via HTTP
|
|
|
|
#
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
|
|
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
|
|
|
DESC="fail2rest is a small REST server that aims to allow full administration of a fail2ban server via HTTP"
|
|
|
|
NAME=fail2rest #CHANGE TO THE NAME OF YOUR FAIL2REST BINARY
|
|
|
|
DAEMON_DIR=/var/www/fail2rest #CHANGE TO YOUR FAIL2REST BINARY DIRECTORY
|
|
|
|
DAEMON="$DAEMON_DIR/$NAME"
|
|
|
|
DAEMON_ARGS="-config=$DAEMON_DIR/config.json" #CHANGE TO THE NAME OF YOUR FAIL2REST CONFIG FILE NAME AND DIRECTORY IF NEED BE
|
|
|
|
PIDFILE=/var/run/$NAME.pid
|
|
|
|
SCRIPTNAME=/etc/init.d/$NAME
|
2014-07-22 00:31:03 +02:00
|
|
|
|
2014-07-21 14:42:03 +02:00
|
|
|
# Load the VERBOSE setting and other rcS variables
|
|
|
|
. /lib/init/vars.sh
|
2014-07-22 00:31:03 +02:00
|
|
|
|
2014-07-21 14:42:03 +02:00
|
|
|
# Define LSB log_* functions.
|
|
|
|
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present
|
|
|
|
. /lib/lsb/init-functions
|
2014-07-22 00:31:03 +02:00
|
|
|
|
2014-07-21 14:42:03 +02:00
|
|
|
#
|
|
|
|
# Function that starts the daemon/service
|
|
|
|
#
|
|
|
|
do_start ()
|
|
|
|
{
|
2014-07-22 00:31:03 +02:00
|
|
|
# Return
|
2014-07-21 14:42:03 +02:00
|
|
|
# 0 if daemon has been started
|
|
|
|
# 1 if daemon was already running
|
|
|
|
# 2 if daemon could not be started
|
|
|
|
log_daemon_msg "Starting system $NAME daemon"
|
|
|
|
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --chdir $DAEMON_DIR --exec $DAEMON -- $DAEMON_ARGS
|
|
|
|
log_end_msg $?
|
2014-07-22 00:31:03 +02:00
|
|
|
|
2014-07-21 14:42:03 +02:00
|
|
|
# Add code here, if necessary, that waits for the process to be ready
|
|
|
|
# to handle requests from services started subsequently which depend
|
|
|
|
# on this one. As a last resort, sleep for some time.
|
|
|
|
}
|
2014-07-22 00:31:03 +02:00
|
|
|
|
2014-07-21 14:42:03 +02:00
|
|
|
#
|
|
|
|
# Function that stops the daemon/service
|
|
|
|
#
|
|
|
|
do_stop()
|
|
|
|
{
|
|
|
|
# Return
|
|
|
|
# 0 if daemon has been stopped
|
|
|
|
# 1 if daemon was already stopped
|
|
|
|
# 2 if daemon could not be stopped
|
|
|
|
# other if a failure occurred
|
|
|
|
log_daemon_msg "Stopping system $NAME daemon"
|
|
|
|
start-stop-daemon --stop --retry=10 --pidfile $PIDFILE
|
|
|
|
log_end_msg $?
|
|
|
|
}
|
2014-07-22 00:31:03 +02:00
|
|
|
|
2014-07-21 14:42:03 +02:00
|
|
|
case "$1" in
|
|
|
|
start|stop)
|
|
|
|
do_${1}
|
|
|
|
;;
|
|
|
|
restart|reload|force-reload)
|
2014-07-22 00:31:03 +02:00
|
|
|
do_stop
|
|
|
|
do_start
|
2014-07-21 14:42:03 +02:00
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status_of_proc "$NAME" "$DAEMON" && exit 0 || exit $?
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
|
|
|
|
exit 3
|
|
|
|
;;
|
|
|
|
esac
|
2014-07-22 00:31:03 +02:00
|
|
|
|
2014-07-21 14:42:03 +02:00
|
|
|
:
|