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/setup-env | |
| 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/setup-env')
| -rwxr-xr-x | bin/setup-env | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/bin/setup-env b/bin/setup-env index 8baf326..aeeda10 100755 --- a/bin/setup-env +++ b/bin/setup-env @@ -26,22 +26,26 @@ fi # Extract values from .env source "$ENV_FILE" -# Resolve the real user's home dir (for skills discovery — the skills extension -# scans ~/.skills/ via os.homedir(); under systemd as root this would be /root) +# Resolve the real user's home dir (the service runs as this user — see bin/install) REAL_USER="${SUDO_USER:-$USER}" +REAL_GROUP=$(id -gn "$REAL_USER" 2>/dev/null || echo "$REAL_USER") REAL_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6) if [[ -z "$REAL_HOME" ]]; then echo "setup-env: could not resolve home for user '$REAL_USER'" >&2 exit 1 fi +# Ensure data dirs are owned by the real user (the service runs as them) +mkdir -p /var/lib/dispatch /var/log/dispatch +chown -R "$REAL_USER:$REAL_GROUP" /var/lib/dispatch /var/log/dispatch + # Write the system env file tee /etc/dispatch/env > /dev/null << EOF # /etc/dispatch/env — Dispatch server configuration (systemd EnvironmentFile) # Generated by bin/setup-env from $ENV_FILE # Edit manually, then: systemctl restart dispatch -# ─── User environment (skills discovery uses \$HOME/.skills/) ──────────────── +# ─── User environment (service runs as $REAL_USER, homedir is correct) ─────── HOME=$REAL_HOME # ─── Ports ─────────────────────────────────────────────────────────────────── |
