5 minutes of retries to find cgroup dir, fix stop action in initscript
smbaker [Wed, 17 Oct 2012 01:06:50 +0000 (18:06 -0700)]
apps/gacks/gackswatcher-lxc.init
apps/gacks/gackswatcher.py

index 6960911..4535568 100644 (file)
@@ -26,7 +26,7 @@ start() {
 
 stop() {
         echo -n $"Stopping gacks watcher: "
-        /usr/sbin/chcontext --ctx 1 pkill -f "gackswatcher.py"
+        pkill -f "gackswatcher.py"
         echo
         return 0
 }
index c7bbad4..017ba3f 100644 (file)
@@ -27,14 +27,25 @@ import signal
 import sys
 import time
 
-if os.path.exists("/dev/cgroup"):
-    CGROUP_DIR="/dev/cgroup"
-elif os.path.exists("/sys/fs/cgroup/cpuset/libvirt/lxc"):
-    CGROUP_DIR="/sys/fs/cgroup/cpuset/libvirt/lxc"
-else:
-    print "I don't know where to find cgroup!"
-    sys.exit(-1)
-
+def get_cgroup_dir():
+    tries = 10
+    while True:
+        if os.path.exists("/dev/cgroup"):
+            return "/dev/cgroup"
+        elif os.path.exists("/sys/fs/cgroup/cpuset/libvirt/lxc"):
+            return "/sys/fs/cgroup/cpuset/libvirt/lxc"
+        else:
+            # cgroups seems to be missing right after boot on the LXC nodes.
+            print "I don't know where to find cgroup!"
+            if (tries > 0):
+                print "Trying again in 30 seconds"
+                time.sleep(30)
+                tries = tries - 1
+            else:
+                print "Giving up"
+                sys.exit(-1)
+
+CGROUP_DIR = get_cgroup_dir()
 
 PROC_DIR="/proc"
 WATCHER_DIR="/var/gacks/watcher/incoming"