summaryrefslogtreecommitdiffstats
path: root/sbin/init.d/monitor
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/init.d/monitor')
-rwxr-xr-xsbin/init.d/monitor46
1 files changed, 46 insertions, 0 deletions
diff --git a/sbin/init.d/monitor b/sbin/init.d/monitor
new file mode 100755
index 0000000..59cbb16
--- /dev/null
+++ b/sbin/init.d/monitor
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+. `dirname $0`/functions
+
+option default_check_interval standard_option 300
+option check_interval standard_option 60
+option facility standard_option
+option try_restart boolean_option
+option html standard_option
+option bin reserved_option /opt/exosec/bin/monitor
+option cmdline reserved_option \
+ '$bin -p $pidfile ${opt_html:+--html $opt_html} ${opt_facility:+--syslog $opt_facility} ${opt_try_restart:+--restart}'
+option pidfile reserved_option /var/run/monitor.pid
+
+function do_check {
+ local run_stat pid next_stat uptime
+
+ if [ $CONFIG -nt $pidfile ] ; then
+ status=CONFIG_CHANGED
+ else
+ status=OK
+ fi
+
+ if do_status $1 $2 > /dev/null ; then
+ run_stat=RUNNING
+ uptime=$[ $( date +%s ) - $( date -d "$( ps ho lstart $REPLY)" +%s ) ]
+
+ read pid < $pidfile
+ set -- $( ps ahxo ppid,pid,comm,lstart | \
+ awk '{if ($1 == '$pid' && $3 == "sleep") print $0 } ')
+ if [ $# == 0 ] ; then
+ status=$status,$opt_check_interval
+ else
+ pid=$2 ; shift 3 ; start=$( date -d "$*" +%s)
+ next_stat=$[ $opt_check_interval - $(date +%s) + $start ]
+ status=$status,$next_stat
+ fi
+ else
+ uptime=0
+ run_stat=STOPPED
+ fi
+
+ echo "$HOSTNAME $PNAME. $(date +%s) $run_stat $uptime $status"
+}
+
+load_config