-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstorADEserver.py
executable file
·175 lines (102 loc) · 3.94 KB
/
storADEserver.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#:: Adeptio Dev team
#:: 2018-12-18
#:: adeptioStorade service core
#:: Alpha testing v1.0
import threading
import asyncore
import logging
import time
import sys
from config import *
from helper import *
from files import Files
from server import Server
from machine import Machine
from status_socket import StatusSocket
class ServerThread(threading.Thread):
def __init__(self, host, port, listen, prot):
threading.Thread.__init__(self)
self.server = Server(host, port, listen, prot)
def run(self):
asyncore.loop(LOOP_TIMEOUT)
def stop(self):
asyncore.close_all()
self.server.handle_close()
self.join()
class StatusThread(threading.Thread):
def __init__(self, host, port, interval):
threading.Thread.__init__(self)
self.interval = interval
self.server = StatusSocket(host, port)
self.event = threading.Event()
def run(self):
while not self.event.is_set():
self.server.send_status_info()
self.event.wait(self.interval)
def stop(self):
self.event.set()
self.server.close_socket()
self.join()
def StorADE_close():
logging.info("Trying to send error information")
stat_server = StatusSocket(ADEHOST, ADEPORT, False)
if stat_server.send_error():
logging.info("Error information sent successful")
else:
logging.info("Error information sent unsuccessful")
logging.info("StorADE closed")
logging.shutdown()
sys.exit()
if __name__ == "__main__":
Files = Files()
Machine = Machine()
check = {
"Can't create StorADE folder": Files.dir_check(Files.full_path()),
"Can't create SSL folder": Files.dir_check(Machine.ssl_path()),
"ImportError: No module named OpenSSL": import_check('OpenSSL'),
"Can't create clients list file": Machine.create_clients_list() > 1,
"Can't find working masternode": Machine.check_adeptio_mn_status(),
"Can't get masternodes list": Machine.check_adeptio_mn_list(),
"Can't get masternode ip": Machine.check_adeptio_mn_ip(),
"Can't find " + ADEPTIO_PATH + " file": Files._is_file(ADEPTIO_PATH)
}
logging.basicConfig(filename=Files.full_path(LOG_FILE), level=logging.DEBUG, format='%(asctime)s | %(levelname)s | %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
logging.getLogger().addHandler(logging.StreamHandler())
logging.info("StorADE started")
for error, exist in check.items():
if not exist:
logging.critical(error)
if False in check.values():
StorADE_close()
#Check if port is free
logging.info("Trying to create ssl files...")
from ssl_ import SSL_
if not SSL_().create_ssl_files():
logging.critical("Failure creating ssl files")
StorADE_close()
logging.info("SSL files created")
logging.info("Trying to start StatusThread...")
st = StatusThread(ADEHOST, ADESSLPORT, STATUS_INTERVAL)
st.start()
if not st.is_alive():
logging.critical("StatusThread starting error")
st.stop()
StorADE_close()
logging.info("StatusThread started")
logging.info("Trying to start ServerThread...")
if Machine.check_adeptio_mn_ip() == 'IPv6':
s = ServerThread(HOST_V6, PORT_V6, LISTEN, 'IPv6')
else:
s = ServerThread(HOST, PORT, LISTEN, 'IPv4')
s.start()
if not s.is_alive():
logging.critical("ServerThread starting error")
s.stop()
StorADE_close()
logging.info("ServerThread started")
if '--terminal' in sys.argv:
raw_input("Press any key to stop the server now...\n")
logging.info("Trying to stop...")
st.stop()
s.stop()
StorADE_close()