41 lines
1.1 KiB
Bash
41 lines
1.1 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
# Pull the latest code and restart Thermograph. Run on the VPS — the GitHub
|
||
|
|
# Actions workflow invokes this over SSH, and you can run it by hand too.
|
||
|
|
#
|
||
|
|
# ssh deploy@vps '/opt/thermograph/deploy/deploy.sh'
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
APP_DIR="${APP_DIR:-/opt/thermograph}"
|
||
|
|
BRANCH="${BRANCH:-main}"
|
||
|
|
cd "$APP_DIR"
|
||
|
|
|
||
|
|
echo "==> Fetching $BRANCH"
|
||
|
|
git fetch --prune origin "$BRANCH"
|
||
|
|
git reset --hard "origin/$BRANCH"
|
||
|
|
|
||
|
|
echo "==> Installing dependencies"
|
||
|
|
if [ ! -d .venv ]; then
|
||
|
|
python3 -m venv .venv
|
||
|
|
fi
|
||
|
|
.venv/bin/pip install --upgrade pip -q
|
||
|
|
.venv/bin/pip install -r backend/requirements.txt -q
|
||
|
|
|
||
|
|
echo "==> Restarting service"
|
||
|
|
sudo systemctl restart thermograph
|
||
|
|
|
||
|
|
echo "==> Health check"
|
||
|
|
PORT="$(sed -n 's/^PORT=//p' /etc/thermograph.env)"; PORT="${PORT:-8137}"
|
||
|
|
BASE="$(sed -n 's/^THERMOGRAPH_BASE=//p' /etc/thermograph.env)"; BASE="${BASE:-/}"
|
||
|
|
# Normalize: no double slash, allow root.
|
||
|
|
url="http://127.0.0.1:${PORT}${BASE%/}/"
|
||
|
|
for i in $(seq 1 15); do
|
||
|
|
if curl -fsS -o /dev/null "$url"; then
|
||
|
|
echo "==> OK: $url is serving"
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
sleep 1
|
||
|
|
done
|
||
|
|
echo "!! Health check failed for $url" >&2
|
||
|
|
sudo systemctl status thermograph --no-pager -l || true
|
||
|
|
exit 1
|