diff options
| author | Adam Malczewski <[email protected]> | 2026-06-21 21:18:53 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-21 21:18:53 +0900 |
| commit | c58d811e719da91e195b1fc3c29c2554c1d9b0ad (patch) | |
| tree | d96bbe5965b624d6f19008c1422a70e499051d77 /bin/install | |
| parent | 219e7f2dd0ff2d0125f18594c6c16a6c0aff6710 (diff) | |
| download | dispatch-c58d811e719da91e195b1fc3c29c2554c1d9b0ad.tar.gz dispatch-c58d811e719da91e195b1fc3c29c2554c1d9b0ad.zip | |
feat(install): run dispatch service as user, not root
systemd service: User= and Group= patched by bin/install from SUDO_USER.
bin/setup-env: chowns data dirs to the real user. Since the service runs
as the user, os.homedir() resolves correctly for skills discovery —
no separate HOME env var needed.
Diffstat (limited to 'bin/install')
| -rwxr-xr-x | bin/install | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/bin/install b/bin/install index 57d0684..99421f1 100755 --- a/bin/install +++ b/bin/install @@ -82,19 +82,24 @@ fi # ─── Install systemd service ───────────────────────────────────────────────── echo "[install] systemd service → /etc/systemd/system/" -install -Dm644 "$ROOT/systemd/dispatch.service" /etc/systemd/system/dispatch.service +# Patch User=/Group= with the real user (so it doesn't run as root) +REAL_USER="${SUDO_USER:-$USER}" +REAL_GROUP=$(id -gn "$REAL_USER" 2>/dev/null || echo "$REAL_USER") +sed "s/# User\/Group are set by bin/install (patched from SUDO_USER)/User=$REAL_USER\nGroup=$REAL_GROUP/" \ + "$ROOT/systemd/dispatch.service" > /etc/systemd/system/dispatch.service +chmod 644 /etc/systemd/system/dispatch.service # ─── Config (don't overwrite if it exists) ─────────────────────────────────── if [[ ! -f /etc/dispatch/env ]]; then - echo "[install] config → /etc/dispatch/env (edit with your API key)" + echo "[install] config → /etc/dispatch/env (run sudo bin/setup-env to populate)" install -Dm600 "$ROOT/systemd/dispatch.env" /etc/dispatch/env - echo " ⚠️ Edit /etc/dispatch/env and set DISPATCH_API_KEY before starting!" else echo "[install] config /etc/dispatch/env already exists — keeping" fi # ─── Data + log directories ────────────────────────────────────────────────── mkdir -p /var/lib/dispatch /var/log/dispatch +chown -R "$REAL_USER:$REAL_GROUP" /var/lib/dispatch /var/log/dispatch # ─── Enable + start ────────────────────────────────────────────────────────── systemctl daemon-reload |
