From 5aab10fab2adcc158c9b25addaebf323a499f058 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Tue, 10 Jul 2018 03:28:02 +0200 Subject: [PATCH] Support client restart without updating --- src/Ui/UiWebsocket.py | 4 +++- src/main.py | 2 ++ zeronet.py | 27 ++++++++++++--------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Ui/UiWebsocket.py b/src/Ui/UiWebsocket.py index 097d336f6..3240b30f9 100644 --- a/src/Ui/UiWebsocket.py +++ b/src/Ui/UiWebsocket.py @@ -960,7 +960,9 @@ def actionServerPortcheck(self, to): res = sys.modules["main"].file_server.openport() self.response(to, res) - def actionServerShutdown(self, to): + def actionServerShutdown(self, to, restart=False): + if restart: + sys.modules["main"].restart_after_shutdown = True sys.modules["main"].file_server.stop() sys.modules["main"].ui_server.stop() diff --git a/src/main.py b/src/main.py index a424625e7..1c5f432fe 100644 --- a/src/main.py +++ b/src/main.py @@ -20,6 +20,7 @@ # Not thread: pyfilesystem and systray icon, Not subprocess: Gevent 1.1+ update_after_shutdown = False # If set True then update and restart zeronet after main loop ended +restart_after_shutdown = False # If set True then restart zeronet after main loop ended # Load config from Config import config @@ -175,6 +176,7 @@ def main(self): logging.info("Starting servers....") gevent.joinall([gevent.spawn(ui_server.start), gevent.spawn(file_server.start)]) + logging.info("All server stopped") # Site commands diff --git a/zeronet.py b/zeronet.py index 6aa4bf25c..f75c9e4d5 100755 --- a/zeronet.py +++ b/zeronet.py @@ -20,7 +20,6 @@ def main(): if main.update_after_shutdown: # Updater import gc import update - import atexit # Try cleanup openssl try: if "lib.opensslVerify" in sys.modules: @@ -42,16 +41,6 @@ def main(): except Exception, err: print "Update error: %s" % err - # Close log files - logger = sys.modules["main"].logging.getLogger() - - for handler in logger.handlers[:]: - handler.flush() - handler.close() - logger.removeHandler(handler) - - atexit._run_exitfuncs() - except Exception, err: # Prevent closing import traceback try: @@ -60,13 +49,21 @@ def main(): except Exception, log_err: print "Failed to log error:", log_err traceback.print_exc() - from src.Config import config + from Config import config traceback.print_exc(file=open(config.log_dir + "/error.log", "a")) - if main and main.update_after_shutdown: # Updater - # Restart - gc.collect() # Garbage collect + if main and (main.update_after_shutdown or main.restart_after_shutdown): # Updater + import atexit print "Restarting..." + # Close log files + logger = sys.modules["main"].logging.getLogger() + + for handler in logger.handlers[:]: + handler.flush() + handler.close() + logger.removeHandler(handler) + + atexit._run_exitfuncs() import time time.sleep(1) # Wait files to close args = sys.argv[:]