diff --git a/sn-manager/README.md b/sn-manager/README.md index a6723a53..5d24124c 100644 --- a/sn-manager/README.md +++ b/sn-manager/README.md @@ -6,6 +6,8 @@ SuperNode Process Manager with Automatic Updates - [Installation](#installation) - [Systemd Service Setup](#systemd-service-setup) + - [Custom Base (Same User, Recommended)](#setup-custom-base-same-user) + - [Custom Base (Dedicated User)](#setup-custom-base-dedicated-user) - [Ensure PATH points to user install](#ensure-path-points-to-user-install-required-for-self-update) - [Initialization](#initialization) - [Commands](#commands) @@ -82,6 +84,116 @@ sudo systemctl restart sn-manager journalctl -u sn-manager -f ``` + +## Setup in a Custom Base (Same User, Simple CLI) — Recommended + +Use your current user and keep CLI commands unchanged by placing data under a custom base and linking it to your home directory. + +Why this is simple: +- CLI stays the same: run `sn-manager ...` as usual (no sudo -u). +- No environment overrides: systemd can use the standard unit from this README. +- Self-update works: binary lives in a user-writable location. + +Variables: +- ``: The custom base directory (e.g., `/srv/app`). + +```bash +# 1) Prepare directories under your chosen base +mkdir -p /.sn-manager/bin +mkdir -p /.supernode + +# 2) Install sn-manager to the base (user-writable for self-update) +curl -L https://github.com/LumeraProtocol/supernode/releases/latest/download/supernode-linux-amd64.tar.gz | tar -xz +install -D -m 0755 sn-manager /.sn-manager/bin/sn-manager + +# 3) Link the base to your home (so CLI and unit files remain unchanged) +ln -s /.sn-manager "$HOME/.sn-manager" +ln -s /.supernode "$HOME/.supernode" + +# 4) Ensure your shell resolves to the user install (self-update) +# Follow: "Ensure PATH points to user install" section below. + +# 5) Use the standard systemd unit from this README (no HOME override needed) +# Then start the service and follow logs +sudo systemctl daemon-reload +sudo systemctl enable --now sn-manager +journalctl -u sn-manager -f +``` + +Notes (plain English): +- Your files live under `` but appear at `~/.sn-manager` and `~/.supernode` via links, keeping tools happy. +- Auto-update needs a writable binary dir; installing to `/.sn-manager/bin` (linked to `~/.sn-manager/bin`) ensures this. +- Avoid multiple installs to prevent PATH confusion; remove any global `/usr/local/bin/sn-manager` copy if present. + + +## Setup in a Custom Base (Dedicated Service User) + +Alternative (isolated) setup. This installs and runs sn-manager and SuperNode under a custom base directory using a dedicated system user. It isolates the service, keeps auto-updates working, and avoids affecting other applications or users. + +Rationale and choices: +- Dedicated service user: Contains impact to just this service, avoids changing your login user’s HOME, and keeps permissions tight. Recommended for production. +- Current user: You may reuse your existing user if desired. In that case, set `User=` in the unit, ensure the base directory is owned by that user, and keep the service-only `HOME=` override. +- Why HOME override: Both sn-manager and SuperNode derive their state from `HOME` (`$HOME/.sn-manager` and `$HOME/.supernode`). Overriding HOME for the service ensures both components operate in the same custom base without extra flags. +- Self-update requirement: sn-manager must be installed in a directory writable by the service user (`/.sn-manager/bin/sn-manager`). + +Variables used below: +- ``: The system user account that will run the service (e.g., `lumera` or your current user). +- ``: The custom base directory (e.g., `/srv/app`). + +```bash +# 1) Create base and (optionally) a dedicated service user +sudo useradd --system --home-dir --shell /usr/sbin/nologin || true +sudo mkdir -p +sudo chown -R : + +# 2) Install sn-manager into the custom base so it can self-update +curl -L https://github.com/LumeraProtocol/supernode/releases/latest/download/supernode-linux-amd64.tar.gz | tar -xz +sudo -u install -D -m 0755 sn-manager /.sn-manager/bin/sn-manager + +# 3) Systemd unit (service-only HOME override keeps state under ) +sudo tee /etc/systemd/system/sn-manager.service < +Environment="HOME=" +WorkingDirectory= +ExecStart=/.sn-manager/bin/sn-manager start +Restart=on-failure +RestartSec=10 +LimitNOFILE=65536 + +[Install] +WantedBy=multi-user.target +EOF + +sudo systemctl daemon-reload + +# 4) Initialize (see the Initialization section below) +# Use: sn-manager init (interactive) or flags as needed. + +# 5) Start and follow logs +sudo systemctl enable --now sn-manager +journalctl -u sn-manager -f +``` + +Notes: +- Your files live under ``: + - Manager data: `/.sn-manager` + - SuperNode data: `/.supernode` +- New user vs current user: + - New user keeps things isolated and safer (recommended for servers). + - Using your current user is fine too; just set `User=` and ensure `` belongs to that user. +- Only the service’s HOME changes: + - This does not change your normal shell’s HOME. + - The change applies only to the sn-manager service and the SuperNode it starts. +- Self-update works only if the binary is writable by the service user: + - Install to `/.sn-manager/bin/sn-manager` as shown. +- Command-line usage as the service user (optional): + - `sudo -u HOME= /.sn-manager/bin/sn-manager status` + ### Ensure PATH points to user install (Required for self-update) To ensure self-update works and avoid conflicts, make sure your shell resolves to the user-writable install: @@ -345,6 +457,8 @@ updates: auto_upgrade: true ``` +When using a custom base setup (service-only HOME override), the path above becomes `$HOME/.sn-manager/config.yml` at `/.sn-manager/config.yml`. + **Reset:** Reset managed data while keeping the installed sn-manager binary: