#!/usr/bin/env bash # Pull the latest LLeMbas and restart the service. # # This is what to run after pushing: it fetches, hard-resets the deployment # checkout to the remote branch, reinstalls dependencies if they changed, and # restarts. Nothing is ever edited in place at /srv/lembas/app, so a hard reset # is safe and avoids merge conflicts from a dirty deployment tree. set -euo pipefail SERVICE_USER=lembas PREFIX=/srv/lembas APP="$PREFIX/app" VENV="$PREFIX/venv" BRANCH="${LEMBAS_BRANCH:-main}" if [[ ! -d "$APP/.git" ]]; then echo "No deployment at $APP. Run deploy/install.sh first." >&2 exit 1 fi before=$(sudo -u "$SERVICE_USER" git -C "$APP" rev-parse HEAD) echo "== fetching ==" sudo -u "$SERVICE_USER" git -C "$APP" fetch --quiet origin "$BRANCH" sudo -u "$SERVICE_USER" git -C "$APP" reset --hard --quiet "origin/$BRANCH" after=$(sudo -u "$SERVICE_USER" git -C "$APP" rev-parse HEAD) if [[ "$before" == "$after" ]]; then echo " already at $(git -C "$APP" rev-parse --short HEAD), nothing to pull" else echo " $(echo "$before" | cut -c1-7) -> $(echo "$after" | cut -c1-7)" sudo -u "$SERVICE_USER" git -C "$APP" --no-pager log --oneline "$before..$after" | sed 's/^/ /' fi # Cheap and idempotent; catches a dependency added since the last deploy. echo "== dependencies ==" sudo -u "$SERVICE_USER" "$VENV/bin/pip" install --quiet -e "$APP" echo "== restart ==" sudo systemctl restart lembas sleep 2 if systemctl is-active --quiet lembas; then echo " lembas is running at https://chat.lan" else echo " lembas FAILED to start:" >&2 sudo journalctl -u lembas -n 30 --no-pager >&2 exit 1 fi