-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-gowa-ui.sh
More file actions
150 lines (130 loc) · 4.04 KB
/
Copy pathdeploy-gowa-ui.sh
File metadata and controls
150 lines (130 loc) · 4.04 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
# Sets up gowa-ui as a SEPARATE service on the VPS.
# Does NOT touch whatomate (/opt/whatomate*, :18123, whatomate_prod DB, redis db 0).
# All secrets are generated ON the VPS and stored to /opt/gowa-ui/.deploy-secrets (root-only).
set -euo pipefail
APP_DIR=/opt/gowa-ui
BIN=$APP_DIR/gowa-ui
CFG=$APP_DIR/config.toml
DB_NAME=gowa_ui
DB_USER=gowa_ui
REDIS_DB=2 # whatomate uses db 0; gowa-ui uses db 2 (distinct)
PORT=8081 # whatomate uses 18123; gowa-ui uses 8081 (free)
echo "==[ gowa-ui separate deploy ]=="
# 1) dirs
mkdir -p "$APP_DIR"/uploads
# 2) generate secrets locally on the VPS (never printed)
ENC_KEY=$(openssl rand -hex 32) # 64 hex chars >= 32
JWT_SECRET=$(openssl rand -hex 32)
DB_PASS=$(openssl rand -hex 16) # hex => safe in SQL quotes
ADMIN_PASS=$(openssl rand -base64 18 | tr -d '/+=' | cut -c1-20)
# 3) create a dedicated Postgres role + database (separate from whatomate_prod)
if su - postgres -c "psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname='${DB_USER}'\"" | grep -q 1; then
echo "role ${DB_USER} exists; leaving as-is"
else
su - postgres -c "psql -c \"CREATE ROLE ${DB_USER} LOGIN PASSWORD '${DB_PASS}';\"" >/dev/null
echo "created role ${DB_USER}"
fi
if su - postgres -c "psql -tAc \"SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'\"" | grep -q 1; then
echo "database ${DB_NAME} exists; reusing"
else
su - postgres -c "psql -c \"CREATE DATABASE ${DB_NAME} OWNER ${DB_USER};\"" >/dev/null
echo "created database ${DB_NAME}"
fi
# 4) write config (VPS values; reuses existing Redis password + a distinct db index)
REDIS_PASS=$(sed -n "/^\[redis\]/,/^\[/p" /opt/whatomate/config.toml | awk -F'"' '/password/{print $2; exit}')
cat > "$CFG" <<EOF
# gowa-ui config — separate service. Generated $(date -u '+%Y-%m-%d %H:%M:%S UTC')
[app]
name = "Gowa-UI"
environment = "production"
debug = false
encryption_key = "${ENC_KEY}"
[server]
host = "0.0.0.0"
port = ${PORT}
read_timeout = 30
write_timeout = 30
base_path = ""
allowed_origins = ""
[database]
host = "127.0.0.1"
port = 5432
user = "${DB_USER}"
password = "${DB_PASS}"
name = "${DB_NAME}"
ssl_mode = "disable"
max_open_conns = 25
max_idle_conns = 5
conn_max_lifetime = 300
[redis]
host = "127.0.0.1"
port = 6379
username = ""
password = "${REDIS_PASS}"
db = ${REDIS_DB}
tls = false
[jwt]
secret = "${JWT_SECRET}"
access_expiry_mins = 15
refresh_expiry_days = 1
[storage]
type = "local"
local_path = "${APP_DIR}/uploads"
[cookie]
domain = ""
secure = false
[rate_limit]
enabled = true
login_max_attempts = 10
register_max_attempts = 10
refresh_max_attempts = 30
sso_max_attempts = 10
window_seconds = 60
trust_proxy = false
api_max_requests = 200
api_window_seconds = 60
[default_admin]
email = "admin@gowa-ui.local"
password = "${ADMIN_PASS}"
full_name = "Gowa-UI Admin"
EOF
chmod 600 "$CFG"
# 5) systemd unit
cat > /etc/systemd/system/gowa-ui.service <<'UNIT'
[Unit]
Description=Gowa-UI (separate test service — does NOT replace whatomate)
After=network.target postgresql.service redis-server.service
[Service]
Type=simple
WorkingDirectory=/opt/gowa-ui
ExecStart=/opt/gowa-ui/gowa-ui server -config /opt/gowa-ui/config.toml -migrate
Restart=always
RestartSec=5
KillSignal=SIGINT
TimeoutStopSec=30
[Install]
WantedBy=multi-user.target
UNIT
# 6) save secrets for the operator (root-only)
cat > "$APP_DIR"/.deploy-secrets <<EOF
# gowa-ui separate deploy secrets — generated $(date -u '+%Y-%m-%d %H:%M:%S UTC')
admin_email = admin@gowa-ui.local
admin_password = ${ADMIN_PASS}
db_user = ${DB_USER}
db_name = ${DB_NAME}
db_password = ${DB_PASS}
redis_db = ${REDIS_DB}
port = ${PORT}
config = ${CFG}
EOF
chmod 600 "$APP_DIR"/.deploy-secrets
# 7) enable + start (creates schema in the EMPTY gowa_ui DB; does not touch whatomate_prod)
systemctl daemon-reload
systemctl enable gowa-ui >/dev/null 2>&1 || true
systemctl restart gowa-ui
echo "started gowa-ui.service — waiting for it to come up..."
sleep 6
systemctl --no-pager --lines=0 status gowa-ui 2>&1 | head -8 || true
echo "==[ deploy script done ]=="
echo "Secrets saved to: ${APP_DIR}/.deploy-secrets (chmod 600)"