r8: - be able to reenable disabled services, too
authorDinko Korunic <Dinko.Korunic@CARNet.hr>
Wed, 10 Oct 2007 15:00:20 +0000 (15:00 +0000)
committerDinko Korunic <Dinko.Korunic@CARNet.hr>
Wed, 10 Oct 2007 15:00:20 +0000 (15:00 +0000)
update-monit.d

index 789efff..4ed19e1 100755 (executable)
@@ -60,26 +60,38 @@ check_pid() {
 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
-            changed=1
-        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"
-            changed=1
+        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