forked from HelloZeroNet/ZeroNet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
zeronet.py
executable file
·62 lines (52 loc) · 1.89 KB
/
zeronet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python2.7
# Included modules
import os
import sys
def main():
print "- Starting ZeroNet..."
main = None
try:
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src/lib")) # External liblary directory
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) # Imports relative to src
import main
main.start()
if main.update_after_shutdown: # Updater
import gc
import update
# Try cleanup openssl
try:
if "lib.opensslVerify" in sys.modules:
sys.modules["lib.opensslVerify"].opensslVerify.closeLibrary()
except Exception, err:
print "Error closing opensslVerify lib", err
try:
if "lib.pyelliptic" in sys.modules:
sys.modules["lib.pyelliptic"].openssl.closeLibrary()
except Exception, err:
print "Error closing pyelliptic lib", err
# Update
update.update()
# Close log files
logger = sys.modules["main"].logging.getLogger()
for handler in logger.handlers[:]:
handler.flush()
handler.close()
logger.removeHandler(handler)
except (Exception, ): # Prevent closing
import traceback
traceback.print_exc()
traceback.print_exc(file=open("log/error.log", "a"))
if main and main.update_after_shutdown: # Updater
# Restart
gc.collect() # Garbage collect
print "Restarting..."
import time
time.sleep(1) # Wait files to close
args = sys.argv[:]
args.insert(0, sys.executable)
if sys.platform == 'win32':
args = ['"%s"' % arg for arg in args]
os.execv(sys.executable, args)
print "Bye."
if __name__ == '__main__':
main()