]> git.donarmstrong.com Git - deb_pkgs/spamass-milter.git/blob - debian/spamass-milter.init
flip order of piddir and socketdir creation
[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 NAME=spamass-milter
36 DAEMON=/usr/sbin/spamass-milter
37 SOCKET=/var/run/spamass/spamass.sock
38 PIDFILE=/var/run/spamass/spamass.pid
39 DESC="Sendmail milter plugin for SpamAssassin"
40
41 DEFAULT=/etc/default/spamass-milter
42 OPTIONS=""
43 RUNAS="nobody"
44 CHUID=""
45 SOCKETMODE="0640"
46 SOCKETOWNER="root:root"
47
48 test -x $DAEMON || exit 0
49
50 if [ -e /etc/mail/sendmail.cf ] && egrep -q 'X.+S=local:/var/run/sendmail/spamass\.sock' /etc/mail/sendmail.cf; then
51     SOCKET=/var/run/sendmail/spamass.sock
52     SOCKETMODE=""
53     SOCKETOWNER=""
54     RUNAS=""
55     echo "WARNING: You are using the old location of spamass.sock. Change your input filter to use";
56     echo "/var/run/spamass/spamass.sock so spamass-milter can run as nobody";
57 fi;
58
59 # If /usr/sbin/postfix exists, set up the defaults for a postfix install
60 # These can be overridden in /etc/default/spamass-milter
61 if [ -x /usr/sbin/postfix ]; then
62     SOCKET="/var/spool/postfix/spamass/spamass.sock"
63     SOCKETOWNER="postfix:postfix"
64     SOCKETMODE="0660"
65 fi;
66
67 if [ -r $DEFAULT ]; then
68     . $DEFAULT;
69 fi;
70
71 if [ -n "$RUNAS" ]; then
72     CHUID="--chuid $RUNAS";
73 fi;
74
75 set -e
76
77 start() {
78     # Because the default socket is in the same location as the
79     # pidfile, we create them in this order.
80     if [ ! -d $(dirname $PIDFILE) ]; then
81         mkdir -p $(dirname $PIDFILE);
82         if [ -d $(dirname $PIDFILE) ] && [ -n "$RUNAS" ]; then
83             chown "$RUNAS" $(dirname $PIDFILE);
84         fi;
85     fi;
86     if [ ! -d $(dirname $SOCKET) ]; then
87         mkdir -p $(dirname $SOCKET);
88         if [ -n "$SOCKETOWNER" ]; then
89             chown "$SOCKETOWNER" $(dirname $SOCKET);
90         fi;
91     fi;
92     if [ -n "$RUNAS" ] && [ -d $(dirname $PIDFILE) ] && [ "$(stat -c '%U' $(dirname $PIDFILE))" != "$RUNAS" ]; then
93         echo "WARNING: $NAME will run as user $RUNAS but $(dirname $PIDFILE) is not owned by $RUNAS";
94         echo "Either delete this directory or chown it appropriately. Startup attempts may fail.";
95     fi;
96     /bin/rm -f $SOCKET
97     start-stop-daemon --start -p $PIDFILE $CHUID --exec $DAEMON -- -P $PIDFILE -f -p $SOCKET $OPTIONS
98     sleep 1s
99     if [ -n "$SOCKETMODE" ]; then
100         chmod $SOCKETMODE $SOCKET;
101     fi;
102     if [ -n "$SOCKETOWNER" ]; then
103         chown $SOCKETOWNER $SOCKET;
104     fi;
105 }
106
107 stop(){
108     start-stop-daemon --stop -p $PIDFILE --signal 3 --exec $DAEMON
109     /bin/sleep 5s
110     /bin/rm -f $SOCKET
111 }
112
113 case "$1" in
114   start)
115         echo -n "Starting $DESC: "
116         start
117         echo "${NAME}"
118         ;;
119   stop)
120         echo -n "Stopping $DESC: "
121         stop
122         echo "${NAME}"
123         ;;
124   force-reload | restart)
125         echo -n "Restarting $DESC: "
126
127         stop
128         start
129         echo "${NAME}"
130
131         ;;
132   *)
133         N=$0
134         echo "Usage: $N {start|stop|restart}" >&2
135         exit 1
136         ;;
137 esac
138
139 exit 0