Merge pull request #1076 from Vashypooh/master
Added support for windows service
This commit is contained in:
@@ -92,6 +92,8 @@ def main():
|
|||||||
'--nolaunch', action='store_true', help='Prevent browser from launching on startup')
|
'--nolaunch', action='store_true', help='Prevent browser from launching on startup')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--pidfile', help='Create a pid file (only relevant when running as a daemon)')
|
'--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.')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -116,6 +118,10 @@ def main():
|
|||||||
plexpy.DAEMON = True
|
plexpy.DAEMON = True
|
||||||
plexpy.QUIET = True
|
plexpy.QUIET = True
|
||||||
|
|
||||||
|
if args.windowsservice:
|
||||||
|
plexpy.WINDOWSSERVICE = True
|
||||||
|
logger.info("Running as windows service: %s", plexpy.WINDOWSSERVICE)
|
||||||
|
|
||||||
if args.pidfile:
|
if args.pidfile:
|
||||||
plexpy.PIDFILE = str(args.pidfile)
|
plexpy.PIDFILE = str(args.pidfile)
|
||||||
|
|
||||||
|
@@ -54,6 +54,7 @@ VERBOSE = True
|
|||||||
DAEMON = False
|
DAEMON = False
|
||||||
CREATEPID = False
|
CREATEPID = False
|
||||||
PIDFILE = None
|
PIDFILE = None
|
||||||
|
WINDOWSSERVICE = False
|
||||||
|
|
||||||
SCHED = BackgroundScheduler()
|
SCHED = BackgroundScheduler()
|
||||||
SCHED_LOCK = threading.Lock()
|
SCHED_LOCK = threading.Lock()
|
||||||
@@ -989,15 +990,17 @@ def shutdown(restart=False, update=False):
|
|||||||
args += ARGS
|
args += ARGS
|
||||||
if '--nolaunch' not in args:
|
if '--nolaunch' not in args:
|
||||||
args += ['--nolaunch']
|
args += ['--nolaunch']
|
||||||
logger.info('Restarting PlexPy with %s', args)
|
|
||||||
|
|
||||||
# os.execv fails with spaced names on Windows
|
# os.execv fails with spaced names on Windows
|
||||||
# https://bugs.python.org/issue19066
|
# https://bugs.python.org/issue19066
|
||||||
if os.name == 'nt':
|
if os.name == 'nt' and plexpy.WINDOWSSERVICE:
|
||||||
|
logger.info("Running as windows service, no need to fork.")
|
||||||
|
elif os.name == 'nt':
|
||||||
subprocess.Popen(args, cwd=os.getcwd())
|
subprocess.Popen(args, cwd=os.getcwd())
|
||||||
|
logger.info('Restarting PlexPy with %s', args)
|
||||||
else:
|
else:
|
||||||
os.execv(exe, args)
|
os.execv(exe, args)
|
||||||
|
logger.info('Restarting PlexPy with %s', args)
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user