summaryrefslogtreecommitdiff
path: root/scripts/scriptmgr.py
diff options
context:
space:
mode:
authorMarko Kreen2011-11-14 10:50:01 +0000
committerMarko Kreen2011-11-14 10:50:01 +0000
commit236972c7dfadcf7ebc654b0585dfd5df94e82e16 (patch)
tree52dcece0a0c5a8a787b772093a7e0fdae014abf6 /scripts/scriptmgr.py
parentb8ee8d708a54abd9ce7f707f3e027589642f4731 (diff)
parentbf55a2492267d6872bd66ac2b25a2e93b9e1d5b0 (diff)
Merge remote-tracking branch 'intgit/master'
Diffstat (limited to 'scripts/scriptmgr.py')
-rwxr-xr-xscripts/scriptmgr.py63
1 files changed, 42 insertions, 21 deletions
diff --git a/scripts/scriptmgr.py b/scripts/scriptmgr.py
index 0eef0529..26317036 100755
--- a/scripts/scriptmgr.py
+++ b/scripts/scriptmgr.py
@@ -78,6 +78,7 @@ class ScriptMgr(skytools.DBScript):
def init_optparse(self, p = None):
p = skytools.DBScript.init_optparse(self, p)
p.add_option("-a", "--all", action="store_true", help="apply command to all jobs")
+ p.add_option("-w", "--wait", action="store_true", help="wait for job(s) after signaling")
p.set_usage(command_usage.strip())
return p
@@ -170,18 +171,14 @@ class ScriptMgr(skytools.DBScript):
print(job)
def cmd_start(self, job_name):
- if job_name not in self.job_map:
- self.log.error('Unknown job: '+job_name)
- return 1
- job = self.job_map[job_name]
- if job['disabled']:
- self.log.info("Skipping %s" % job_name)
- return 0
+ job = self.get_job_by_name (job_name)
+ if isinstance (job, int):
+ return job # ret.code
self.log.info('Starting %s' % job_name)
os.chdir(job['cwd'])
pidfile = job['pidfile']
if not pidfile:
- self.log.warning("No pidfile for %s cannot launch")
+ self.log.warning("No pidfile for %s, cannot launch" % job_name)
return 0
if os.path.isfile(pidfile):
if skytools.signal_pidfile(pidfile, 0):
@@ -199,26 +196,42 @@ class ScriptMgr(skytools.DBScript):
return 0
def cmd_stop(self, job_name):
- if job_name not in self.job_map:
- self.log.error('Unknown job: '+job_name)
- return
- job = self.job_map[job_name]
- if job['disabled']:
- self.log.info("Skipping %s" % job_name)
- return
+ job = self.get_job_by_name (job_name)
+ if isinstance (job, int):
+ return job # ret.code
self.log.info('Stopping %s' % job_name)
self.signal_job(job, signal.SIGINT)
def cmd_reload(self, job_name):
+ job = self.get_job_by_name (job_name)
+ if isinstance (job, int):
+ return job # ret.code
+ self.log.info('Reloading %s' % job_name)
+ self.signal_job(job, signal.SIGHUP)
+
+ def get_job_by_name (self, job_name):
if job_name not in self.job_map:
- self.log.error('Unknown job: '+job_name)
- return
+ self.log.error ("Unknown job: %s" % job_name)
+ return 1
job = self.job_map[job_name]
if job['disabled']:
- self.log.info("Skipping %s" % job_name)
- return
- self.log.info('Reloading %s' % job_name)
- self.signal_job(job, signal.SIGHUP)
+ self.log.info ("Skipping %s" % job_name)
+ return 0
+ return job
+
+ def wait_for_stop (self, job_name):
+ job = self.get_job_by_name (job_name)
+ if isinstance (job, int):
+ return job # ret.code
+ msg = False
+ while True:
+ if skytools.signal_pidfile (job['pidfile'], 0):
+ if not msg:
+ self.log.info ("Waiting for %s to stop" % job_name)
+ msg = True
+ time.sleep (0.1)
+ else:
+ return 0
def signal_job(self, job, sig):
os.chdir(job['cwd'])
@@ -274,10 +287,18 @@ class ScriptMgr(skytools.DBScript):
elif cmd == "stop":
for n in jobs:
self.cmd_stop(n)
+ if self.options.wait:
+ for n in jobs:
+ self.wait_for_stop(n)
elif cmd == "restart":
for n in jobs:
self.cmd_stop(n)
+ if self.options.wait:
+ for n in jobs:
+ self.wait_for_stop(n)
+ else:
time.sleep(2)
+ for n in jobs:
self.cmd_start(n)
elif cmd == "reload":
for n in jobs: