]> TLD Linux GIT Repositories - packages/spamassassin.git/blob - spamassassin-spamd.init
- updated to 4.0.1
[packages/spamassassin.git] / spamassassin-spamd.init
1 #!/bin/sh
2 #
3 # spamassassin This script starts and stops the spamd daemon
4 #
5 # chkconfig: 2345 80 30
6 #
7 # description: spamd is a daemon process which uses SpamAssassin to check \
8 #              email messages for SPAM.  It is normally called by spamc \
9 #              from a MDA.
10 # processname: spamd
11 # pidfile:     /var/run/spamd.pid
12
13 # Source function library.
14 . /etc/rc.d/init.d/functions
15
16 # Source networking configuration.
17 . /etc/sysconfig/network
18
19 SPAMD_OPTS="-d -c"
20 # Source configureation.
21 if [ -f /etc/sysconfig/spamd ] ; then
22         . /etc/sysconfig/spamd
23 fi
24
25 # Check that networking is up.
26 if is_no "${NETWORKING}"; then
27         msg_network_down "SpamAssassin"
28         exit 1
29 fi
30
31 start() {
32         # Start daemon.
33         if [ -f /var/lock/subsys/spamd ]; then
34                 msg_already_running "SpamAssassin"
35                 return
36         fi
37
38         # Check if database is installed.
39         if [ "$(find /var/lib/spamassassin/ -name '*.cf' | head -n1 | wc -l)" -eq 0 ]; then
40                 show 'Spamassassin database not found. Run sa-update first.'; fail
41                 return 1
42         fi
43
44         msg_starting "SpamAssassin"
45         daemon /usr/bin/spamd -r /var/run/spamd.pid $SPAMD_OPTS
46         RETVAL=$?
47         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/spamd
48 }
49
50 stop() {
51         # Stop daemons.
52         if [ ! -f /var/lock/subsys/spamd ]; then
53                 msg_not_running "SpamAssassin"
54                 return
55         fi
56
57         msg_stopping "SpamAssassin"
58         killproc --pidfile spamd.pid spamd
59         RETVAL=$?
60         rm -f /var/lock/subsys/spamd
61 }
62
63 condrestart() {
64         if [ ! -f /var/lock/subsys/spamd ]; then
65                 msg_not_running "SpamAssassin"
66                 RETVAL=$1
67                 return
68         fi
69
70         stop
71         start
72 }
73
74 # See how we were called.
75 case "$1" in
76   start)
77         start
78         ;;
79   stop)
80         stop
81         ;;
82   restart)
83         stop
84         start
85         ;;
86   try-restart)
87         condrestart 0
88         ;;
89   force-reload)
90         condrestart 7
91         ;;
92   status)
93         status --pidfile spamd.pid spamd
94         ;;
95   *)
96         msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
97         exit 1
98 esac
99
100 exit $RETVAL