- fixevi za Squeeze
[monit-cn.git] / debian / postinst
index e665ab6..8afacff 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# postinst script for bind9-cn
+# postinst script for monit-cn
 #
 # see: dh_installdeb(1)
 
@@ -34,7 +34,7 @@ esac
 installfile=1
 if [ -e /etc/monit/monitrc ]; then
     lines=$(grep -v '^#' /etc/monit/monitrc | wc -l)
-    if [ $lines -lt 2 ]; then
+    if [ $lines -lt 4 ]; then
         installfile=1
         mv -f /etc/monit/monitrc /etc/monit/monitrc.dpkg-old
     else
@@ -47,25 +47,46 @@ if [ $installfile -eq 1 ]; then
     chmod u=rw,go= /etc/monit/monitrc
 fi
 
+# sed monitrc with proper hostname
+if grep -q '@localhost' /etc/monit/monitrc; then
+    CARNET_HOSTNAME=`hostname`
+    CARNET_DOMAINNAME=`hostname --domain`
+    cp_check_and_sed '@localhost' \
+        "s/@localhost/@$CARNET_HOSTNAME.$CARNET_DOMAINNAME/g" \
+        /etc/monit/monitrc || true
+fi
+
+# fix "but not on { changed } bug in monitrc
+cp_check_and_sed '^set alert [^[:space:]]*@[^[:space:]]* (but )?not on { changed }$' \
+    's/^set alert \([^[:space:]]*@[^[:space:]]*\) .*$/set alert \1 only on { uid, gid, size, nonexist, data, icmp, instance, invalid, exec, timeout, resource, checksum, match, timestamp, connection, permission }/g' \
+    /etc/monit/monitrc || true
+
+# if alert for "changed" is enabled, disable it ASAP
+# we're waiting for "but not on { changed }" to enter in official
+# package...
+cp_check_and_sed '^set alert [^[:space:]]*@[^[:space:]]*$' \
+    's/^set alert \([^[:space:]]*@[^[:space:]]*\)$/set alert \1 only on { uid, gid, size, nonexist, data, icmp, instance, invalid, exec, timeout, resource, checksum, match, timestamp, connection, permission }/g' \
+    /etc/monit/monitrc || true
+
 # (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
+cp_check_and_sed '^startup[[:space:]]*=[[:space:]]*1' \
+    's/^startup[[:space:]]*=.*/startup=0/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
+if ! grep -q 'CARNet package monit-cn' /etc/init.d/monit; then
+    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
-fi
-if [ -e "/etc/init.d/monit" ]; then
-    if ! grep -q 'CARNet package monit-cn' /etc/init.d/monit; then
+    if [ -e "/etc/init.d/monit" ]; then
         # shebang
         head -n1 /etc/init.d/monit > /etc/init.d/monit.$$
         # middle part
@@ -84,8 +105,7 @@ fi
 # install as inittab service
 if ! grep -q '/usr/sbin/monit' /etc/inittab; then
     echo "CN: Installing monit service in /etc/inittab"
-    rm -f /etc/inittab.$$
-    cp /etc/inittab /etc/inittab.$$
+    cp -a /etc/inittab /etc/inittab.$$
     cp-update monit-cn /etc/inittab.$$ <<EOF
 mo:2345:respawn:/usr/sbin/monit -Ic /etc/monit/monitrc
 m0:06:wait:/usr/sbin/monit -Ic /etc/monit/monitrc stop myprocess
@@ -95,7 +115,7 @@ fi
 
 # reload init, since we have new configuration
 echo "CN: (Re)starting monit service, please check /var/log/daemon.log"
-pkill -9 -f /usr/sbin/monit || true
+pkill -9 -f '/usr/sbin/monit$' || true
 kill -HUP 1
 
 # dh_installdeb will replace this with shell code automatically