Skip to content

Commit

Permalink
Add basic stale pid detection heuristic
Browse files Browse the repository at this point in the history
While any normal crashes should already remove the pid file
if one was created mumo can still be killed in ways which
make it unable to clean up after itself. This patch adds
a basic heuristic which checks if the pid mentioned in the
pid file belongs to a running process. If so we assume this
is actually mumo and terminate. If not we assume mumo isn't
running and break the lock. This approach is not 100% reliable
and it break the acquire timeout properties we had before
but should do the trick.
  • Loading branch information
hacst committed Jun 24, 2015
1 parent b0b2c1b commit 5680d80
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mumo.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,15 @@ def error(self, message):
ret = do_main_program()
else:
pidfile = daemon.pidlockfile.TimeoutPIDLockFile(cfg.system.pidfile, 5)
if pidfile.is_locked():
try:
os.kill(pidfile.read_pid(), 0)
print >> sys.stderr, 'Mumo already running as %s' % pidfile.read_pid()
sys.exit(1)
except OSError:
print >> sys.stderr, 'Found stale mumo pid file but no process, breaking lock'
pidfile.break_lock()

context = daemon.DaemonContext(working_directory=sys.path[0],
stderr=logfile,
pidfile=pidfile)
Expand Down

0 comments on commit 5680d80

Please sign in to comment.