]> git.donarmstrong.com Git - deb_pkgs/spamass-milter.git/blob - debian/spamass-milter.init
afa63ca6774c764ecaf2b7bb391461a4f55c92ba
[deb_pkgs/spamass-milter.git] / debian / spamass-milter.init
1 #!/bin/sh
2 #
3 # $Id$
4 #
5 # Sample init script for Debian GNU/Linux
6 #
7 #  Copyright (c) 2002 Georg C. F. Greve <greve@gnu.org>,
8 #   all rights maintained by FSF Europe e.V., 
9 #   Villa Vogelsang, Antonienallee 1, 45279 Essen, Germany
10 #
11 #   This program is free software; you can redistribute it and/or modify
12 #   it under the terms of the GNU General Public License as published by
13 #   the Free Software Foundation; either version 2 of the License, or
14 #   (at your option) any later version.
15 #  
16 #   This program is distributed in the hope that it will be useful,
17 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
18 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 #   GNU General Public License for more details.
20 #  
21 #   You should have received a copy of the GNU General Public License
22 #   along with this program; if not, write to the Free Software
23 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24 #
25 #   Contact:
26 #            Michael Brown <michaelb@opentext.com>
27
28 # This init script was modified on Thu, 30 Jan 2003 02:06:04 -0500 by
29 # Don Armstrong <don@donarmstrong.com> from contrib/spamass-milter to
30 # allow force-reload and options specified in
31 # /etc/default/spamass-milter necessary for inclusion in debian.
32
33 # It has been modified additionally to support LSB Boot options and
34 # status on Friday, July 6, 2007 14:02:44 PDT
35
36
37 ### BEGIN INIT INFO
38 # Provides:          spamass-milter
39 # Required-Start:    $syslog $local_fs $remote_fs
40 # Required-Stop:     $syslog $local_fs $remote_fs
41 # Default-Start:     2 3 4 5
42 # Default-Stop:      0 1 6
43 # Short-Description: milter for spamassassin
44 # Description:       Calls spamassassin to allow filtering out
45 #                    spam from ham in libmilter compatible MTAs.
46 ### END INIT INFO
47
48
49 PATH=/sbin:/bin:/usr/sbin:/usr/bin
50 NAME=spamass-milter
51 DAEMON=/usr/sbin/spamass-milter
52 SOCKET=/var/run/spamass/spamass.sock
53 PIDFILE=/var/run/spamass/spamass.pid
54 DESC="Sendmail milter plugin for SpamAssassin"
55
56 DEFAULT=/etc/default/spamass-milter
57 OPTIONS=""
58 RUNAS="spamass-milter"
59 CHUID=""
60 SOCKETMODE="0600"
61 SOCKETOWNER="root:root"
62
63 test -x $DAEMON || exit 0
64
65 if [ -e /etc/mail/sendmail.cf ] && egrep -q 'X.+S=local:/var/run/sendmail/spamass\.sock' /etc/mail/sendmail.cf; then
66     SOCKET=/var/run/sendmail/spamass.sock
67     SOCKETMODE=""
68     SOCKETOWNER=""
69     RUNAS=""
70     echo "WARNING: You are using the old location of spamass.sock. Change your input filter to use";
71     echo "/var/run/spamass/spamass.sock so spamass-milter can run as spamass-milter";
72 fi;
73
74 # If /usr/sbin/postfix exists, set up the defaults for a postfix install
75 # These can be overridden in /etc/default/spamass-milter
76 if [ -x /usr/sbin/postfix ]; then
77     SOCKET="/var/spool/postfix/spamass/spamass.sock"
78     SOCKETOWNER="postfix:postfix"
79     SOCKETMODE="0660"
80 fi;
81
82 if [ -r $DEFAULT ]; then
83     . $DEFAULT;
84 fi;
85
86 if [ -n "$RUNAS" ]; then
87     CHUID="--chuid $RUNAS";
88 fi;
89
90 set -e
91
92 start() {
93     if status; then
94         echo "$NAME is already running";
95         exit 1;
96     fi;
97     # Because the default socket is in the same location as the
98     # pidfile, we create them in this order.
99     for DIR in "$(dirname $PIDFILE)" "$(dirname $SOCKET)"; do 
100     # if the dirname is '.', then it's some kind of odd socket, like
101     # an inet socket. Don't create the directory in such a case
102         if [ "$DIR" != "." ] && [ ! -d "$DIR" ]; then
103             mkdir -p "$DIR";
104             if [ -x /sbin/restorecon ]; then 
105                 /sbin/restorecon "$DIR";
106             fi;
107             if [ -n "$RUNAS" ]; then
108                 chown "$RUNAS" "$DIR";
109             fi;
110         fi;
111     done;
112     if [ -n "$RUNAS" ] && [ -d $(dirname $PIDFILE) ] &&
113         [ "$(stat -c '%U' $(dirname $PIDFILE))" != "$RUNAS" ]; then
114         echo "WARNING: $NAME will run as user $RUNAS but $(dirname $PIDFILE) is not owned by $RUNAS";
115         echo "Either delete this directory or chown it appropriately. Startup attempts may fail.";
116     fi;
117     if [ -n "$RUNAS" ] && [ $(dirname $SOCKET) != "." ] &&
118         [ -d $(dirname $SOCKET) ] &&
119         [ "$(stat -c '%U' $(dirname $SOCKET))" != "$RUNAS" ]; then
120         echo "WARNING: $NAME will run as user $RUNAS but $(dirname $SOCKET) is not owned by $RUNAS";
121         echo "Either delete this directory or chown it appropriately. Startup attempts may fail.";
122     fi;
123     if [ $(dirname $SOCKET) != "." ]; then 
124         /bin/rm -f $SOCKET
125     fi;
126     start-stop-daemon --start -p $PIDFILE $CHUID --exec $DAEMON -- -P $PIDFILE -f -p $SOCKET $OPTIONS
127     sleep 1
128     if [ -n "$SOCKETMODE" ]; then
129         chmod $SOCKETMODE $SOCKET;
130     fi;
131     if [ -n "$SOCKETOWNER" ]; then
132         chown $SOCKETOWNER $SOCKET;
133     fi;
134 }
135
136 stop(){
137     start-stop-daemon --oknodo --stop -p $PIDFILE --signal 3 --exec $DAEMON
138     /bin/sleep 5
139     /bin/rm -f $SOCKET
140     /bin/rm -f $PIDFILE
141 }
142
143 status(){
144     if [ -e $PIDFILE ]; then 
145         if kill -0 $(cat $PIDFILE); then
146             echo "${NAME} running";
147             exit 0;
148         else
149             echo "${NAME} dead but $PIDFILE exists";
150             exit 1;
151         fi;
152         echo "${NAME} not running";
153         exit 3;
154     fi;
155 }
156
157 case "$1" in
158   start)
159         echo -n "Starting $DESC: "
160         start
161         echo "${NAME}"
162         ;;
163   stop)
164         echo -n "Stopping $DESC: "
165         stop
166         echo "${NAME}"
167         ;;
168   force-reload | restart)
169         echo -n "Restarting $DESC: "
170
171         stop
172         start
173         echo "${NAME}"
174         ;;
175   status)
176         status
177         ;;
178   *)
179         N=$0
180         echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
181         exit 1
182         ;;
183 esac
184
185 exit 0