Support client restart without updating
This commit is contained in:
parent
77aa23a375
commit
5aab10fab2
3 changed files with 17 additions and 16 deletions
|
@ -960,7 +960,9 @@ class UiWebsocket(object):
|
||||||
res = sys.modules["main"].file_server.openport()
|
res = sys.modules["main"].file_server.openport()
|
||||||
self.response(to, res)
|
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"].file_server.stop()
|
||||||
sys.modules["main"].ui_server.stop()
|
sys.modules["main"].ui_server.stop()
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ else: # Old gevent
|
||||||
# Not thread: pyfilesystem and systray icon, Not subprocess: Gevent 1.1+
|
# 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
|
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
|
# Load config
|
||||||
from Config import config
|
from Config import config
|
||||||
|
@ -175,6 +176,7 @@ class Actions(object):
|
||||||
|
|
||||||
logging.info("Starting servers....")
|
logging.info("Starting servers....")
|
||||||
gevent.joinall([gevent.spawn(ui_server.start), gevent.spawn(file_server.start)])
|
gevent.joinall([gevent.spawn(ui_server.start), gevent.spawn(file_server.start)])
|
||||||
|
logging.info("All server stopped")
|
||||||
|
|
||||||
# Site commands
|
# Site commands
|
||||||
|
|
||||||
|
|
27
zeronet.py
27
zeronet.py
|
@ -20,7 +20,6 @@ def main():
|
||||||
if main.update_after_shutdown: # Updater
|
if main.update_after_shutdown: # Updater
|
||||||
import gc
|
import gc
|
||||||
import update
|
import update
|
||||||
import atexit
|
|
||||||
# Try cleanup openssl
|
# Try cleanup openssl
|
||||||
try:
|
try:
|
||||||
if "lib.opensslVerify" in sys.modules:
|
if "lib.opensslVerify" in sys.modules:
|
||||||
|
@ -42,16 +41,6 @@ def main():
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
print "Update error: %s" % 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
|
except Exception, err: # Prevent closing
|
||||||
import traceback
|
import traceback
|
||||||
try:
|
try:
|
||||||
|
@ -60,13 +49,21 @@ def main():
|
||||||
except Exception, log_err:
|
except Exception, log_err:
|
||||||
print "Failed to log error:", log_err
|
print "Failed to log error:", log_err
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
from src.Config import config
|
from Config import config
|
||||||
traceback.print_exc(file=open(config.log_dir + "/error.log", "a"))
|
traceback.print_exc(file=open(config.log_dir + "/error.log", "a"))
|
||||||
|
|
||||||
if main and main.update_after_shutdown: # Updater
|
if main and (main.update_after_shutdown or main.restart_after_shutdown): # Updater
|
||||||
# Restart
|
import atexit
|
||||||
gc.collect() # Garbage collect
|
|
||||||
print "Restarting..."
|
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
|
import time
|
||||||
time.sleep(1) # Wait files to close
|
time.sleep(1) # Wait files to close
|
||||||
args = sys.argv[:]
|
args = sys.argv[:]
|
||||||
|
|
Loading…
Reference in a new issue