diff options
author | Csaba Henk <csaba@lowlife.hu> | 2011-04-02 19:40:49 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2011-04-04 08:02:27 -0700 |
commit | 01b3dff29adee2041b0ef1b374eda8c88fb07678 (patch) | |
tree | c8f6c7eabb962c97f3e88add716eda429e2c3567 /xlators/features/marker/utils/syncdaemon/monitor.py | |
parent | e77c35248e8ce796bc5b108c10013089a0c65bde (diff) |
syncdaemon: add monitor mode to support autorestart
Signed-off-by: Csaba Henk <csaba@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 2537 (gsync autorestart)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2537
Diffstat (limited to 'xlators/features/marker/utils/syncdaemon/monitor.py')
-rw-r--r-- | xlators/features/marker/utils/syncdaemon/monitor.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/monitor.py b/xlators/features/marker/utils/syncdaemon/monitor.py new file mode 100644 index 00000000000..3f327b6d04d --- /dev/null +++ b/xlators/features/marker/utils/syncdaemon/monitor.py @@ -0,0 +1,54 @@ +import os +import sys +import time +import logging +from gconf import gconf +from syncdutils import update_file + +class Monitor(object): + + def __init__(self): + self.state = None + + def set_state(self, state): + if state == self.state: + return + self.state = state + logging.info('new state: %s' % state) + if getattr(gconf, 'state_file', None): + update_file(gconf.state_file, lambda f: f.write(state + '\n')) + + def monitor(self): + argv = sys.argv[:] + for o in ('-N', '--no-daemon', '--monitor'): + while o in argv: + argv.remove(o) + argv.extend(('-N', '-p', '')) + argv.insert(0, os.path.basename(sys.executable)) + + self.set_state('starting...') + ret = 0 + def nwait(p, o=0): + p2, r = os.waitpid(p, o) + if not p2: + return + if os.WIFEXITED(r): + return os.WEXITSTATUS(r) + return 1 + while ret in (0, 1): + logging.info('-' * 60) + logging.info('starting gsyncd worker') + cpid = os.spawnv(os.P_NOWAIT, sys.executable, argv) + time.sleep(60) + ret = nwait(cpid, os.WNOHANG) + if not ret: + self.set_state('OK') + ret = nwait(cpid) + elif ret in (0, 1): + self.set_state('faulty') + time.sleep(10) + self.set_state('inconsistent') + return ret + +def monitor(): + return Monitor().monitor() |