85 lines
2.0 KiB
Bash
Executable File
85 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# PingQL Deploy Script
|
|
# Usage: ./deploy.sh [web|api|monitor|db|all] [...]
|
|
# Example: ./deploy.sh web api
|
|
# Example: ./deploy.sh all
|
|
|
|
set -e
|
|
|
|
SSH="ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_ed25519"
|
|
|
|
DB_HOST="root@142.132.190.209"
|
|
API_HOST="root@88.99.123.102"
|
|
WEB_HOST="root@78.47.43.36"
|
|
MONITOR_HOSTS=("root@5.161.76.127" "root@5.78.178.12" "root@5.223.51.251" "root@49.13.118.44")
|
|
|
|
deploy_db() {
|
|
echo "[db] Restarting PostgreSQL on database-eu-central..."
|
|
$SSH $DB_HOST "systemctl restart postgresql && echo 'PostgreSQL restarted'"
|
|
}
|
|
|
|
deploy_api() {
|
|
echo "[api] Deploying to api-eu-central..."
|
|
$SSH $API_HOST bash << 'REMOTE'
|
|
cd /opt/pingql
|
|
git pull
|
|
cd apps/api
|
|
/root/.bun/bin/bun install
|
|
systemctl restart pingql-api
|
|
systemctl restart caddy
|
|
echo "API deployed and restarted"
|
|
REMOTE
|
|
}
|
|
|
|
deploy_web() {
|
|
echo "[web] Deploying to web-eu-central..."
|
|
$SSH $WEB_HOST bash << 'REMOTE'
|
|
cd /opt/pingql
|
|
git pull
|
|
cd apps/web
|
|
/root/.bun/bin/bun install
|
|
/root/.bun/bin/bun run css
|
|
systemctl restart pingql-web
|
|
systemctl restart caddy
|
|
echo "Web deployed and restarted"
|
|
REMOTE
|
|
}
|
|
|
|
deploy_monitor() {
|
|
echo "[monitor] Deploying to all 4 monitors in parallel..."
|
|
for host in "${MONITOR_HOSTS[@]}"; do
|
|
(
|
|
echo "[monitor] Starting deploy on $host..."
|
|
$SSH $host bash << 'REMOTE'
|
|
cd /opt/pingql
|
|
git pull
|
|
cd apps/monitor
|
|
/root/.cargo/bin/cargo build --release
|
|
systemctl restart pingql-monitor
|
|
echo "Monitor deployed and restarted on $(hostname)"
|
|
REMOTE
|
|
) &
|
|
done
|
|
wait
|
|
echo "[monitor] All monitors deployed"
|
|
}
|
|
|
|
# Parse args
|
|
if [ $# -eq 0 ]; then
|
|
echo "Usage: $0 [web|api|monitor|db|all] [...]"
|
|
exit 1
|
|
fi
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
db) deploy_db ;;
|
|
api) deploy_api ;;
|
|
web) deploy_web ;;
|
|
monitor) deploy_monitor ;;
|
|
all) deploy_db; deploy_api; deploy_web; deploy_monitor ;;
|
|
*) echo "Unknown target: $arg (valid: web, api, monitor, db, all)"; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
echo "Deploy complete."
|