From b5e747815851c222ec0e3edd76a6fa1c82ae07bb Mon Sep 17 00:00:00 2001 From: root Date: Sun, 31 May 2026 15:32:09 +1000 Subject: [PATCH] chore(deploy): systemd unit, push.sh, one-time setup notes --- deploy/README.md | 53 ++++++++++++++++++++++++++++++++++++++ deploy/push.sh | 22 ++++++++++++++++ deploy/void-server.service | 18 +++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 deploy/README.md create mode 100755 deploy/push.sh create mode 100644 deploy/void-server.service diff --git a/deploy/README.md b/deploy/README.md new file mode 100644 index 0000000..bb4dda1 --- /dev/null +++ b/deploy/README.md @@ -0,0 +1,53 @@ +# Deploy notes — Void 2.0 + +## App deploy (CT 311 — `void2-app`) + +One-time setup on the target host: + +```bash +# Node 22 (from nodesource if Debian's default is older) +curl -fsSL https://deb.nodesource.com/setup_22.x | bash - +apt install -y nodejs + +# Service user + working dir +useradd -r -m -d /opt/void-server void +mkdir -p /opt/void-server +chown void: /opt/void-server + +# systemd +install -m 644 void-server.service /etc/systemd/system/void-server.service +systemctl daemon-reload +systemctl enable void-server + +# Secrets — /opt/void-server/.env must contain: +# DATABASE_URL=postgres://void:@:5432/void +# OWNER_TOKEN=<32+ char secret> +# PORT=3000 +# NODE_ENV=production +chmod 600 /opt/void-server/.env +chown void: /opt/void-server/.env +``` + +Then from the dev box: + +```bash +cd /project/src/void-v2 +./deploy/push.sh +``` + +## Maintenance + +```bash +journalctl -u void-server -f # follow logs +systemctl status void-server # check status +systemctl restart void-server # cycle + +# Run migrations on the deployed copy: +ssh root@void2-app 'cd /opt/void-server && npm run migrate' +``` + +## Notes + +- `.env` is excluded from the rsync to avoid clobbering production secrets with dev values. +- The push script uses `--omit=dev` to skip test deps on the target. +- `tests/` is excluded — they're for the dev environment only. diff --git a/deploy/push.sh b/deploy/push.sh new file mode 100755 index 0000000..eef81ad --- /dev/null +++ b/deploy/push.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Push dev source to void2-app (CT 311) and restart the service. +# Run from /project/src/void-v2. +# +# Override TARGET / REMOTE_DIR via env if needed: +# TARGET=root@192.168.1.16 ./deploy/push.sh + +TARGET=${TARGET:-root@void2-app} +REMOTE_DIR=${REMOTE_DIR:-/opt/void-server} + +rsync -avz --delete \ + --exclude node_modules \ + --exclude .git \ + --exclude tests \ + --exclude coverage \ + --exclude .env \ + ./ "$TARGET:$REMOTE_DIR/" + +ssh "$TARGET" "cd $REMOTE_DIR && npm install --omit=dev && systemctl restart void-server" +echo "Deployed." diff --git a/deploy/void-server.service b/deploy/void-server.service new file mode 100644 index 0000000..120a854 --- /dev/null +++ b/deploy/void-server.service @@ -0,0 +1,18 @@ +[Unit] +Description=Void 2.0 server +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=void +WorkingDirectory=/opt/void-server +EnvironmentFile=/opt/void-server/.env +ExecStart=/usr/bin/node /opt/void-server/server.js +Restart=on-failure +RestartSec=5 +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=multi-user.target