-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynctl_entrypoint.sh
More file actions
107 lines (94 loc) · 4.26 KB
/
synctl_entrypoint.sh
File metadata and controls
107 lines (94 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# © ECAD Infra Inc.
set -eu
# Parse command-line arguments
CONFIG_FILE="/config/homeserver.yaml"
SKIP_TEMPLATING=false
while [ $# -gt 0 ]; do
case "$1" in
-c|--config)
CONFIG_FILE="$2"
shift 2
;;
--skip-templating)
SKIP_TEMPLATING=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [-c|--config <path>] [--skip-templating]"
exit 1
;;
esac
done
echo "Using config file: $CONFIG_FILE"
# Configure metrics bind address based on SYNAPSE_ENABLE_METRICS (official Synapse convention)
# SYNAPSE_ENABLE_METRICS=1 enables metrics listener (port 19090 for main, 19091+ for workers)
# Defaults to 0 (disabled) to match official Synapse Docker behavior
if [ "${SYNAPSE_ENABLE_METRICS:-0}" = "1" ]; then
export METRICS_BIND_ADDRESS="0.0.0.0"
echo "Metrics enabled on 0.0.0.0:19090 (main), 19091+ (workers)"
else
export METRICS_BIND_ADDRESS="127.0.0.1"
echo "Metrics disabled (set SYNAPSE_ENABLE_METRICS=1 to enable)"
fi
# Set defaults for optional configuration variables
# PUBLIC_BASEURL: Federation and .well-known delegation (defaults to https://SERVER_NAME)
export PUBLIC_BASEURL="${PUBLIC_BASEURL:-https://$SERVER_NAME}"
# DB_CP_MIN/MAX: Database connection pool size (defaults match previous hardcoded values)
export DB_CP_MIN="${DB_CP_MIN:-20}"
export DB_CP_MAX="${DB_CP_MAX:-80}"
# Perform variable substitution unless --skip-templating is set
ENVSUBST_VARS='${SERVER_NAME} ${DB_HOST} ${DB_USER} ${DB_PASS} ${DB_NAME} ${REGISTRATION_SHARED_SECRET} ${METRICS_BIND_ADDRESS} ${PUBLIC_BASEURL} ${DB_CP_MIN} ${DB_CP_MAX}'
if [ "$SKIP_TEMPLATING" = "false" ]; then
echo "Performing template variable substitution..."
envsubst "$ENVSUBST_VARS" < "${CONFIG_FILE}.template" > "$CONFIG_FILE"
if [ -f /config/shared_config.yaml.template ]; then
envsubst '${SERVER_NAME}' < /config/shared_config.yaml.template > /config/shared_config.yaml
fi
# Process worker config templates
if [ -d /config/workers.template ]; then
mkdir -p /config/workers
for tmpl in /config/workers.template/*.yaml; do
[ -f "$tmpl" ] || continue
envsubst '${METRICS_BIND_ADDRESS}' < "$tmpl" > "/config/workers/$(basename "$tmpl")"
done
fi
# Implement SERVE_WELLKNOWN functionality for Cloudflare-proxied servers
# When SERVE_WELLKNOWN=true, configure Synapse to serve .well-known/matrix/server
# This enables federation on port 443 instead of 8448 (required for Cloudflare)
if [ "${SERVE_WELLKNOWN:-false}" = "true" ]; then
echo "Enabling .well-known/matrix/server endpoint (SERVE_WELLKNOWN=true)"
# Add serve_server_wellknown setting if not already present
if ! grep -q "^serve_server_wellknown:" "$CONFIG_FILE"; then
echo "" >> "$CONFIG_FILE"
echo "# Auto-configured by entrypoint based on SERVE_WELLKNOWN env var" >> "$CONFIG_FILE"
echo "serve_server_wellknown: true" >> "$CONFIG_FILE"
fi
fi
else
echo "Skipping template variable substitution (--skip-templating)"
# When skipping, ensure config files exist (copy templates as-is)
[ ! -f "$CONFIG_FILE" ] && cp "${CONFIG_FILE}.template" "$CONFIG_FILE"
[ ! -f /config/shared_config.yaml ] && [ -f /config/shared_config.yaml.template ] && \
cp /config/shared_config.yaml.template /config/shared_config.yaml
[ ! -d /config/workers ] && [ -d /config/workers.template ] && \
cp -r /config/workers.template /config/workers
fi
(umask 077; echo "${SIGNING_KEY}" > /config/signing.key)
/usr/local/bin/wait-for.sh -t 30 "$DB_HOST:5432"
# Start Synapse based on SYNAPSE_WORKERS mode (default: single-process)
SYNAPSE_WORKERS="${SYNAPSE_WORKERS:-false}"
if [ "$SYNAPSE_WORKERS" = "true" ]; then
echo "Starting Synapse in multi-worker mode with config: $CONFIG_FILE"
echo "Note: Multi-worker mode requires a load balancer for createRoom routing"
synctl start "$CONFIG_FILE" -w /config/workers/main_process.yaml
synctl start "$CONFIG_FILE" -w /config/workers/worker1.yaml
synctl start "$CONFIG_FILE" -w /config/workers/worker2.yaml
synctl start "$CONFIG_FILE" -w /config/workers/worker3.yaml
synctl start "$CONFIG_FILE" -w /config/workers/worker4.yaml --no-daemonize
else
echo "Starting Synapse in single-process mode with config: $CONFIG_FILE"
synctl start "$CONFIG_FILE" --no-daemonize
fi