Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Allow non-interactive config generation from dpkg config snippets #13669

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion debian/matrix-synapse.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description=Synapse Matrix homeserver
Type=notify
User=matrix-synapse
WorkingDirectory=/var/lib/matrix-synapse
ExecStartPre=/opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/ --generate-keys
ExecStartPre=/opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d --generate-config
ExecStart=/opt/venvs/matrix-synapse/bin/python -m synapse.app.homeserver --config-path=/etc/matrix-synapse/homeserver.yaml --config-path=/etc/matrix-synapse/conf.d/
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
Expand Down
45 changes: 34 additions & 11 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import argparse
import errno
import itertools
import logging
import os
import re
Expand Down Expand Up @@ -413,6 +414,14 @@ def invoke_all_static(cls, func_name: str, *args: Any, **kwargs: any) -> None:
if hasattr(config, func_name):
getattr(config, func_name)(*args, **kwargs)

@staticmethod
def pop_config_by_name(config_files: List[str], name: str) -> Optional[str]:
for idx, path in enumerate(config_files):
if os.path.basename(path) == name:
return config_files.pop(idx)

return None

def generate_config(
self,
config_dir_path: str,
Expand Down Expand Up @@ -704,12 +713,33 @@ def load_or_generate_config(
== _ConfigGenerateMode.GENERATE_EVERYTHING_AND_EXIT
):
if config_args.report_stats is None:
parser.error(
"Please specify either --report-stats=yes or --report-stats=no\n\n"
+ MISSING_REPORT_STATS_SPIEL
report_stats_file = cls.pop_config_by_name(
config_files, "report_stats.yaml"
)
if report_stats_file:
with open(report_stats_file) as f:
config_args.report_stats = yaml.safe_load(f)["report_stats"]
else:
parser.error(
"Please specify either --report-stats=yes or --report-stats=no\n\n"
+ MISSING_REPORT_STATS_SPIEL
)
Comment on lines +716 to +726
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting aside for now the fact that we're hardcoding some very debian-package-specific magic into the main code here:

It's worth noting that, at present, you can dpkg-reconfigure matrix-synapse-py3 and change the report_stats setting. That will be written back to /etc/matrix-synapse/conf.d/report_stats.yaml so that it is picked up by synapse on the next restart.

It looks to me as if this change will put the report_stats setting into /etc/matrix-synapse/homeserver.yaml on first run, where it will never be changed thereafter - so users can no longer dpkg-reconfigure this setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, I'll think about how to address this.


(config_path,) = config_files
server_name = config_args.server_name
if not server_name:
server_name_file = cls.pop_config_by_name(
config_files, "server_name.yaml"
)
if server_name_file:
with open(server_name_file) as f:
server_name = yaml.safe_load(f)["server_name"]
else:
raise ConfigError(
"Must specify a server_name to a generate config for."
" Pass -H server.name."
)

(config_path, *_) = config_files
if not path_exists(config_path):
print("Generating config file %s" % (config_path,))

Expand All @@ -719,13 +749,6 @@ def load_or_generate_config(
data_dir_path = os.getcwd()
data_dir_path = os.path.abspath(data_dir_path)

server_name = config_args.server_name
if not server_name:
raise ConfigError(
"Must specify a server_name to a generate config for."
" Pass -H server.name."
)

config_str = obj.generate_config(
config_dir_path=config_dir_path,
data_dir_path=data_dir_path,
Expand Down