X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=update-monit.d;h=e5235e6cdd8318bfcdc6f14f2275d7d61c55a247;hb=2d8499aec085db578ddf5b422f21ff356ee66391;hp=72e55c522729d5274a6f1dbbb2f78ba7fc789104;hpb=c8e1f9a3251c3c43dd63e058de7924542c4d0d25;p=monit-cn.git diff --git a/update-monit.d b/update-monit.d index 72e55c5..e5235e6 100755 --- a/update-monit.d +++ b/update-monit.d @@ -1,4 +1,11 @@ #!/bin/sh +# +# Copyright (C) 2007 Dinko Korunic, CARNet, Grupa za izradu paketa +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. MONIT_DIR=/etc/monit.d TEMPLATES_DIR=/usr/share/monit-cn @@ -12,13 +19,26 @@ check_service() { return 1 fi - script='BEGIN { RS = "[ \t\n]+" } + scriptpid='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') + pidfiles=$(awk "$scriptpid" < "$filename" | sed -e 's/"//g') check_pidfile $pidfiles + + if [ $RET -eq 1 ]; then + return 1 + fi + + scriptinit='BEGIN { RS = "[ \t\n]+" } + { line[NR] = $0 "" } + END { for (j in line) + if (((line[j] == "start") || (line[j] == "stop")) && (line[j + 1] == "program") && (line[j + 2] == "=")) + print line[j + 3] }' + initscripts=$(awk "$scriptinit" < "$filename" | sed -e 's/"//g') + check_initscript $initscripts + return $RET } @@ -41,6 +61,20 @@ check_pidfile() { return 0 } +check_initscript() { + RET=0 + + while [ -n "$1" ]; do + if [ ! -x "$1" ]; then + RET=1 + return 1 + fi + shift + done + + return 0 +} + check_pid() { RET=0 @@ -55,27 +89,52 @@ check_pid() { return 0 } +##################################################################### +changed=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 +for i in $(find "$MONIT_DIR" -name '*.conf'); do check_service $i - if [ $RET -eq 0 ]; then + if [ ! $RET -eq 0 ]; then serviceconf=$(basename $i) - if [ ! -r "$MONIT_DIR"/$serviceconf ]; then - echo "CN: Enabled $serviceconf" - cp -a $i "$MONIT_DIR" + echo "CN: Disabled $serviceconf" + mv -f $i $i.disabled + changed=1 + fi +done + +for i in $(find "$TEMPLATES_DIR" -name '*.conf'); do + serviceconf=$(basename $i) + if [ -r "$MONIT_DIR"/$serviceconf.disabled ]; then + check_service "$MONIT_DIR"/$serviceconf.disabled + if [ $RET -eq 0 ]; then + if [ ! -r "$MONIT_DIR"/$serviceconf ]; then + echo "CN: Enabled $serviceconf (previously disabled)" + mv "$MONIT_DIR"/$serviceconf.disabled \ + "$MONIT_DIR"/$serviceconf + changed=1 + fi + fi + else + check_service $i + if [ $RET -eq 0 ]; then + if [ ! -r "$MONIT_DIR"/$serviceconf ]; then + echo "CN: Enabled $serviceconf (new service)" + cp -a $i "$MONIT_DIR" + changed=1 + fi fi fi done + +if [ $changed -eq 1 ]; then + echo "CN: Stopping/restarting monit service" + pkill -9 -f /usr/sbin/monit || true +else + echo "CN: No new services detected, sorry" +fi + +exit 0