#!/usr/bin/env bash # Deploy telegram relay on the VPS (idempotent). # Expects app files already present in APP_DIR (CI rsync or prior clone). set -euo pipefail APP_DIR="${APP_DIR:-/opt/ghabilee-telegram-relay}" cd "$APP_DIR" install -m 0644 deploy/docker-compose.production.yml "$APP_DIR/docker-compose.yml" if [ ! -f "$APP_DIR/.env" ]; then echo "Missing $APP_DIR/.env — copy from .env.example and fill secrets before serving traffic." >&2 cp .env.example "$APP_DIR/.env" chmod 600 "$APP_DIR/.env" echo "Created placeholder .env; edit it, then re-run deploy." >&2 exit 2 fi docker compose -f "$APP_DIR/docker-compose.yml" build --pull docker compose -f "$APP_DIR/docker-compose.yml" up -d --remove-orphans install -m 0644 deploy/nginx/telegram-relay.conf /etc/nginx/sites-available/telegram-relay ln -sfn /etc/nginx/sites-available/telegram-relay /etc/nginx/sites-enabled/telegram-relay nginx -t systemctl reload nginx for attempt in $(seq 1 30); do health="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' ghabilee-telegram-relay 2>/dev/null || echo missing)" echo "health ${attempt}/30: ${health}" if [ "$health" = "healthy" ] || [ "$health" = "running" ]; then curl -sf "http://127.0.0.1:3100/health" >/dev/null echo "Deploy OK" exit 0 fi case "$health" in unhealthy|exited|dead|missing) exit 1 ;; esac sleep 2 done echo "Timed out waiting for healthy container" >&2 exit 1