2011-11-21 14:37:46 +01:00
|
|
|
#! /bin/bash
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: rspamd
|
|
|
|
# Required-Start: $syslog $remote_fs
|
|
|
|
# Required-Stop: $syslog $remote_fs
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: Rspamd spam filtering system
|
2014-03-08 11:07:35 +01:00
|
|
|
# Description: Rspamd is fast and modular spam filtering system
|
2011-11-21 14:37:46 +01:00
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
# Author: Vsevolod Stakhov <vsevolod@highsecure.ru>
|
|
|
|
|
|
|
|
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
|
|
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
|
|
|
DESC="Rspamd"
|
|
|
|
NAME=rspamd
|
|
|
|
DAEMON=/usr/bin/$NAME
|
2015-10-14 22:48:41 +02:00
|
|
|
RSPAMADM=/usr/bin/rspamadm
|
2015-03-07 11:53:16 +01:00
|
|
|
DAEMON_ARGS="-c /etc/rspamd/rspamd.sysvinit.conf"
|
2013-02-02 20:27:55 +01:00
|
|
|
DESC="rapid spam filtering system"
|
2014-02-23 09:48:40 +01:00
|
|
|
PIDFILE=/run/rspamd/$NAME.pid
|
2011-11-21 14:37:46 +01:00
|
|
|
SCRIPTNAME=/etc/init.d/$NAME
|
|
|
|
|
|
|
|
# Exit if the package is not installed
|
|
|
|
[ -x "$DAEMON" ] || exit 0
|
|
|
|
|
|
|
|
# Load the VERBOSE setting and other rcS variables
|
|
|
|
. /lib/init/vars.sh
|
|
|
|
|
|
|
|
# Define LSB log_* functions.
|
|
|
|
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
|
|
|
|
#
|
|
|
|
# Function that starts the daemon/service
|
|
|
|
#
|
|
|
|
do_start()
|
|
|
|
{
|
|
|
|
# Return
|
|
|
|
# 0 if daemon has been started
|
|
|
|
# 1 if daemon was already running
|
|
|
|
# 2 if daemon could not be started
|
2014-11-08 20:05:54 +01:00
|
|
|
mkdir -m 755 -p /run/rspamd
|
|
|
|
chown _rspamd:_rspamd /run/rspamd
|
2015-10-14 15:51:22 +02:00
|
|
|
$RSPAMADM configtest $DAEMON_ARGS > /dev/null \
|
2011-11-21 14:37:46 +01:00
|
|
|
|| return 1
|
|
|
|
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
|
2014-03-28 15:01:33 +01:00
|
|
|
$DAEMON_ARGS -u _rspamd -g _rspamd \
|
2011-11-21 14:37:46 +01:00
|
|
|
|| return 2
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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
|
2011-11-21 15:20:10 +01:00
|
|
|
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
|
2011-11-21 14:37:46 +01:00
|
|
|
RETVAL="$?"
|
|
|
|
[ "$RETVAL" = 2 ] && return 2
|
|
|
|
# Many daemons don't delete their pidfiles when they exit.
|
|
|
|
rm -f $PIDFILE
|
|
|
|
return "$RETVAL"
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Function that sends a SIGHUP to the daemon/service
|
|
|
|
#
|
|
|
|
do_reload() {
|
2011-11-21 15:20:10 +01:00
|
|
|
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
|
2011-11-21 14:37:46 +01:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-11-23 12:27:36 +01:00
|
|
|
#
|
|
|
|
# Function that sends a SIGUSR1 to the daemon/service
|
|
|
|
#
|
|
|
|
do_reopenlog() {
|
|
|
|
start-stop-daemon --stop --signal 10 --quiet --pidfile $PIDFILE
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2014-03-06 22:02:50 +01:00
|
|
|
case "$1" in
|
2011-11-21 14:37:46 +01:00
|
|
|
start)
|
2014-03-06 22:02:50 +01:00
|
|
|
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
|
|
|
do_start
|
|
|
|
case "$?" in
|
|
|
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
|
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
|
|
esac
|
|
|
|
;;
|
2011-11-21 14:37:46 +01:00
|
|
|
stop)
|
2014-03-06 22:02:50 +01:00
|
|
|
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
|
|
|
do_stop
|
|
|
|
case "$?" in
|
|
|
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
|
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
|
|
esac
|
|
|
|
;;
|
2011-11-21 14:37:46 +01:00
|
|
|
status)
|
2014-03-06 22:02:50 +01:00
|
|
|
status_of_proc -p $PIDFILE "$DAEMON" "$NAME" || exit $?
|
|
|
|
;;
|
2016-08-22 19:12:22 +02:00
|
|
|
reload|force-reload)
|
|
|
|
log_daemon_msg "Reloading $DESC" "$NAME"
|
|
|
|
do_reload
|
|
|
|
log_end_msg $?
|
|
|
|
;;
|
2011-11-23 12:27:36 +01:00
|
|
|
reopenlog)
|
2014-03-06 22:02:50 +01:00
|
|
|
log_daemon_msg "Reopen logs for $DESC" "$NAME"
|
|
|
|
do_reopenlog
|
|
|
|
log_end_msg $?
|
|
|
|
;;
|
2011-11-21 14:37:46 +01:00
|
|
|
restart)
|
2014-03-06 22:02:50 +01:00
|
|
|
log_daemon_msg "Restarting $DESC" "$NAME"
|
|
|
|
do_stop
|
|
|
|
case "$?" in
|
|
|
|
0|1)
|
|
|
|
do_start
|
2011-11-21 14:37:46 +01:00
|
|
|
case "$?" in
|
2014-03-06 22:02:50 +01:00
|
|
|
0) log_end_msg 0 ;;
|
|
|
|
1) log_end_msg 1 ;; # Old process is still running
|
|
|
|
*) log_end_msg 1 ;; # Failed to start
|
2011-11-21 14:37:46 +01:00
|
|
|
esac
|
|
|
|
;;
|
2014-03-06 22:02:50 +01:00
|
|
|
*)
|
|
|
|
# Failed to stop
|
|
|
|
log_end_msg 1
|
2011-11-21 14:37:46 +01:00
|
|
|
;;
|
2014-03-06 22:02:50 +01:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
2016-08-22 19:12:22 +02:00
|
|
|
echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|reopenlog}" >&2
|
2014-03-06 22:02:50 +01:00
|
|
|
exit 3
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|