r13: - add postgrey + asterisk
[monit-cn.git] / debian / postinst
index e387901..e665ab6 100755 (executable)
@@ -47,23 +47,42 @@ if [ $installfile -eq 1 ]; then
     chmod u=rw,go= /etc/monit/monitrc
 fi
 
-# generate monit.d files
-update-monit.d
+# (re)generate monit.d files
+update-monit.d || true
 
 # disable monit startup
 cp_check_and_sed '^startup=1/#startup=1/g' /etc/default/monit \
     || true
 
+# systemv part
+echo "CN: Disabling monit SystemV script"
+if [ -x "/etc/init.d/monit" ]; then
+    update-rc.d -f monit remove >/dev/null 2>&1
+    if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+        invoke-rc.d monit stop || true
+    else
+        /etc/init.d/monit stop || true
+    fi
+fi
+if [ -e "/etc/init.d/monit" ]; then
+    if ! grep -q 'CARNet package monit-cn' /etc/init.d/monit; then
+        # shebang
+        head -n1 /etc/init.d/monit > /etc/init.d/monit.$$
+        # middle part
+        cp-update monit-cn /etc/init.d/monit.$$ <<EOF
+echo "CN: Monit SystemV init script disabled -- inittab is in use"
+echo "CN: Exiting now..."
+exit 0
+EOF
+        # rest of init script
+        tail -n+2 /etc/init.d/monit >> /etc/init.d/monit.$$
+        mv -f /etc/init.d/monit.$$ /etc/init.d/monit
+        chmod +x /etc/init.d/monit
+    fi
+fi
+
 # install as inittab service
 if ! grep -q '/usr/sbin/monit' /etc/inittab; then
-    if [ -x "/etc/init.d/monit" ]; then
-        update-rc.d -f monit remove >/dev/null 2>&1
-        if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
-            invoke-rc.d monit stop || true
-        else
-            /etc/init.d/monit stop || true
-        fi
-    fi
     echo "CN: Installing monit service in /etc/inittab"
     rm -f /etc/inittab.$$
     cp /etc/inittab /etc/inittab.$$
@@ -75,7 +94,8 @@ EOF
 fi
 
 # reload init, since we have new configuration
-echo "CN: Starting monit service, please check /var/log/daemon.log"
+echo "CN: (Re)starting monit service, please check /var/log/daemon.log"
+pkill -9 -f /usr/sbin/monit || true
 kill -HUP 1
 
 # dh_installdeb will replace this with shell code automatically