diff options
author | Csaba Henk <csaba@gluster.com> | 2011-02-14 16:42:05 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2011-02-14 14:32:03 -0800 |
commit | 30504941ea36ed40bbb628e8144ec2413e6fe765 (patch) | |
tree | 705d997e03764132973c3ac1f513d6301305b8bc /xlators | |
parent | 8c801cfd05eb533ae64ea9f06e49e632955cf0c0 (diff) |
syncdaemon: fix some pidfile issues
Signed-off-by: Csaba Henk <csaba@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1570 (geosync related changes)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1570
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/features/marker/utils/syncdaemon/gsyncd.py | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/gsyncd.py b/xlators/features/marker/utils/syncdaemon/gsyncd.py index fedf1fbdb0c..6655056489d 100644 --- a/xlators/features/marker/utils/syncdaemon/gsyncd.py +++ b/xlators/features/marker/utils/syncdaemon/gsyncd.py @@ -63,6 +63,17 @@ def startup(**kw): if fd: os.close(fd) + if getattr(gconf, 'pid_file', None) and kw.get('go_daemon') != 'postconn': + try: + write_pid(gconf.pid_file) + except OSError: + gconf.pid_file = None + ex = sys.exc_info()[1] + if ex.errno == EEXIST: + sys.stderr.write("pidfile is taken, exiting.\n") + exit(2) + raise + if kw.get('go_daemon') == 'should': x, y = os.pipe() gconf.cpid = os.fork() @@ -70,29 +81,19 @@ def startup(**kw): os.close(x) sys.exit() os.close(y) + os.setsid() + dn = os.open(os.devnull, os.O_RDWR) + for f in (sys.stdin, sys.stdout, sys.stderr): + os.dup2(dn, f.fileno()) + if getattr(gconf, 'pid_file', None): + write_pid(gconf.pid_file + '.tmp') + os.rename(gconf.pid_file + '.tmp', gconf.pid_file) # wait for parent to terminate # so we can start up with # no messing from the dirty # ol' bustard select.select((x,), (), ()) os.close(x) - if getattr(gconf, 'pid_file', None): - write_pid(gconf.pid_file + '.tmp') - os.rename(gconf.pid_file + '.tmp', gconf.pid_file) - os.setsid() - dn = os.open(os.devnull, os.O_RDWR) - for f in (sys.stdin, sys.stdout, sys.stderr): - os.dup2(dn, f.fileno()) - elif getattr(gconf, 'pid_file', None): - try: - write_pid(gconf.pid_file) - except OSError: - gconf.pid_file = None - ex = sys.exc_info()[1] - if ex.errno == EEXIST: - sys.stderr.write("pidfile is taken, exiting.\n") - exit(2) - raise lkw = {'level': gconf.log_level} if kw.get('log_file'): |