zeronet.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. # Included modules
  3. import os
  4. import sys
  5. def main():
  6. print "- Starting ZeroNet..."
  7. main = None
  8. try:
  9. sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) # Imports relative to src
  10. import main
  11. main.start()
  12. if main.update_after_shutdown: # Updater
  13. import gc
  14. import update
  15. # Try cleanup openssl
  16. try:
  17. if "lib.opensslVerify" in sys.modules:
  18. sys.modules["lib.opensslVerify"].opensslVerify.closeLibrary()
  19. except Exception, err:
  20. print "Error closing openssl", err
  21. # Update
  22. update.update()
  23. # Close log files
  24. logger = sys.modules["main"].logging.getLogger()
  25. for handler in logger.handlers[:]:
  26. handler.flush()
  27. handler.close()
  28. logger.removeHandler(handler)
  29. except (Exception, ): # Prevent closing
  30. import traceback
  31. traceback.print_exc()
  32. traceback.print_exc(file=open("log/error.log", "a"))
  33. if main and main.update_after_shutdown: # Updater
  34. # Restart
  35. gc.collect() # Garbage collect
  36. print "Restarting..."
  37. args = sys.argv[:]
  38. args.insert(0, sys.executable)
  39. if sys.platform == 'win32':
  40. args = ['"%s"' % arg for arg in args]
  41. os.execv(sys.executable, args)
  42. print "Bye."
  43. if __name__ == '__main__':
  44. main()