X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=debian%2Fpostinst;h=0d324379537fa5653931cf5989c94f5110d08481;hb=ee0772bec2e346af5c73ee581300805779e84c8f;hp=e3879012b442df3dff3e85c8991d0b6ef0b1c005;hpb=c8e1f9a3251c3c43dd63e058de7924542c4d0d25;p=monit-cn.git diff --git a/debian/postinst b/debian/postinst index e387901..0d32437 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,36 +46,93 @@ 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 + +# 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 + +# migrate from old hierarchy +if [ -d /etc/monit.d ]; then + find /etc/monit.d -type f -print0 | xargs -0r -I% mv % /etc/monit/conf.d || true + rmdir /etc/monit.d >/dev/null 2>&1 || true +fi + +# (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 - -# 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 +# 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 +# # shebang +# head -n1 /etc/init.d/monit > /etc/init.d/monit.$$ +# # middle part +# cp-update monit-cn /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 +# +## if old inittab is referencing sbin, fix it +#if grep -q '/usr/sbin/monit' /etc/inittab; then +# cp_check_and_sed '/usr/sbin/monit' \ +# 's:/usr/sbin/monit:/usr/bin/monit:g' \ +# /etc/inittab || true +#fi +# +## install as inittab service +#if ! grep -q '/usr/bin/monit' /etc/inittab; then +# echo "CN: Installing monit service in /etc/inittab" +# cp -a /etc/inittab /etc/inittab.$$ +# cp-update monit-cn /etc/inittab.$$ <