]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Auto-restart
authorZack Cerza <zack@cerza.org>
Mon, 9 Dec 2013 20:56:49 +0000 (14:56 -0600)
committerZack Cerza <zack@cerza.org>
Mon, 9 Dec 2013 21:01:33 +0000 (15:01 -0600)
If /tmp/teuthology-restart-workers is newer than the running process,
restart.

Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/queue.py

index d2da9b477087dcb6ae29e9b70b4fc4a68ce917cc..c913aca517dc4aaa32b6079b32ca689b4e1f02dc 100644 (file)
@@ -7,21 +7,38 @@ import sys
 import tempfile
 import time
 import yaml
-
 import beanstalkc
 
+from datetime import datetime
+
 from . import report
 from . import safepath
 from .config import config as teuth_config
 from .misc import read_config
 
 log = logging.getLogger(__name__)
+start_time = datetime.utcnow()
+restart_file_path = '/tmp/teuthology-restart-workers'
 
-# simple flock class
 
+def need_restart():
+    if not os.path.exists(restart_file_path):
+        return False
+    if os.path.getmtime(restart_file_path) > start_time:
+        return True
+    else:
+        return False
 
-class filelock(object):
 
+def restart():
+    log.info('Restarting...')
+    args = sys.argv[:]
+    args.insert(0, sys.executable)
+    os.execv(sys.executable, args)
+
+
+class filelock(object):
+    # simple flock class
     def __init__(self, fn):
         self.fn = fn
         self.fd = None
@@ -127,6 +144,9 @@ def worker(ctx):
     beanstalk.ignore('default')
 
     while True:
+        if need_restart():
+            restart()
+
         job = beanstalk.reserve(timeout=60)
         if job is None:
             continue