]> git.donarmstrong.com Git - deb_pkgs/spamass-milter.git/blob - debian/spamass-milter.init
and sleep before chown to allow the socket to be created
[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
34 PATH=/sbin:/bin:/usr/sbin:/usr/bin
35 DAEMON=/usr/sbin/spamass-milter
36 SOCKET=/var/run/spamass/spamass.sock
37 PIDFILE=/var/run/spamass/spamass.pid
38 DESC="Sendmail milter plugin for SpamAssassin"
39
40 DEFAULT=/etc/default/spamass-milter
41 OPTIONS=""
42 RUNAS="nobody"
43 CHUID=""
44 SOCKETMODE="0660"
45 SOCKETOWNER="root:adm"
46
47 test -x $DAEMON || exit 0
48
49 # If /usr/sbin/postfix exists, set up the defaults for a postfix install
50 # These can be overridden in /etc/default/spamass-milter
51 if [ -x /usr/sbin/postfix ]; then
52     SOCKET="/var/spool/postfix/spamass/spamass.sock"
53     PIDFILE="/var/spool/postfix/spamass/spamass.pid"
54     SOCKETOWNER="postfix:postfix"
55 fi;
56
57 if [ -r $DEFAULT ]; then
58     . $DEFAULT;
59 fi;
60
61 if [ -n "$RUNAS" ]; then
62     CHUID="--chuid $RUNAS";
63 fi;
64
65 set -e
66
67 start() {
68     if [ ! -d $(dirname $SOCKET) ]; then
69         mkdir -p $(dirname $SOCKET);
70         if [ -n "$SOCKETOWNER" ]; then
71             chown "$SOCKETOWNER" $(dirname $SOCKET);
72         fi;
73     fi;
74     if [ ! -d $(dirname $PIDFILE) ]; then
75         mkdir -p $(dirname $PIDFILE);
76         if [ -n "$RUNAS" ]; then
77             chown "$RUNAS" $(dirname $PIDFILE);
78         fi;
79     fi;
80     # Drop in a compatibility symlink for the old sendmail socket location
81     if [ -d /var/run/sendmail ] && [ -n "$RUNAS" ] && 
82         [ "$SOCKET" == "/var/run/spamass/spamass.sock" ] && 
83         ! [ -e /var/run/sendmail/spamass.sock ]; then
84         ln -s $SOCKET /var/run/sendmail/spamass.sock;
85     fi;
86     /bin/rm -f $SOCKET
87     start-stop-daemon --start -p $PIDFILE $CHUID --exec $DAEMON -- -P $PIDFILE -f -p $SOCKET $OPTIONS
88     sleep 1s
89     if [ -n "$SOCKETMODE" ]; then
90         chmod $SOCKETMODE $SOCKET;
91     fi;
92     if [ -n "$SOCKETOWNER" ]; then
93         chown $SOCKETOWNER $SOCKET:
94     fi;
95 }
96
97 stop(){
98     start-stop-daemon --stop -p $PIDFILE --signal 3 --exec $DAEMON
99     /bin/sleep 5s
100     /bin/rm -f $SOCKET
101 }
102
103 case "$1" in
104   start)
105         echo -n "Starting $DESC: "
106         start
107         echo "${DAEMON}"
108         ;;
109   stop)
110         echo -n "Stopping $DESC: "
111         stop
112         echo "${DAEMON}"
113         ;;
114   force-reload | restart)
115         echo -n "Restarting $DESC: "
116
117         stop
118         start
119         echo "${DAEMON}"
120
121         ;;
122   *)
123         N=$0
124         echo "Usage: $N {start|stop|restart}" >&2
125         exit 1
126         ;;
127 esac
128
129 exit 0