r1: [svn-inject] Installing original source of monit-cn
[monit-cn.git] / debian / postinst
1 #!/bin/sh
2 # postinst script for bind9-cn
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
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>
12 #          <new-version>
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
18 #
19
20 case "$1" in
21     configure|reconfigure)
22       # continue below
23     ;;
24
25     *)
26         exit 0
27     ;;
28 esac
29
30 # import CN-functions
31 . /usr/share/carnet-tools/functions.sh
32
33 # check if monitrc is an empty template
34 installfile=1
35 if [ -e /etc/monit/monitrc ]; then
36     lines=$(grep -v '^#' /etc/monit/monitrc | wc -l)
37     if [ $lines -lt 2 ]; then
38         installfile=1
39         mv -f /etc/monit/monitrc /etc/monit/monitrc.dpkg-old
40     else
41         installfile=0
42     fi
43 fi
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
48 fi
49
50 # generate monit.d files
51 update-monit.d
52
53 # disable monit startup
54 cp_check_and_sed '^startup=1/#startup=1/g' /etc/default/monit \
55     || true
56
57 # install as inittab service
58 if ! grep -q '/usr/sbin/monit' /etc/inittab; then
59     if [ -x "/etc/init.d/monit" ]; then
60         update-rc.d -f monit remove >/dev/null 2>&1
61         if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
62             invoke-rc.d monit stop || true
63         else
64             /etc/init.d/monit stop || true
65         fi
66     fi
67     echo "CN: Installing monit service in /etc/inittab"
68     rm -f /etc/inittab.$$
69     cp /etc/inittab /etc/inittab.$$
70     cp-update monit-cn /etc/inittab.$$ <<EOF
71 mo:2345:respawn:/usr/sbin/monit -Ic /etc/monit/monitrc
72 m0:06:wait:/usr/sbin/monit -Ic /etc/monit/monitrc stop myprocess
73 EOF
74     cp_mv /etc/inittab.$$ /etc/inittab
75 fi
76
77 # reload init, since we have new configuration
78 echo "CN: Starting monit service, please check /var/log/daemon.log"
79 kill -HUP 1
80
81 # dh_installdeb will replace this with shell code automatically
82 # generated by other debhelper scripts.
83
84 #DEBHELPER#
85
86 exit 0