From 9827d989e4fc13c1c4f0e2629979c4c2614ba63f Mon Sep 17 00:00:00 2001 From: Brandon Rochon Date: Wed, 31 Oct 2018 17:02:04 -0700 Subject: [PATCH] Clean up stale pid. Fixes #122 Change-Id: Ic4603e53108471ba016ba478445fd533cfa93664 --- pdagent/thirdparty/daemon.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pdagent/thirdparty/daemon.py b/pdagent/thirdparty/daemon.py index a141e21a..e9ed0828 100644 --- a/pdagent/thirdparty/daemon.py +++ b/pdagent/thirdparty/daemon.py @@ -19,6 +19,7 @@ import atexit import os import sys +import psutil def daemonize( @@ -42,9 +43,11 @@ def daemonize( except (IOError, ValueError): pid = None - if pid: - message = "pidfile %s already exists. Is it already running?\n" + if (pid and psutil.pid_exists(pid)): + message = "pidfile %s already exists and the process is running!\n" raise SystemExit(message % pidfile) + if pid: + os.remove(pidfile) # Do first fork try: