X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=debian%2Fpostinst;h=29a05cdff582cad64fcd441465591f8180090714;hb=5fabdf86c590c423463f0e91462b7f0b06f39f62;hp=e3879012b442df3dff3e85c8991d0b6ef0b1c005;hpb=c8e1f9a3251c3c43dd63e058de7924542c4d0d25;p=monit-cn.git diff --git a/debian/postinst b/debian/postinst index e387901..29a05cd 100755 --- a/debian/postinst +++ b/debian/postinst @@ -1,5 +1,5 @@ #!/bin/sh -# postinst script for bind9-cn +# postinst script for monit-cn # # see: dh_installdeb(1) @@ -30,11 +30,10 @@ esac # import CN-functions . /usr/share/carnet-tools/functions.sh -# check if monitrc is an empty template +# check if monitrc is ours installfile=1 if [ -e /etc/monit/monitrc ]; then - lines=$(grep -v '^#' /etc/monit/monitrc | wc -l) - if [ $lines -lt 2 ]; then + if ! grep -q "CARNet package monit-cn" /etc/monit/monitrc; then installfile=1 mv -f /etc/monit/monitrc /etc/monit/monitrc.dpkg-old else @@ -47,39 +46,43 @@ if [ $installfile -eq 1 ]; then chmod u=rw,go= /etc/monit/monitrc fi -# generate monit.d files -update-monit.d +# 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 -# disable monit startup -cp_check_and_sed '^startup=1/#startup=1/g' /etc/default/monit \ - || true +# migrate to "but not on { instance }" alerting style +cp_check_and_sed '^set alert [^[:space:]]*@[^[:space:]]* ' \ + 's/^set alert \([^[:space:]]*@[^[:space:]]*\) .*$/set alert \1 but not on { instance }/g' \ + /etc/monit/monitrc || true -# 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.$$ - cp-update monit-cn /etc/inittab.$$ </dev/null 2>&1 || true fi -# reload init, since we have new configuration -echo "CN: Starting monit service, please check /var/log/daemon.log" -kill -HUP 1 +# (re)generate monit.d files +update-monit.d || true + +# disable monit startup +cp_check_and_sed '^startup[[:space:]]*=[[:space:]]*0' \ + 's/^startup[[:space:]]*=.*/startup=1/g' /etc/default/monit || true +cp_check_and_sed '^START[[:space:]]*=[[:space:]]*no' \ + 's/^START[[:space:]]*=.*/START=yes/g' /etc/default/monit || true + +# remove us from systemv monit script +if grep -q 'CARNet package monit-cn' /etc/init.d/monit; then + echo "CN: Removing monit workaround from /etc/init.d/monit -- systemd is in use" + cp-update -r monit-cn /etc/init.d/monit + chmod +x /etc/init.d/monit +fi -# dh_installdeb will replace this with shell code automatically -# generated by other debhelper scripts. +service monit restart #DEBHELPER#