<%
    database = node.metadata.get('matrix-synapse/database')
    db_string = 'postgresql://{}:{}@{}/{}?sslmode=disable'.format(
        database['user'],
        database['password'],
        database.get('host', 'localhost'),
        database['database'],
    )
%>\
[Unit]
Description=matrix-org sliding-sync proxy
After=network.target
Requires=postgresql.service

[Service]
User=matrix-synapse
Group=matrix-synapse
Environment=SYNCV3_SERVER=https://${node.metadata.get('matrix-synapse/baseurl')}
Environment=SYNCV3_DB=${db_string}
Environment=SYNCV3_SECRET=${node.metadata.get('matrix-synapse/sliding_sync/secret')}
Environment=SYNCV3_BINDADDR=127.0.0.1:20070
ExecStart=/usr/local/bin/matrix-sliding-sync
Restart=always
RestartSec=10s

[Install]
WantedBy=multi-user.target
