From afdde930bbd41bc87521ed0b010b2e1710638859 Mon Sep 17 00:00:00 2001 From: jerryfane Date: Fri, 6 Nov 2026 19:50:42 +0100 Subject: [PATCH] fix(deploy): give shell stages HOME under systemd (#24) --- README.md | 6 +++++- deploy/stagehand.service | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d8829a..0a2b24b 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ Unit files and an example config are in [`deploy/`](deploy/). - To stop the run without failing it, a stage can write `{"decision":"blocked","summary":"…","needs":["…"]}` to `$STAGEHAND_RESULT`. - **What a shell stage sees:** - - `PATH`, `HOME`, `LANG` and `TZ` from the runner; + - `PATH`, `HOME` and `TZ` from the runner (each only if the runner has it), and `LANG=C.UTF-8`; - `STAGEHAND_PIPELINE`, `STAGEHAND_RUN_ID`, `STAGEHAND_STAGE`, `STAGEHAND_ATTEMPT`; - `STAGEHAND_WORK`, the run's shared work directory, where stages pass files to each other; - `STAGEHAND_RESULT`; @@ -442,6 +442,7 @@ After=network-online.target Wants=network-online.target [Service] +Environment=HOME=/root ExecStart=/usr/local/bin/stagehand --home /var/lib/stagehand serve --status-addr 127.0.0.1:8795 Restart=on-failure KillMode=control-group @@ -455,6 +456,9 @@ WantedBy=multi-user.target `interrupted`, so they can be resumed later. - **Crashes:** `KillMode=control-group` makes systemd kill any stage processes left behind if the runner crashes. +- **`HOME`:** systemd sets no `HOME` for a root service without `User=`, and stages get the + runner's `HOME` (or none). Set it, as above, if stages run tools that keep credentials there + (omp, herdr, gh); otherwise they work under `stagehand run` but fail under `serve`. ### Upgrading and rolling back diff --git a/deploy/stagehand.service b/deploy/stagehand.service index 18121ee..4034cb0 100644 --- a/deploy/stagehand.service +++ b/deploy/stagehand.service @@ -8,6 +8,9 @@ Wants=network-online.target stagehand-hetzner2-tunnel.service stagehand-gateway- [Service] Type=simple Environment=STAGEHAND_HOME=/var/lib/stagehand +# systemd sets no HOME for a root service without User=; shell stages inherit +# this one (tools such as omp, herdr and gh find their credentials through it). +Environment=HOME=/root Environment=STAGEHAND_CONFIG=/etc/stagehand/config.yaml # --trigger-addr: event intake (loopback only; needs events.secret_file in the config). ExecStart=/usr/local/bin/stagehand serve --status-addr 127.0.0.1:8797 --trigger-addr 127.0.0.1:8798