Last active
May 10, 2026 21:14
-
-
Save koliadych/7f54d8d200778c7de0685669c0b8447c to your computer and use it in GitHub Desktop.
fintechner caddy timeouts + clean restart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -euo pipefail | |
| export AWS_PAGER="" | |
| REGION=ap-northeast-1 | |
| INSTANCE_ID=i-089ad4a6b76132ba2 | |
| # Build the new Caddyfile content (base64-encoded so SSM doesn't mangle newlines) | |
| CADDYFILE=$(cat <<'CFG' | |
| { | |
| email koliadych@gmail.com | |
| } | |
| 13-193-136-150.sslip.io { | |
| reverse_proxy localhost:3000 | |
| # Connector API (admin runtime ops can take 10-30s; explicit timeouts) | |
| handle_path /api/* { | |
| reverse_proxy localhost:8080 { | |
| transport http { | |
| dial_timeout 5s | |
| read_timeout 180s | |
| write_timeout 180s | |
| } | |
| } | |
| } | |
| handle_path /ws { | |
| reverse_proxy localhost:8080 | |
| } | |
| encode gzip zstd | |
| log { | |
| output file /var/log/caddy/access.log | |
| } | |
| } | |
| CFG | |
| ) | |
| CADDYFILE_B64=$(printf '%s' "$CADDYFILE" | base64 -w0) | |
| cat > /tmp/ssm-fix.json <<JSON | |
| { | |
| "commands": [ | |
| "echo === 1. update Caddyfile with explicit timeouts ===", | |
| "echo '${CADDYFILE_B64}' | base64 -d | sudo tee /etc/caddy/Caddyfile >/dev/null", | |
| "sudo caddy validate --config /etc/caddy/Caddyfile", | |
| "sudo systemctl reload caddy", | |
| "echo === 2. break the reload loop, restart connector cleanly ===", | |
| "sudo systemctl stop fintechner-connector", | |
| "sleep 2", | |
| "sudo systemctl reset-failed fintechner-connector", | |
| "sudo systemctl start fintechner-connector", | |
| "sleep 8", | |
| "echo === 3. restart dashboard ===", | |
| "sudo systemctl restart fintechner-dashboard", | |
| "sleep 6", | |
| "echo === 4. health summary ===", | |
| "echo --- services ---", | |
| "sudo systemctl is-active caddy fintechner-connector fintechner-dashboard timescale.service 2>/dev/null || sudo systemctl is-active caddy fintechner-connector fintechner-dashboard; sudo docker ps --format \"timescale: {{.Status}}\"", | |
| "echo --- ports ---", | |
| "sudo ss -tlnp | grep -E :(80|443|3000|8080)", | |
| "echo --- connector last 20 ---", | |
| "sudo journalctl -u fintechner-connector -n 20 --no-pager" | |
| ] | |
| } | |
| JSON | |
| CMD_ID=$(aws --region "$REGION" ssm send-command \ | |
| --instance-ids "$INSTANCE_ID" \ | |
| --document-name AWS-RunShellScript \ | |
| --parameters file:///tmp/ssm-fix.json \ | |
| --query Command.CommandId --output text) | |
| rm -f /tmp/ssm-fix.json | |
| echo " ssm: $CMD_ID" | |
| for i in $(seq 1 30); do | |
| sleep 4 | |
| STATUS=$(aws --region "$REGION" ssm get-command-invocation --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query Status --output text 2>/dev/null || echo Pending) | |
| case "$STATUS" in Success|Failed|Cancelled|TimedOut) echo " $STATUS"; break ;; *) echo " $STATUS";; esac | |
| done | |
| echo | |
| echo "=== STDOUT ===" | |
| aws --region "$REGION" ssm get-command-invocation --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query StandardOutputContent --output text | |
| echo | |
| echo "=== STDERR ===" | |
| aws --region "$REGION" ssm get-command-invocation --command-id "$CMD_ID" --instance-id "$INSTANCE_ID" --query StandardErrorContent --output text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment