Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
bootstrap-hetzner.sh15.2 KB · 317 lines
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/env bash
# =============================================================================
# Gluecron one-shot Hetzner bootstrap.
#
# Run ONCE on a fresh (or partially-set-up) Hetzner box, via the web console,
# as root. Idempotent: safe to re-run. Won't touch existing crontech systemd
# units, will append gluecron's entries instead.
#
# Usage (paste this ONE line in Hetzner Console as root):
#   curl -sSL https://raw.githubusercontent.com/ccantynz-alt/Gluecron.com/main/scripts/bootstrap-hetzner.sh \
#     | bash -s -- "ssh-ed25519 AAAA... your@laptop"
#
# What it does (every step is idempotent + verbose):
#   1. Authorise the supplied SSH pubkey on root@ (so you can SSH from laptop)
#   2. Re-enable PasswordAuthentication as a safety fallback
#   3. Install Bun, Postgres, Caddy, git if missing
#   4. Create local Postgres DB + user 'gluecron' if missing
#   5. Clone /opt/gluecron from main if missing, or git pull if present
#   6. Write /etc/gluecron.env with DATABASE_URL pointing at local Postgres
#   7. Bun install + run migrations
#   8. Write systemd unit for gluecron on port 3010
#   9. Append gluecron + www.gluecron blocks to Caddyfile (if missing)
#  10. Reload Caddy + start gluecron
#  11. Smoke test /healthz
# =============================================================================

set -euo pipefail
PUBKEY="${1:-}"
PORT="${PORT:-3010}"
SITE_DOMAIN="${SITE_DOMAIN:-gluecron.com}"
DB_USER="gluecron"
DB_NAME="gluecron"
DB_PASS="$(openssl rand -hex 16)"

say() { echo ""; echo "==> $*"; }
ok() { echo "    ✓ $*"; }
warn() { echo "    ⚠ $*"; }

# ────────────────────────────────────────────────────────────────────────────
# 1. Authorise SSH pubkey
# ────────────────────────────────────────────────────────────────────────────
say "[1/11] Authorising SSH key on root@"
mkdir -p /root/.ssh
chmod 700 /root/.ssh
touch /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
if [ -n "$PUBKEY" ]; then
  if grep -qF "$PUBKEY" /root/.ssh/authorized_keys 2>/dev/null; then
    ok "SSH key already authorised"
  else
    echo "$PUBKEY" >> /root/.ssh/authorized_keys
    ok "SSH key added"
  fi
else
  warn "No PUBKEY argument — skipping SSH key install"
fi

# ────────────────────────────────────────────────────────────────────────────
# 2. Re-enable PasswordAuthentication (safety fallback)
# ────────────────────────────────────────────────────────────────────────────
say "[2/11] Configuring sshd (allow both key + password as fallback)"
sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
sed -i 's/^#*PubkeyAuthentication.*/PubkeyAuthentication yes/' /etc/ssh/sshd_config
sed -i 's/^#*PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
mkdir -p /etc/ssh/sshd_config.d
cat > /etc/ssh/sshd_config.d/99-gluecron-auth.conf <<EOF
PasswordAuthentication yes
PubkeyAuthentication yes
PermitRootLogin yes
EOF
systemctl reload ssh 2>/dev/null || systemctl reload sshd 2>/dev/null || true
ok "sshd reloaded — both auth methods enabled"

# ────────────────────────────────────────────────────────────────────────────
# 3. Install dependencies if missing
# ────────────────────────────────────────────────────────────────────────────
say "[3/11] Ensuring git, curl, postgresql, caddy, bun are installed"
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq

for pkg in git curl ca-certificates gnupg debian-keyring debian-archive-keyring apt-transport-https openssl unzip xz-utils tar; do
  dpkg -l | grep -qw "$pkg" || apt-get install -y -qq "$pkg"
done
ok "base packages installed"

# Postgres
if ! command -v psql >/dev/null 2>&1; then
  apt-get install -y -qq postgresql postgresql-contrib
  systemctl enable --now postgresql
  ok "postgres installed + started"
else
  ok "postgres already installed"
fi

# Caddy (skip install if already there — likely from crontech setup)
if ! command -v caddy >/dev/null 2>&1; then
  curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
  curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
  apt-get update -qq
  apt-get install -y -qq caddy
  systemctl enable --now caddy
  ok "caddy installed + started"
else
  ok "caddy already installed (likely from crontech)"
fi

# Bun
if [ ! -x /root/.bun/bin/bun ]; then
  curl -fsSL https://bun.sh/install | bash >/dev/null
  ok "bun installed"
else
  ok "bun already installed"
fi
export PATH="/root/.bun/bin:$PATH"
ok "bun version: $(/root/.bun/bin/bun --version 2>/dev/null || echo unknown)"

# ────────────────────────────────────────────────────────────────────────────
# 4. Local Postgres DB + user
# ────────────────────────────────────────────────────────────────────────────
say "[4/11] Creating local Postgres DB + user (idempotent)"
if sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname='${DB_USER}'" | grep -q 1; then
  ok "postgres user '${DB_USER}' already exists"
else
  sudo -u postgres psql -c "CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASS}';"
  ok "postgres user '${DB_USER}' created"
fi
if sudo -u postgres psql -tAc "SELECT 1 FROM pg_database WHERE datname='${DB_NAME}'" | grep -q 1; then
  ok "postgres database '${DB_NAME}' already exists"
else
  sudo -u postgres psql -c "CREATE DATABASE ${DB_NAME} OWNER ${DB_USER};"
  ok "postgres database '${DB_NAME}' created"
fi

# Read existing DB password if env file already has one (don't overwrite)
EXISTING_DB_URL=""
if [ -f /etc/gluecron.env ] && grep -q '^DATABASE_URL=' /etc/gluecron.env; then
  EXISTING_DB_URL=$(grep '^DATABASE_URL=' /etc/gluecron.env | cut -d= -f2- | tr -d '"')
  ok "reusing existing DATABASE_URL from /etc/gluecron.env"
fi
DATABASE_URL="${EXISTING_DB_URL:-postgresql://${DB_USER}:${DB_PASS}@127.0.0.1:5432/${DB_NAME}}"

# If we're using a NEW password we just generated, sync it to the DB user
if [ -z "$EXISTING_DB_URL" ]; then
  sudo -u postgres psql -c "ALTER USER ${DB_USER} WITH PASSWORD '${DB_PASS}';"
fi

# ────────────────────────────────────────────────────────────────────────────
# 5. Clone or update /opt/gluecron
# ────────────────────────────────────────────────────────────────────────────
say "[5/11] Setting up /opt/gluecron source tree"
mkdir -p /opt
if [ ! -d /opt/gluecron/.git ]; then
  git clone https://github.com/ccantynz-alt/Gluecron.com.git /opt/gluecron
  ok "cloned gluecron"
else
  cd /opt/gluecron
  git fetch --prune origin main
  git reset --hard origin/main
  ok "pulled latest main"
fi
cd /opt/gluecron

# ────────────────────────────────────────────────────────────────────────────
# 6. Write /etc/gluecron.env (preserve existing where present)
# ────────────────────────────────────────────────────────────────────────────
say "[6/11] Writing /etc/gluecron.env"
mkdir -p /data/repos
chmod 755 /data/repos
umask 077
cat > /etc/gluecron.env <<EOF
DATABASE_URL=${DATABASE_URL}
APP_BASE_URL=https://${SITE_DOMAIN}
SITE_ADMIN_USERNAME=${SITE_ADMIN_USERNAME:-ccantynz}
GIT_REPOS_PATH=/data/repos
PORT=${PORT}
DEMO_SEED_ON_BOOT=1
EMAIL_PROVIDER=log
EMAIL_FROM="gluecron <no-reply@${SITE_DOMAIN}>"
NODE_ENV=production
EOF
chmod 600 /etc/gluecron.env
umask 022
ok "/etc/gluecron.env written (chmod 600)"

# ────────────────────────────────────────────────────────────────────────────
# 7. Bun install + run migrations
# ────────────────────────────────────────────────────────────────────────────
say "[7/11] bun install + db:migrate"
/root/.bun/bin/bun install --frozen-lockfile
set -a; source /etc/gluecron.env; set +a
/root/.bun/bin/bun run src/db/migrate.ts || warn "migrations command failed — may already be applied"
ok "deps + migrations done"

# ────────────────────────────────────────────────────────────────────────────
# 8. systemd unit for gluecron
# ────────────────────────────────────────────────────────────────────────────
# Block N2 — `Type=notify` so `systemctl restart gluecron` blocks until the
# new process has called sd_notify(READY=1) (wired in src/lib/systemd-notify.ts
# from src/index.ts). That eliminates the post-restart sleep-and-poll loop in
# the deploy workflow.
#
# Block N2 — Bun-compiled single-binary path. If `/opt/gluecron/.next/gluecron-server`
# exists (built by the deploy workflow), prefer it (~10x faster cold start vs
# `bun run src/index.ts`). Falls back to interpreted Bun for safety so a stale
# bootstrap still produces a runnable unit on a brand-new box.
say "[8/11] Writing /etc/systemd/system/gluecron.service"
BUN_BIN=/root/.bun/bin/bun
COMPILED_BIN=/opt/gluecron/.next/gluecron-server
mkdir -p /opt/gluecron/.next
if [ -x "$COMPILED_BIN" ]; then
  EXEC_START="$COMPILED_BIN"
else
  EXEC_START="${BUN_BIN} run src/index.ts"
fi
cat > /etc/systemd/system/gluecron.service <<EOF
[Unit]
Description=Gluecron — AI-native code intelligence platform
After=network-online.target postgresql.service
Wants=network-online.target

[Service]
Type=notify
NotifyAccess=main
User=root
WorkingDirectory=/opt/gluecron
EnvironmentFile=/etc/gluecron.env
ExecStart=${EXEC_START}
Restart=always
RestartSec=5
# Block N2 — give the new process up to 30s to call sd_notify(READY=1).
# Default is 90s; we lower it so a hung-on-startup deploy fails fast.
TimeoutStartSec=30
StandardOutput=journal
StandardError=journal
SyslogIdentifier=gluecron
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable gluecron >/dev/null
systemctl restart gluecron
ok "gluecron systemd unit installed + started (Type=notify, ExecStart=${EXEC_START})"

# ────────────────────────────────────────────────────────────────────────────
# 9. Append gluecron + www.gluecron to Caddyfile if missing
# ────────────────────────────────────────────────────────────────────────────
say "[9/11] Caddy reverse-proxy config for ${SITE_DOMAIN}"
CADDYFILE=/etc/caddy/Caddyfile
touch "$CADDYFILE"
if grep -qE "^${SITE_DOMAIN}\s*\{" "$CADDYFILE"; then
  ok "${SITE_DOMAIN} block already in Caddyfile — leaving as-is"
else
  cat >> "$CADDYFILE" <<EOF

${SITE_DOMAIN} {
    encode zstd gzip
    reverse_proxy localhost:${PORT}
}

www.${SITE_DOMAIN} {
    redir https://${SITE_DOMAIN}{uri} permanent
}
EOF
  ok "appended ${SITE_DOMAIN} block to Caddyfile"
fi

if caddy validate --config "$CADDYFILE" --adapter caddyfile 2>&1 | grep -qi "valid"; then
  systemctl reload caddy || systemctl restart caddy
  ok "caddy reloaded"
else
  warn "caddy validate warned — check: caddy validate --config $CADDYFILE"
fi

# ────────────────────────────────────────────────────────────────────────────
# 10. Wait + smoke test
# ────────────────────────────────────────────────────────────────────────────
say "[10/11] Waiting for /healthz to come up (60s)"
for i in $(seq 1 12); do
  code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${PORT}/healthz" || echo 000)
  if [ "$code" = "200" ]; then
    ok "gluecron is live on http://localhost:${PORT} (attempt $i)"
    break
  fi
  sleep 5
done
if [ "$code" != "200" ]; then
  warn "healthz did not respond 200 after 60s. Logs: journalctl -u gluecron -n 50 --no-pager"
fi

# ────────────────────────────────────────────────────────────────────────────
# 11. Summary
# ────────────────────────────────────────────────────────────────────────────
say "[11/11] DONE"
echo ""
echo "============================================================"
echo "  GLUECRON BOOTSTRAP COMPLETE"
echo "============================================================"
echo "  systemd unit:   gluecron.service"
echo "  port:           ${PORT}"
echo "  env file:       /etc/gluecron.env (chmod 600)"
echo "  bare repos:     /data/repos"
echo "  source:         /opt/gluecron"
echo ""
echo "  Test from your laptop:"
echo "    ssh root@\$(hostname -I | awk '{print \$1}') 'systemctl status gluecron --no-pager | head -5'"
echo ""
echo "  Public URL (once DNS is correct + Caddy issued cert):"
echo "    https://${SITE_DOMAIN}"
echo "    https://${SITE_DOMAIN}/api/version"
echo ""
echo "  Useful commands:"
echo "    systemctl status gluecron"
echo "    journalctl -u gluecron -f"
echo "    bash /opt/gluecron/scripts/bootstrap-hetzner.sh   # safe to re-run"
echo "============================================================"