mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 13:41:15 -07:00
Attempt to verify the PID in an existing PID file before giving up.
If the PID doesn't map to a running process, then we can simply ignore the presence of the PID file and overwrite it with the current (new) PID later.
This commit is contained in:
parent
95ce293169
commit
465add46d4
1 changed files with 15 additions and 2 deletions
17
PlexPy.py
17
PlexPy.py
|
@ -122,8 +122,21 @@ def main():
|
||||||
# If the pidfile already exists, plexpy may still be running, so
|
# If the pidfile already exists, plexpy may still be running, so
|
||||||
# exit
|
# exit
|
||||||
if os.path.exists(plexpy.PIDFILE):
|
if os.path.exists(plexpy.PIDFILE):
|
||||||
raise SystemExit("PID file '%s' already exists. Exiting." %
|
try:
|
||||||
plexpy.PIDFILE)
|
with open(plexpy.PIDFILE, 'r') as fp:
|
||||||
|
pid = int(fp.read())
|
||||||
|
os.kill(pid, 0)
|
||||||
|
except IOError as e:
|
||||||
|
raise SystemExit("Unable to read PID file: %s", e)
|
||||||
|
except OSError:
|
||||||
|
logger.warn("PID file '%s' already exists, but PID %d is " \
|
||||||
|
"not running. Ignoring PID file." %
|
||||||
|
(plexpy.PIDFILE, pid))
|
||||||
|
else:
|
||||||
|
# The pidfile exists and points to a live PID. plexpy may
|
||||||
|
# still be running, so exit.
|
||||||
|
raise SystemExit("PID file '%s' already exists. Exiting." %
|
||||||
|
plexpy.PIDFILE)
|
||||||
|
|
||||||
# The pidfile is only useful in daemon mode, make sure we can write the
|
# The pidfile is only useful in daemon mode, make sure we can write the
|
||||||
# file properly
|
# file properly
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue