]> git.donarmstrong.com Git - deb_pkgs/spamass-milter.git/blobdiff - debian/spamass-milter.init
flip order of piddir and socketdir creation
[deb_pkgs/spamass-milter.git] / debian / spamass-milter.init
index 2518624e37cee5c9ea94fbf05aa397fc75ad996d..4855d4eec76efebbdaa4cee5541a802f05323523 100644 (file)
@@ -32,6 +32,7 @@
 
 
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
+NAME=spamass-milter
 DAEMON=/usr/sbin/spamass-milter
 SOCKET=/var/run/spamass/spamass.sock
 PIDFILE=/var/run/spamass/spamass.pid
@@ -41,17 +42,26 @@ DEFAULT=/etc/default/spamass-milter
 OPTIONS=""
 RUNAS="nobody"
 CHUID=""
-SOCKETMODE="0660"
-SOCKETOWNER="root:adm"
+SOCKETMODE="0640"
+SOCKETOWNER="root:root"
 
 test -x $DAEMON || exit 0
 
+if [ -e /etc/mail/sendmail.cf ] && egrep -q 'X.+S=local:/var/run/sendmail/spamass\.sock' /etc/mail/sendmail.cf; then
+    SOCKET=/var/run/sendmail/spamass.sock
+    SOCKETMODE=""
+    SOCKETOWNER=""
+    RUNAS=""
+    echo "WARNING: You are using the old location of spamass.sock. Change your input filter to use";
+    echo "/var/run/spamass/spamass.sock so spamass-milter can run as nobody";
+fi;
+
 # If /usr/sbin/postfix exists, set up the defaults for a postfix install
 # These can be overridden in /etc/default/spamass-milter
 if [ -x /usr/sbin/postfix ]; then
     SOCKET="/var/spool/postfix/spamass/spamass.sock"
-    PIDFILE="/var/spool/postfix/spamass/spamass.pid"
     SOCKETOWNER="postfix:postfix"
+    SOCKETMODE="0660"
 fi;
 
 if [ -r $DEFAULT ]; then
@@ -65,23 +75,23 @@ fi;
 set -e
 
 start() {
+    # Because the default socket is in the same location as the
+    # pidfile, we create them in this order.
+    if [ ! -d $(dirname $PIDFILE) ]; then
+       mkdir -p $(dirname $PIDFILE);
+       if [ -d $(dirname $PIDFILE) ] && [ -n "$RUNAS" ]; then
+           chown "$RUNAS" $(dirname $PIDFILE);
+       fi;
+    fi;
     if [ ! -d $(dirname $SOCKET) ]; then
        mkdir -p $(dirname $SOCKET);
        if [ -n "$SOCKETOWNER" ]; then
            chown "$SOCKETOWNER" $(dirname $SOCKET);
        fi;
     fi;
-    if [ ! -d $(dirname $PIDFILE) ]; then
-       mkdir -p $(dirname $PIDFILE);
-       if [ -n "$RUNAS" ]; then
-           chown "$RUNAS" $(dirname $PIDFILE);
-       fi;
-    fi;
-    # Drop in a compatibility symlink for the old sendmail socket location
-    if [ -d /var/run/sendmail ] && [ -n "$RUNAS" ] && 
-       [ "$SOCKET" == "/var/run/spamass/spamass.sock" ] && 
-       [ ! -L /var/run/sendmail/spamass.sock ] || [ ! -e /var/run/sendmail/spamass.sock ]; then
-       ln -s $SOCKET /var/run/sendmail/spamass.sock;
+    if [ -n "$RUNAS" ] && [ -d $(dirname $PIDFILE) ] && [ "$(stat -c '%U' $(dirname $PIDFILE))" != "$RUNAS" ]; then
+       echo "WARNING: $NAME will run as user $RUNAS but $(dirname $PIDFILE) is not owned by $RUNAS";
+       echo "Either delete this directory or chown it appropriately. Startup attempts may fail.";
     fi;
     /bin/rm -f $SOCKET
     start-stop-daemon --start -p $PIDFILE $CHUID --exec $DAEMON -- -P $PIDFILE -f -p $SOCKET $OPTIONS
@@ -90,7 +100,7 @@ start() {
        chmod $SOCKETMODE $SOCKET;
     fi;
     if [ -n "$SOCKETOWNER" ]; then
-       chown $SOCKETOWNER $SOCKET:
+       chown $SOCKETOWNER $SOCKET;
     fi;
 }
 
@@ -104,19 +114,19 @@ case "$1" in
   start)
        echo -n "Starting $DESC: "
        start
-       echo "${DAEMON}"
+       echo "${NAME}"
        ;;
   stop)
        echo -n "Stopping $DESC: "
        stop
-       echo "${DAEMON}"
+       echo "${NAME}"
        ;;
   force-reload | restart)
        echo -n "Restarting $DESC: "
 
        stop
        start
-       echo "${DAEMON}"
+       echo "${NAME}"
 
        ;;
   *)