1#!/bin/sh
2#
3# rspamd - this script starts and stops the rspamd daemon
4### BEGIN INIT INFO
5# Provides:          rspamd
6# Required-Start:    $remote_fs $network
7# Required-Stop:     $network $remote_fs
8# Default-Start:     5
9# Default-Stop:
10# Short-Description: Rspamd daemon
11# Description:       Rspamd spam filtering daemon process
12### END INIT INFO
13#
14# chkconfig:   - 85 15
15# description:  rspamd is a spam filtering system
16# processname: rspamd
17# config:      /etc/rspamd/rspamd.conf
18# config:      /etc/sysconfig/rspamd
19# pidfile:     /var/run/rspamd/rspamd.pid
20
21# Source function library.
22. /etc/rc.d/init.d/functions
23
24# Source networking configuration.
25. /etc/sysconfig/network
26
27# Check that networking is up.
28[ "$NETWORKING" = "no" ] && exit 0
29
30rspamd="/usr/bin/rspamd"
31rspamadm="/usr/bin/rspamadm"
32prog=$(basename $rspamd)
33
34RSPAMD_CONF_FILE="/etc/rspamd/rspamd.conf"
35RSPAMD_USER="_rspamd"
36RSPAMD_GROUP="_rspamd"
37
38[ -f /etc/sysconfig/rspamd ] && . /etc/sysconfig/rspamd
39
40lockfile=/var/lock/subsys/rspamd
41
42start() {
43    [ -x $rspamd ] || exit 5
44    [ -f $rspamd_CONF_FILE ] || exit 6
45    echo -n $"Starting $prog: "
46    daemon $rspamd -c $RSPAMD_CONF_FILE -u $RSPAMD_USER -g $RSPAMD_GROUP
47    retval=$?
48    echo
49    [ $retval -eq 0 ] && touch $lockfile
50    return $retval
51}
52
53stop() {
54    echo -n $"Stopping $prog: "
55    killproc $prog -TERM
56    retval=$?
57    if [ $retval -eq 0 ]; then
58        if [ "$CONSOLETYPE" != "serial" ]; then
59           echo -en "\\033[16G"
60        fi
61        STOPTIMEOUT=30
62        while [ $STOPTIMEOUT -gt 0 ]; do
63            rh_status_q || break
64            sleep 1
65            let STOPTIMEOUT=${STOPTIMEOUT}-1
66        done
67        if [ $STOPTIMEOUT -eq 0 ]; then
68          echo "Timeout error occurred trying to stop Rspamd. Forcefully stop the remaining processes."
69          killproc $prog -KILL
70          # Sleep forever after SIGKILL being sent (e.g. UNINT SLEEP)
71          while rh_status_q
72          do
73            sleep 1
74            echo -n $"."
75          done
76        fi
77        rm -f $lockfile
78    fi
79    echo
80    return $retval
81}
82
83restart() {
84    configtest || return $?
85    stop
86    start
87}
88
89reload() {
90    configtest || return $?
91    echo -n $"Reloading $prog: "
92    killproc $rspamd -HUP
93    RETVAL=$?
94    echo
95}
96
97force_reload() {
98    restart
99}
100
101configtest() {
102  $rspamadm configtest -c $RSPAMD_CONF_FILE
103}
104
105rh_status() {
106    status $prog
107}
108
109rh_status_q() {
110    rh_status >/dev/null 2>&1
111}
112
113case "$1" in
114    start)
115        rh_status_q && exit 0
116        $1
117        ;;
118    stop)
119        rh_status_q || exit 0
120        $1
121        ;;
122    restart|configtest)
123        $1
124        ;;
125    reload)
126        rh_status_q || exit 7
127        $1
128        ;;
129    force-reload)
130        force_reload
131        ;;
132    status)
133        rh_status
134        ;;
135    condrestart|try-restart)
136        rh_status_q || exit 0
137        restart
138	    ;;
139    *)
140        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
141        exit 2
142esac
143