--- /dev/null
+monit-cn
+~~~~~~~~
+
+Ovaj paket donosi primjere konfiguracije za monit, instalaciju u inittab,
+kao i skriptu za detekciju aktivnih i radecih servisa koji se mogu pratiti
+kroz monit.
+
+ -- Dinko Korunic <kreator@carnet.hr> at Mon, 24 Sep 2007 18:51:14 +0200
--- /dev/null
+monit-cn (1:4.5-1) stable; urgency=low
+
+ * inicijalni paket sa skriptama za detekciju aktivnih servisa i generiranje
+ monit.conf, itd.
+
+ -- Dinko Korunic <kreator@carnet.hr> Mon, 24 Sep 2007 18:34:20 +0200
--- /dev/null
+monit-cn (1:4.5-1) stable; urgency=low
+
+ * inicijalni paket sa skriptama za detekciju aktivnih servisa i generiranje
+ monit.conf, itd.
+
+ -- Dinko Korunic <kreator@carnet.hr> Mon, 24 Sep 2007 18:34:20 +0200
--- /dev/null
+Source: monit-cn
+Section: net
+Priority: optional
+Maintainer: Dinko Korunic <kreator@carnet.hr>
+Build-Depends: debhelper (>= 4)
+Standards-Version: 3.7.2
+
+Package: monit-cn
+Architecture: all
+Depends: monit (>= 1:4.5-1), carnet-tools-cn (>= 2.1.8)
+Description: A utility for monitoring and managing daemons or similar programs
+ monit is a utility for monitoring and managing daemons or similar
+ programs running on a Unix system. It will start specified programs
+ if they are not running and restart programs not responding.
+ .
+ monit supports:
+ * Daemon mode - poll programs at a specified interval
+ * Monitoring modes - active, passive or manual
+ * Start, stop and restart of programs
+ * Group and manage groups of programs
+ * Process dependency definition
+ * Logging to syslog or own logfile
+ * Configuration - comprehensive controlfile
+ * Runtime and TCP/IP port checking (tcp and udp)
+ * SSL support for port checking
+ * Unix domain socket checking
+ * Process status and process timeout
+ * Process cpu usage
+ * Process memory usage
+ * Process zombie check
+ * Check the systems load average
+ * Check a file or directory timestamp
+ * Alert, stop or restart a process based on its characteristics
+ * MD5 checksum for programs started and stopped by monit
+ * Alert notification for program timeout, restart, checksum, stop
+ resource and timestamp error
+ * Flexible and customizable email alert messages
+ * Protocol verification. HTTP, FTP, SMTP, POP, IMAP, NNTP, SSH, DWP,
+ LDAPv2 and LDAPv3
+ * An http interface with optional SSL support to make monit
+ accessible from a webbrowser
+ .
+ This is the CARNet Debian customization package which brings
+ update-monit.d script (which will hopefully generate configuration based
+ on currently installed and running services which can be monitored with
+ monit), as well as automagical instalation as respawnable process in
+ inittab.
--- /dev/null
+/etc/monit.d
+/usr/share/monit-cn
+/etc/monit
--- /dev/null
+changelog.CARNet
+README.CARNet
--- /dev/null
+monit-cn /usr/share
+update-monit.d /usr/sbin
--- /dev/null
+#!/bin/sh
+# postinst script for bind9-cn
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+# * <postinst> `configure' <most-recently-configured-version>
+# * <old-postinst> `abort-upgrade' <new version>
+# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+# <new-version>
+# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+# <failed-install-package> <version> `removing'
+# <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+#
+
+case "$1" in
+ configure|reconfigure)
+ # continue below
+ ;;
+
+ *)
+ exit 0
+ ;;
+esac
+
+# import CN-functions
+. /usr/share/carnet-tools/functions.sh
+
+# check if monitrc is an empty template
+installfile=1
+if [ -e /etc/monit/monitrc ]; then
+ lines=$(grep -v '^#' /etc/monit/monitrc | wc -l)
+ if [ $lines -lt 2 ]; then
+ installfile=1
+ mv -f /etc/monit/monitrc /etc/monit/monitrc.dpkg-old
+ else
+ installfile=0
+ fi
+fi
+if [ $installfile -eq 1 ]; then
+ echo "CN: Installing default monitrc in /etc/monit/monitrc"
+ cp -a /usr/share/monit-cn/monitrc /etc/monit/monitrc
+ chmod u=rw,go= /etc/monit/monitrc
+fi
+
+# generate monit.d files
+update-monit.d
+
+# 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.$$ <<EOF
+mo:2345:respawn:/usr/sbin/monit -Ic /etc/monit/monitrc
+m0:06:wait:/usr/sbin/monit -Ic /etc/monit/monitrc stop myprocess
+EOF
+ cp_mv /etc/inittab.$$ /etc/inittab
+fi
+
+# reload init, since we have new configuration
+echo "CN: Starting monit service, please check /var/log/daemon.log"
+kill -HUP 1
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
--- /dev/null
+#!/bin/sh
+# postrm script for bind9-cn
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+# * <postrm> `remove'
+# * <postrm> `purge'
+# * <old-postrm> `upgrade' <new-version>
+# * <new-postrm> `failed-upgrade' <old-version>
+# * <new-postrm> `abort-install'
+# * <new-postrm> `abort-install' <old-version>
+# * <new-postrm> `abort-upgrade' <old-version>
+# * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+case "$1" in
+ purge)
+ # continue below
+ ;;
+
+ *)
+ exit 0
+ ;;
+esac
+
+# import CN-functions
+. /usr/share/carnet-tools/functions.sh
+
+# remove us from inittab
+echo "CN: Removing monit service from /etc/inittab"
+cp-update -r monit-cn /etc/inittab
+
+# kill monit
+echo "CN: Stopping monit service"
+pkill -9 -f /usr/sbin/monit
+
+# reload init
+kill -HUP 1
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
--- /dev/null
+#!/usr/bin/make -f
+# Sample debian/rules that uses debhelper.
+# This file is public domain software, originally written by Joey Hess.
+#
+# This version is for packages that are architecture independent.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+build: build-stamp
+build-stamp:
+ dh_testdir
+
+ # Add here commands to compile the package.
+ #$(MAKE)
+
+ touch build-stamp
+
+clean:
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp
+
+ # Add here commands to clean up after the build process.
+ #-$(MAKE) clean
+ #-$(MAKE) distclean
+
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+
+ # Add here commands to install the package into debian/<packagename>.
+ #$(MAKE) prefix=`pwd`/debian/`dh_listpackages`/usr install
+
+# Build architecture-independent files here.
+binary-indep: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_install
+# dh_installexamples
+# dh_installmenu
+# dh_installdebconf
+# dh_installlogrotate
+# dh_installemacsen
+# dh_installcatalogs
+# dh_installpam
+# dh_installmime
+# dh_installinit
+# dh_installcron
+# dh_installinfo
+# dh_undocumented
+ dh_installman
+ dh_link
+ dh_compress
+ dh_fixperms
+# dh_perl
+# dh_python
+ dh_installdeb
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+# Build architecture-dependent files here.
+binary-arch: build install
+# We have nothing to do by default.
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install
--- /dev/null
+# amavisd monit-cn template
+
+check process amavisd with pidfile "/var/run/amavis/amavisd.pid"
+ group mail
+ start program = "/etc/init.d/amavis start"
+ stop program = "/etc/init.d/amavis stop"
+ if failed host 127.0.0.1 port 10024 protocol smtp
+ then restart
--- /dev/null
+# apache2 monit-cn template
+
+check process apache2 with pidfile "/var/run/apache2.pid"
+ start program = "/etc/init.d/apache2 start"
+ stop program = "/etc/init.d/apache2 stop"
+ if failed host 127.0.0.1 port 80 protocol http
+ with timeout 15 seconds
+ then restart
+ if children > 250 then restart
--- /dev/null
+# bind9 monit-cn template
+
+check process bind with pidfile "/var/run/bind/run/named.pid"
+ start program = "/etc/init.d/bind9 start"
+ stop program = "/etc/init.d/bind9 stop"
+ if failed host 127.0.0.1 port 53 type tcp
+ then restart
+ if failed host 127.0.0.1 port 53 type udp
+ then restart
--- /dev/null
+# clamd monit-cn template
+
+check process clamd with pidfile "/var/run/clamav/clamd.pid"
+ group mail
+ start program = "/etc/init.d/clamav-daemon start"
+ stop program = "/etc/init.d/clamav-daemon stop"
+ if failed unixsocket "/var/run/clamav/clamd.ctl"
+ then restart
--- /dev/null
+# dhcpd monit-cn template
+
+check process dhcpd with pidfile "/var/run/dhcpd.pid"
+ start program = "/etc/init.d/dhcp3-server start"
+ stop program = "/etc/init.d/dhcp3-server stop"
--- /dev/null
+# dovecot monit-cn template
+
+check process dovecot with pidfile "/var/run/dovecot/master.pid"
+ group mail
+ start program = "/etc/init.d/dovecot start"
+ stop program = "/etc/init.d/dovecot stop"
+ if failed host 127.0.0.1 port 143 protocol imap
+ then restart
+ if failed host 127.0.0.1 port 110 type tcp
+ then restart
--- /dev/null
+# monit-cn template
+
+set daemon 300
+set logfile syslog facility log_daemon
+
+set mail-format {
+ from: monit@localhost
+ subject: $SERVICE $EVENT at $DATE
+ message: monit $ACTION $SERVICE at $DATE on $HOST
+ }
+set mailserver 127.0.0.1
+set alert root@localhost
+
+#set httpd port 2812 and use address 127.0.0.1
+#allow localhost
+#allow admin:monit
+
+include /etc/monit.d/*conf
--- /dev/null
+# mysql monit-cn template
+
+check process mysql with pidfile "/var/run/mysqld/mysqld.pid"
+ start program = "/etc/init.d/mysql start"
+ stop program = "/etc/init.d/mysql stop"
+ if failed host 127.0.0.1 port 3306 protocol mysql
+ with timeout 10 seconds
+ then restart
--- /dev/null
+# openldap monit-cn template
+
+check process openldap with pidfile "/var/run/slapd/slapd.pid"
+ start program = "/etc/init.d/slapd start"
+ stop program = "/etc/init.d/slapd stop"
+ if failed host 127.0.0.1 port 389 protocol ldap3
+ with timeout 10 seconds
+ then restart
+ if 5 restarts within 5 cycles then timeout
--- /dev/null
+# postfix monit-cn template
+
+check process postfix with pidfile "/var/spool/postfix/pid/master.pid"
+ group mail
+ start program = "/etc/init.d/postfix start"
+ stop program = "/etc/init.d/postfix stop"
+ if failed host 127.0.0.1 port 25 protocol smtp
+ then restart
--- /dev/null
+# sophie monit-cn template
+
+check process sophie with pidfile "/var/run/sophie/pid"
+ group mail
+ start program = "/etc/init.d/sophie start"
+ stop program = "/etc/init.d/sophie stop"
+ if failed unixsocket "/var/run/sophie/sock"
+ then restart
--- /dev/null
+# thttpd monit-cn template
+
+check process thttpd with pidfile "/var/run/thttpd.pid"
+ start program = "/etc/init.d/thttpd start"
+ stop program = "/etc/init.d/thttpd stop"
+ if failed host 127.0.0.1 port 80
+ with timeout 15 seconds
+ then restart
+ if children > 100 then restart
--- /dev/null
+# tomcat5 monit-cn template
+
+check process tomcat5 with pidfile "/usr/share/tomcat5/temp/tomcat5.pid"
+ start program = "/etc/init.d/tomcat5 start"
+ stop program = "/etc/init.d/tomcat5 stop"
+ if failed host 127.0.0.1 port 8081 protocol http
+ with timeout 15 seconds
+ then restart
+ if children > 250 then restart
+
--- /dev/null
+#!/bin/sh
+
+MONIT_DIR=/etc/monit.d
+TEMPLATES_DIR=/usr/share/monit-cn
+
+check_service() {
+ RET=0
+
+ filename="$1"
+ if [ ! -r "$filename" ]; then
+ RET=1
+ return 1
+ fi
+
+ script='BEGIN { RS = "[ \t\n]+" }
+ { line[NR] = $0 "" }
+ END { for (j in line)
+ if (line[j] == "pidfile")
+ print line[j + 1] }'
+ pidfiles=$(awk "$script" < "$filename" | sed -e 's/"//g')
+ check_pidfile $pidfiles
+ return $RET
+}
+
+check_pidfile() {
+ RET=0
+
+ while [ -n "$1" ]; do
+ if [ -r "$1" ]; then
+ check_pid $(cat "$1")
+ if [ $RET -eq 1 ]; then
+ return 1
+ fi
+ else
+ RET=1
+ return 1
+ fi
+ shift
+ done
+
+ return 0
+}
+
+check_pid() {
+ RET=0
+
+ while [ -n "$1" ]; do
+ if ! kill -0 "$1" >/dev/null 2>&1; then
+ RET=1
+ return 1
+ fi
+ shift
+ done
+
+ return 0
+}
+
+
+if [ ! -d "$MONIT_DIR" ]; then
+ mkdir -p "$MONIT_DIR"
+else
+ for i in $(find "$MONIT_DIR" -name '*.conf'); do
+ check_service $i
+ if [ ! $RET -eq 0 ]; then
+ serviceconf=$(basename $i)
+ echo "CN: Disabled $serviceconf"
+ mv -f $i $i.disabled
+ fi
+ done
+fi
+
+for i in $(find "$TEMPLATES_DIR" -name '*.conf'); do
+ check_service $i
+ if [ $RET -eq 0 ]; then
+ serviceconf=$(basename $i)
+ if [ ! -r "$MONIT_DIR"/$serviceconf ]; then
+ echo "CN: Enabled $serviceconf"
+ cp -a $i "$MONIT_DIR"
+ fi
+ fi
+done