@@ -64,6 +64,7 @@ class TeosDaemon:
64
64
config (:obj:`dict`): the configuration object.
65
65
sk (:obj:`PrivateKey`): the :obj:`PrivateKey` of the tower.
66
66
logger (:obj:`Logger <teos.logger.Logger>`): the logger instance.
67
+ logging_port (:obj:`int`): the port where the logging server can be reached (localhost:logging_port)
67
68
68
69
Attributes:
69
70
stop_command_event (:obj:`threading.Event`): The event that will be set to initiate a graceful shutdown.
@@ -85,9 +86,10 @@ class TeosDaemon:
85
86
rpc_process (:obj:`multiprocessing.Process`): The instance of the internal RPC server; only set if running.
86
87
"""
87
88
88
- def __init__ (self , config , sk , logger ):
89
+ def __init__ (self , config , sk , logger , logging_port ):
89
90
self .config = config
90
91
self .logger = logger
92
+ self .logging_port = logging_port
91
93
92
94
# event triggered when a ``stop`` command is issued
93
95
# Using multiprocessing.Event seems to cause a deadlock if event.set() is called in a signal handler that
@@ -153,6 +155,7 @@ def __init__(self, config, sk, logger):
153
155
self .config .get ("RPC_BIND" ),
154
156
self .config .get ("RPC_PORT" ),
155
157
self .internal_api_endpoint ,
158
+ self .logging_port ,
156
159
self .stop_event ,
157
160
),
158
161
daemon = True ,
@@ -238,8 +241,14 @@ def bootstrap_components(self):
238
241
# Activate ChainMonitor
239
242
self .chain_monitor .activate ()
240
243
241
- def start_services (self ):
242
- """Readies the tower by setting up signal handling, and starting all the services."""
244
+ def start_services (self , logging_port ):
245
+ """
246
+ Readies the tower by setting up signal handling, and starting all the services.
247
+
248
+ Args:
249
+ logging_port (:obj:`int`): the port where the logging server can be reached (localhost:logging_port)
250
+ """
251
+
243
252
signal (SIGINT , self .handle_signals )
244
253
signal (SIGTERM , self .handle_signals )
245
254
signal (SIGQUIT , self .handle_signals )
@@ -262,7 +271,8 @@ def start_services(self):
262
271
"gunicorn" ,
263
272
f"--bind={ api_endpoint } " ,
264
273
f"teos.api:serve(internal_api_endpoint='{ self .internal_api_endpoint } ', "
265
- f"endpoint='{ api_endpoint } ', min_to_self_delay='{ self .config .get ('MIN_TO_SELF_DELAY' )} ')" ,
274
+ f"endpoint='{ api_endpoint } ', logging_port='{ logging_port } ', "
275
+ f"min_to_self_delay='{ self .config .get ('MIN_TO_SELF_DELAY' )} ')" ,
266
276
]
267
277
)
268
278
else :
@@ -271,6 +281,7 @@ def start_services(self):
271
281
kwargs = {
272
282
"internal_api_endpoint" : self .internal_api_endpoint ,
273
283
"endpoint" : api_endpoint ,
284
+ "logging_port" : logging_port ,
274
285
"min_to_self_delay" : self .config .get ("MIN_TO_SELF_DELAY" ),
275
286
"auto_run" : True ,
276
287
},
@@ -326,7 +337,7 @@ def start(self):
326
337
"""This method implements the whole lifetime cycle of the the TEOS tower. This method does not return."""
327
338
self .logger .info ("Starting TEOS" )
328
339
self .bootstrap_components ()
329
- self .start_services ()
340
+ self .start_services (self . logging_port )
330
341
331
342
self .stop_command_event .wait ()
332
343
@@ -338,14 +349,15 @@ def main(config):
338
349
339
350
silent = config .get ("DAEMON" )
340
351
logging_server_ready = multiprocessing .Event ()
352
+ logging_port = multiprocessing .Value ("i" )
341
353
logging_process = multiprocessing .Process (
342
- target = serve_logging , daemon = True , args = (config .get ("LOG_FILE" ), silent , logging_server_ready )
354
+ target = serve_logging , daemon = True , args = (config .get ("LOG_FILE" ), logging_port , silent , logging_server_ready )
343
355
)
344
356
logging_process .start ()
345
357
346
358
logging_server_ready .wait ()
347
359
348
- setup_logging ()
360
+ setup_logging (logging_port . value )
349
361
logger = get_logger (component = "Daemon" )
350
362
351
363
if not os .path .exists (config .get ("TEOS_SECRET_KEY" )) or config .get ("OVERWRITE_KEY" ):
@@ -366,7 +378,7 @@ def main(config):
366
378
logger .warning ("Windows cannot run gunicorn as WSGI. Changing to waitress" )
367
379
368
380
try :
369
- TeosDaemon (config , sk , logger ).start ()
381
+ TeosDaemon (config , sk , logger , logging_port . value ).start ()
370
382
except Exception as e :
371
383
logger .error ("An error occurred: {}. Shutting down" .format (e ))
372
384
exit (1 )
0 commit comments