From 1cccd810ae6bb750f91dc0fcde7d7aedf91b802a Mon Sep 17 00:00:00 2001 From: morpheus65535 <5130500+morpheus65535@users.noreply.github.com> Date: Wed, 10 Oct 2018 07:15:06 -0400 Subject: [PATCH] Auto reload after restart --- bazarr.py | 23 ++++++++++------------- bazarr/main.py | 2 +- views/system.tpl | 19 +++++++++++++------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/bazarr.py b/bazarr.py index 48a822268..abe2f5c53 100644 --- a/bazarr.py +++ b/bazarr.py @@ -30,20 +30,17 @@ def start_bazarr(): script = [sys.executable, os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr/main.py'))] + globals()['arguments'] pidfile = os.path.normcase(os.path.join(os.path.dirname(__file__), 'bazarr.pid')) - if os.path.exists(pidfile): - logging.error("Bazarr already running, please stop it first.") + ep = sp.Popen(script, stdout=sp.PIPE, stderr=sp.STDOUT) + try: + file = open(pidfile,'w') + except: + logging.error("Error trying to write pid file.") else: - ep = sp.Popen(script, stdout=sp.PIPE, stderr=sp.STDOUT) - try: - file = open(pidfile,'w') - except: - logging.error("Error trying to write pid file.") - else: - file.write(str(ep.pid)) - file.close() - logging.info("Bazarr starting with process id: " + str(ep.pid) + "...") - for line in iter(ep.stdout.readline, ''): - sys.stdout.write(line) + file.write(str(ep.pid)) + file.close() + logging.info("Bazarr starting with process id: " + str(ep.pid) + "...") + for line in iter(ep.stdout.readline, ''): + sys.stdout.write(line) def shutdown_bazarr(restarting): diff --git a/bazarr/main.py b/bazarr/main.py index b5092214e..3c883f95c 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -1,4 +1,4 @@ -bazarr_version = '0.6.6' +bazarr_version = '0.6.7' import gc gc.enable() diff --git a/views/system.tpl b/views/system.tpl index d7904cf4d..bbc77c86d 100644 --- a/views/system.tpl +++ b/views/system.tpl @@ -208,7 +208,7 @@ window.location = '{{base_url}}execute/' + $(this).data("taskid"); }) - $('a:not(.tabs), button:not(.cancel, #download_log)').click(function(){ + $('a:not(.tabs), button:not(.cancel, #download_log), #restart').click(function(){ $('#loader').addClass('active'); }) @@ -217,7 +217,7 @@ url: "{{base_url}}shutdown", async: false }) - .fail(function(){ + .always(function(){ document.open(); document.write('Bazarr has shutdown.'); document.close(); @@ -227,12 +227,19 @@ $('#restart').click(function(){ $.ajax({ url: "{{base_url}}restart", - async: false + async: true }) .done(function(){ - document.open(); - document.write('Bazarr is restarting. Please reload page manually until it come back (should be less than 30 seconds).'); - document.close(); + setTimeout(function(){ setInterval(ping, 2000); },8000); }); }) + + function ping() { + $.ajax({ + url: window.location.href, + success: function(result) { + window.location.reload(); + } + }); + } \ No newline at end of file