from json import dumps defaults = { 'apt': { 'repos': { 'matrix': { 'items': { 'deb https://packages.matrix.org/{os} {os_release} main', }, }, }, 'packages': { 'matrix-synapse-py3': {}, }, }, 'backups': { 'paths': { '/var/lib/matrix-synapse', }, }, 'icinga2_api': { 'matrix-synapse': { 'services': { 'MATRIX-SYNAPSE PROCESS': { 'command_on_monitored_host': '/usr/lib/nagios/plugins/check_procs -a synapse.app.homeserver -c 1:', 'vars.notification.sms': True, }, }, }, }, 'matrix-synapse': { 'registration_shared_secret': repo.vault.human_password_for('{} matrix-synapse registration_shared_secret'.format(node.name)), 'database': { 'user': 'synapse_user', 'password': repo.vault.password_for('{} postgresql synapse_user'.format(node.name)), 'database': 'synapse', }, 'appservice_configs': set(), }, 'postgresql': { 'roles': { 'synapse_user': { 'password': repo.vault.password_for('{} postgresql synapse_user'.format(node.name)), }, }, 'databases': { 'synapse': { 'owner': 'synapse_user', 'when_creating': { 'collation': 'C', 'ctype': 'C', }, }, }, }, 'zfs': { 'datasets': { 'tank/matrix-synapse': { 'mountpoint': '/var/lib/matrix-synapse', 'needed_by': { 'pkg_apt:matrix-synapse-py3', }, }, }, }, } @metadata_reactor.provides( 'nginx/vhosts/matrix-synapse', ) def nginx(metadata): if not node.has_bundle('nginx'): raise DoNotRunAgain locations = { '/_matrix': { 'target': 'http://[::1]:20080', }, '/_synapse': { 'target': 'http://[::1]:20080', }, '/.well-known/matrix/client': { 'return': dumps({ 'm.homeserver': { 'base_url': 'https://{}'.format(metadata.get('matrix-synapse/baseurl')), }, 'm.identity_server': { 'base_url': metadata.get('matrix-synapse/identity_server', 'https://matrix.org'), }, **metadata.get('matrix-synapse/additional_client_config', {}), }, sort_keys=True), 'additional_config': { 'default_type application/json', 'add_header Access-Control-Allow-Origin *', }, }, '/.well-known/matrix/server': { 'return': dumps({ 'm.server': '{}:443'.format(metadata.get('matrix-synapse/baseurl')), }, sort_keys=True), 'additional_config': { 'default_type application/json', 'add_header Access-Control-Allow-Origin *', }, }, } if node.has_bundle('matrix-media-repo'): locations['/_matrix/media'] = { 'target': 'http://localhost:20090', 'max_body_size': '{}M'.format(metadata.get('matrix-media-repo/upload_max_mb')), # matrix-media-repo needs this to be the # homeserver address. 'x_forwarded_host': metadata.get('matrix-synapse/server_name'), } return { 'nginx': { 'vhosts': { 'matrix-synapse': { 'domain': metadata.get('matrix-synapse/baseurl'), 'locations': locations, 'website_check_path': '/_matrix/static/', 'website_check_string': 'Synapse is running', }, }, }, }