X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=monit-cn.git;a=blobdiff_plain;f=debian%2Fpostinst;h=5b887c2d10742c68d526bff9c5773c0d85e63603;hp=e3879012b442df3dff3e85c8991d0b6ef0b1c005;hb=4021af87bb46b6ad7922e87d15e67561c41fd0d9;hpb=c8e1f9a3251c3c43dd63e058de7924542c4d0d25 diff --git a/debian/postinst b/debian/postinst index e387901..5b887c2 100755 --- a/debian/postinst +++ b/debian/postinst @@ -1,40 +1,17 @@ #!/bin/sh -# postinst script for bind9-cn -# -# see: dh_installdeb(1) set -e -# summary of how this script can be called: -# * `configure' -# * `abort-upgrade' -# * `abort-remove' `in-favour' -# -# * `abort-deconfigure' `in-favour' -# `removing' -# -# for details, see http://www.debian.org/doc/debian-policy/ or -# the debian-policy package -# +[ "$1" = "configure" ] || exit 0 +[ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx -case "$1" in - configure|reconfigure) - # continue below - ;; - - *) - exit 0 - ;; -esac - -# import CN-functions +# Load CARNet Tools . /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 +24,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#