30 lines
1.3 KiB
Bash
30 lines
1.3 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/"
|
||
|
|
[ -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"
|