|
29 | 29 | import os
|
30 | 30 | import subprocess
|
31 | 31 | import sys
|
32 |
| -from typing import Any, Dict, Set |
| 32 | +from typing import Any, Dict, Mapping, Set |
33 | 33 |
|
34 | 34 | import jinja2
|
35 | 35 | import yaml
|
@@ -341,7 +341,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
|
341 | 341 | # base shared worker jinja2 template.
|
342 | 342 | #
|
343 | 343 | # This config file will be passed to all workers, included Synapse's main process.
|
344 |
| - shared_config = {"listeners": listeners} |
| 344 | + shared_config: Dict[str, Any] = {"listeners": listeners} |
345 | 345 |
|
346 | 346 | # The supervisord config. The contents of which will be inserted into the
|
347 | 347 | # base supervisord jinja2 template.
|
@@ -446,21 +446,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
|
446 | 446 |
|
447 | 447 | # Write out the worker's logging config file
|
448 | 448 |
|
449 |
| - # Check whether we should write worker logs to disk, in addition to the console |
450 |
| - extra_log_template_args = {} |
451 |
| - if environ.get("SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK"): |
452 |
| - extra_log_template_args["LOG_FILE_PATH"] = "{dir}/logs/{name}.log".format( |
453 |
| - dir=data_dir, name=worker_name |
454 |
| - ) |
455 |
| - |
456 |
| - # Render and write the file |
457 |
| - log_config_filepath = "/conf/workers/{name}.log.config".format(name=worker_name) |
458 |
| - convert( |
459 |
| - "/conf/log.config", |
460 |
| - log_config_filepath, |
461 |
| - worker_name=worker_name, |
462 |
| - **extra_log_template_args, |
463 |
| - ) |
| 449 | + log_config_filepath = generate_worker_log_config(environ, worker_name, data_dir) |
464 | 450 |
|
465 | 451 | # Then a worker config file
|
466 | 452 | convert(
|
@@ -496,6 +482,10 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
|
496 | 482 |
|
497 | 483 | # Finally, we'll write out the config files.
|
498 | 484 |
|
| 485 | + # log config for the master process |
| 486 | + master_log_config = generate_worker_log_config(environ, "master", data_dir) |
| 487 | + shared_config["log_config"] = master_log_config |
| 488 | + |
499 | 489 | # Shared homeserver config
|
500 | 490 | convert(
|
501 | 491 | "/conf/shared.yaml.j2",
|
@@ -532,6 +522,30 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
|
532 | 522 | os.mkdir(log_dir)
|
533 | 523 |
|
534 | 524 |
|
| 525 | +def generate_worker_log_config( |
| 526 | + environ: Mapping[str, str], worker_name: str, data_dir: str |
| 527 | +) -> str: |
| 528 | + """Generate a log.config file for the given worker. |
| 529 | +
|
| 530 | + Returns: the path to the generated file |
| 531 | + """ |
| 532 | + # Check whether we should write worker logs to disk, in addition to the console |
| 533 | + extra_log_template_args = {} |
| 534 | + if environ.get("SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK"): |
| 535 | + extra_log_template_args["LOG_FILE_PATH"] = "{dir}/logs/{name}.log".format( |
| 536 | + dir=data_dir, name=worker_name |
| 537 | + ) |
| 538 | + # Render and write the file |
| 539 | + log_config_filepath = "/conf/workers/{name}.log.config".format(name=worker_name) |
| 540 | + convert( |
| 541 | + "/conf/log.config", |
| 542 | + log_config_filepath, |
| 543 | + worker_name=worker_name, |
| 544 | + **extra_log_template_args, |
| 545 | + ) |
| 546 | + return log_config_filepath |
| 547 | + |
| 548 | + |
535 | 549 | def start_supervisord():
|
536 | 550 | """Starts up supervisord which then starts and monitors all other necessary processes
|
537 | 551 |
|
|
0 commit comments