Skip to content

Commit

Permalink
Support client restart without updating
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Jul 10, 2018
1 parent 77aa23a commit 5aab10f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/Ui/UiWebsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
27 changes: 12 additions & 15 deletions zeronet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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[:]
Expand Down

0 comments on commit 5aab10f

Please sign in to comment.