mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Fix service restart
This commit is contained in:
parent
79e335f185
commit
25dbfd3a0e
2 changed files with 34 additions and 14 deletions
|
@ -128,6 +128,8 @@ class Service(xbmc.Monitor):
|
||||||
|
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
|
|
||||||
|
raise Exception("ExitService")
|
||||||
|
|
||||||
def start_default(self):
|
def start_default(self):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
46
service.py
46
service.py
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import threading
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
|
@ -40,6 +41,30 @@ DELAY = int(settings('startupDelay') or 0)
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceManager(threading.Thread):
|
||||||
|
|
||||||
|
''' Service thread.
|
||||||
|
To allow to restart and reload modules internally.
|
||||||
|
'''
|
||||||
|
exception = None
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
|
service = Service()
|
||||||
|
|
||||||
|
try:
|
||||||
|
service.service()
|
||||||
|
except Exception as error:
|
||||||
|
|
||||||
|
if not 'ExitService' in error:
|
||||||
|
service.shutdown()
|
||||||
|
|
||||||
|
self.exception = error
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
LOG.warn("-->[ service ]")
|
LOG.warn("-->[ service ]")
|
||||||
|
@ -48,28 +73,21 @@ if __name__ == "__main__":
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
session = Service()
|
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
|
||||||
|
raise Exception("Aborted during startup delay")
|
||||||
|
|
||||||
try:
|
session = ServiceManager()
|
||||||
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
|
session.start()
|
||||||
raise Exception("Aborted during startup delay")
|
session.join() # Block until the thread exits.
|
||||||
|
|
||||||
session.service()
|
if 'RestartService' in session.exception:
|
||||||
except Exception as error: # TODO, build exceptions
|
continue
|
||||||
|
|
||||||
LOG.exception(error)
|
|
||||||
session.shutdown()
|
|
||||||
|
|
||||||
if 'RestartService' in error:
|
|
||||||
continue
|
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
''' Issue initializing the service.
|
''' Issue initializing the service.
|
||||||
'''
|
'''
|
||||||
LOG.exception(error)
|
LOG.exception(error)
|
||||||
|
|
||||||
break
|
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
LOG.warn("--<[ service ]")
|
LOG.warn("--<[ service ]")
|
||||||
|
|
Loading…
Reference in a new issue