Files
proxmox/phoenix-deploy-api/scripts/install-systemd.sh
defiQUG 92d854a31c
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
phoenix-deploy-api: OpenAPI, server, systemd install, env example
Made-with: Cursor
2026-03-27 18:50:54 -07:00

37 lines
1.7 KiB
Bash

#!/usr/bin/env bash
# Install Phoenix Deploy API to /opt/phoenix-deploy-api and enable systemd service.
# Run with: sudo ./scripts/install-systemd.sh
# Or from repo root: sudo phoenix-deploy-api/scripts/install-systemd.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
APP_DIR="$SCRIPT_DIR/.."
TARGET="/opt/phoenix-deploy-api"
if [ "$(id -u)" -ne 0 ]; then
echo "Run with sudo to install to $TARGET and install systemd unit."
exit 1
fi
echo "Installing Phoenix Deploy API to $TARGET ..."
mkdir -p "$TARGET"
cp -a "$APP_DIR/server.js" "$APP_DIR/package.json" "$APP_DIR/package-lock.json" "$TARGET/" 2>/dev/null || cp -a "$APP_DIR/server.js" "$APP_DIR/package.json" "$TARGET/"
# Program manifest for GET /api/v1/public-sector/programs (server loads from cwd-adjacent copy on /opt)
if [[ -f "$REPO_ROOT/config/public-sector-program-manifest.json" ]]; then
cp -a "$REPO_ROOT/config/public-sector-program-manifest.json" "$TARGET/public-sector-program-manifest.json"
echo "Installed public-sector-program-manifest.json"
else
echo "WARN: $REPO_ROOT/config/public-sector-program-manifest.json missing — set PUBLIC_SECTOR_MANIFEST_PATH in .env"
fi
[ -f "$APP_DIR/.env" ] && cp "$APP_DIR/.env" "$TARGET/.env" || [ -f "$APP_DIR/.env.example" ] && cp "$APP_DIR/.env.example" "$TARGET/.env" || true
chown -R root:root "$TARGET"
cd "$TARGET" && npm install --omit=dev
cp "$APP_DIR/phoenix-deploy-api.service" /etc/systemd/system/
systemctl daemon-reload
systemctl enable phoenix-deploy-api
systemctl start phoenix-deploy-api
echo "Done. Status: $(systemctl is-active phoenix-deploy-api)"
echo "Edit $TARGET/.env (GITEA_TOKEN, etc.) and run: systemctl restart phoenix-deploy-api"