2 # postinst script for monit-cn
4 # see: dh_installdeb(1)
8 # summary of how this script can be called:
9 # * <postinst> `configure' <most-recently-configured-version>
10 # * <old-postinst> `abort-upgrade' <new version>
11 # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
13 # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14 # <failed-install-package> <version> `removing'
15 # <conflicting-package> <version>
16 # for details, see http://www.debian.org/doc/debian-policy/ or
17 # the debian-policy package
21 configure|reconfigure)
31 . /usr/share/carnet-tools/functions.sh
33 # check if monitrc is ours
35 if [ -e /etc/monit/monitrc ]; then
36 if ! grep -q "CARNet package monit-cn" /etc/monit/monitrc; then
38 mv -f /etc/monit/monitrc /etc/monit/monitrc.dpkg-old
43 if [ $installfile -eq 1 ]; then
44 echo "CN: Installing default monitrc in /etc/monit/monitrc"
45 cp -a /usr/share/monit-cn/monitrc /etc/monit/monitrc
46 chmod u=rw,go= /etc/monit/monitrc
49 # sed monitrc with proper hostname
50 if grep -q '@localhost' /etc/monit/monitrc; then
51 CARNET_HOSTNAME=`hostname`
52 CARNET_DOMAINNAME=`hostname --domain`
53 cp_check_and_sed '@localhost' \
54 "s/@localhost/@$CARNET_HOSTNAME.$CARNET_DOMAINNAME/g" \
55 /etc/monit/monitrc || true
58 # migrate to "but not on { instance }" alerting style
59 cp_check_and_sed '^set alert [^[:space:]]*@[^[:space:]]* ' \
60 's/^set alert \([^[:space:]]*@[^[:space:]]*\) .*$/set alert \1 but not on { instance }/g' \
61 /etc/monit/monitrc || true
63 # migrate from old hierarchy
64 if [ -d /etc/monit.d ]; then
65 find /etc/monit.d -type f -print0 | xargs -0r -I% mv % /etc/monit/conf.d || true
66 rmdir /etc/monit.d >/dev/null 2>&1 || true
69 # (re)generate monit.d files
70 update-monit.d || true
72 # disable monit startup
73 cp_check_and_sed '^startup[[:space:]]*=[[:space:]]*0' \
74 's/^startup[[:space:]]*=.*/startup=1/g' /etc/default/monit || true
75 cp_check_and_sed '^START[[:space:]]*=[[:space:]]*no' \
76 's/^START[[:space:]]*=.*/START=yes/g' /etc/default/monit || true
78 # remove us from systemv monit script
79 if grep -q 'CARNet package monit-cn' /etc/init.d/monit; then
80 echo "CN: Removing monit workaround from /etc/init.d/monit -- systemd is in use"
81 cp-update -r monit-cn /etc/init.d/monit
82 chmod +x /etc/init.d/monit