2 # postinst script for bind9-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 an empty template
35 if [ -e /etc/monit/monitrc ]; then
36 lines=$(grep -v '^#' /etc/monit/monitrc | wc -l)
37 if [ $lines -lt 2 ]; then
39 mv -f /etc/monit/monitrc /etc/monit/monitrc.dpkg-old
44 if [ $installfile -eq 1 ]; then
45 echo "CN: Installing default monitrc in /etc/monit/monitrc"
46 cp -a /usr/share/monit-cn/monitrc /etc/monit/monitrc
47 chmod u=rw,go= /etc/monit/monitrc
50 # sed monitrc with proper hostname
51 if grep -q '@localhost' /etc/monit/monitrc; then
52 CARNET_HOSTNAME=`hostname`
53 CARNET_DOMAINNAME=`hostname --domain`
54 cp_check_and_sed '@localhost' \
55 "s/@localhost/@$CARNET_HOSTNAME.$CARNET_DOMAINNAME/g" \
56 /etc/monit/monitrc || true
59 # if alert for "changed" is enabled, disable it ASAP
60 # we're waiting for "but not on { changed }" to enter in official
62 cp_check_and_sed '^set alert [^[:space:]]*@[^[:space:]]*$' \
63 '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' \
64 /etc/monit/monitrc || true
66 # (re)generate monit.d files
67 update-monit.d || true
69 # disable monit startup
70 cp_check_and_sed '^startup[[:space:]]*=[[:space:]]*1' \
71 '^startup[[:space:]]*=.*/startup=0/g' /etc/default/monit || true
74 echo "CN: Disabling monit SystemV script"
75 if [ -x "/etc/init.d/monit" ]; then
76 update-rc.d -f monit remove >/dev/null 2>&1
77 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
78 invoke-rc.d monit stop || true
80 /etc/init.d/monit stop || true
83 if [ -e "/etc/init.d/monit" ]; then
84 if ! grep -q 'CARNet package monit-cn' /etc/init.d/monit; then
86 head -n1 /etc/init.d/monit > /etc/init.d/monit.$$
88 cp-update monit-cn /etc/init.d/monit.$$ <<EOF
89 echo "CN: Monit SystemV init script disabled -- inittab is in use"
90 echo "CN: Exiting now..."
94 tail -n+2 /etc/init.d/monit >> /etc/init.d/monit.$$
95 mv -f /etc/init.d/monit.$$ /etc/init.d/monit
96 chmod +x /etc/init.d/monit
100 # install as inittab service
101 if ! grep -q '/usr/sbin/monit' /etc/inittab; then
102 echo "CN: Installing monit service in /etc/inittab"
103 rm -f /etc/inittab.$$
104 cp /etc/inittab /etc/inittab.$$
105 cp-update monit-cn /etc/inittab.$$ <<EOF
106 mo:2345:respawn:/usr/sbin/monit -Ic /etc/monit/monitrc
107 m0:06:wait:/usr/sbin/monit -Ic /etc/monit/monitrc stop myprocess
109 cp_mv /etc/inittab.$$ /etc/inittab
112 # reload init, since we have new configuration
113 echo "CN: (Re)starting monit service, please check /var/log/daemon.log"
114 pkill -9 -f /usr/sbin/monit || true
117 # dh_installdeb will replace this with shell code automatically
118 # generated by other debhelper scripts.