From 464fa1f8a32dbc09ec875aff9b35389dc262a2b3 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sun, 1 Oct 2017 11:08:40 -0700 Subject: [PATCH] Add no forking option to startup arguments --- PlexPy.py | 8 ++++---- plexpy/__init__.py | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/PlexPy.py b/PlexPy.py index 68ed8198..0648e15f 100755 --- a/PlexPy.py +++ b/PlexPy.py @@ -93,7 +93,7 @@ def main(): parser.add_argument( '--pidfile', help='Create a pid file (only relevant when running as a daemon)') parser.add_argument( - '--windowsservice', action='store_true', help='Running as a windows service.') + '--nofork', action='store_true', help='Start PlexPy as a service, do not fork when restarting') args = parser.parse_args() @@ -118,9 +118,9 @@ def main(): plexpy.DAEMON = True plexpy.QUIET = True - if args.windowsservice: - plexpy.WINDOWSSERVICE = True - logger.info("Running as windows service: %s", plexpy.WINDOWSSERVICE) + if args.nofork: + plexpy.NOFORK = True + logger.info("PlexPy is running as a service, it will not fork when restarted.") if args.pidfile: plexpy.PIDFILE = str(args.pidfile) diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 9dcf1609..79c82307 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -54,7 +54,7 @@ VERBOSE = True DAEMON = False CREATEPID = False PIDFILE = None -WINDOWSSERVICE = False +NOFORK = False SCHED = BackgroundScheduler() SCHED_LOCK = threading.Lock() @@ -993,14 +993,15 @@ def shutdown(restart=False, update=False): # os.execv fails with spaced names on Windows # https://bugs.python.org/issue19066 - if os.name == 'nt' and plexpy.WINDOWSSERVICE: - logger.info("Running as windows service, no need to fork.") + if NOFORK: + logger.info('Running as service, not forking. Exiting...') elif os.name == 'nt': + logger.info('Restarting PlexPy with %s', args) subprocess.Popen(args, cwd=os.getcwd()) - logger.info('Restarting PlexPy with %s', args) else: - os.execv(exe, args) logger.info('Restarting PlexPy with %s', args) + os.execv(exe, args) + os._exit(0)