From 936abbef9d51992d53f9d24d87abb72fe823eab7 Mon Sep 17 00:00:00 2001 From: Florian Schmidt Date: Mon, 16 Nov 2026 15:31:01 +0100 Subject: [PATCH] feat(deploy): install the update trigger units (#15) shellbook-update.path starts the oneshot shellbook-update.service, which runs the fixed root-owned updater and logs to /var/log/shellbook-update.log. --- deploy/README.md | 8 ++++++++ deploy/install.sh | 28 ++++++++++++++++++++++++++++ deploy/test/install-script.test.sh | 15 ++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/deploy/README.md b/deploy/README.md index 2b46d44..cddb0bb 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -49,6 +49,14 @@ scripts from `/opt/shellbook`, which the service user (and the terminal panel) can modify. A failed build leaves the running service in place; check `journalctl -u shellbook`. +Settings → Updates shows the installed commit, checks the repository for new +commits, and starts the same update with **Update now**, following its output +through the restart. The button needs the trigger units the installer adds +(`shellbook-update.path` watches `/var/lib/shellbook/update-request` and starts +`shellbook-update.service` as root; output in `/var/log/shellbook-update.log`). Older +installations get them with one `shellbook-update` run from the CLI. If the button +does nothing, check `systemctl status shellbook-update.path shellbook-update`. + Configuration is `/etc/shellbook/env`; data is `/var/lib/shellbook` (back it up along with workspace and service-user home). `SHELLBOOK_SESSION_SECONDS` defaults to 2592000 (30 days). Cookies survive restart. Logout clears the browser cookie; diff --git a/deploy/install.sh b/deploy/install.sh index 4cc7a95..edce639 100755 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -120,6 +120,33 @@ PATH=/home/shellbook/.local/bin:/usr/local/bin:/usr/bin:/bin EOF fi chmod 600 /etc/shellbook/env +# Updates from the web UI (#15). The service stays unprivileged and may only change a +# request file in its data directory; systemd then runs the fixed root-owned updater +# above. Its output goes to root-owned /var/log, readable by the service. +data_dir=$(sed -n 's/^SHELLBOOK_DATA_DIR=//p' /etc/shellbook/env) +[[ $data_dir =~ ^/[A-Za-z0-9._/-]+$ ]] || { echo 'Invalid SHELLBOOK_DATA_DIR' >&2; exit 1; } +cat > /etc/systemd/system/shellbook-update.service <<'EOF' +[Unit] +Description=Update ShellBook (requested from the web UI) + +[Service] +Type=oneshot +ExecStart=/usr/local/sbin/shellbook-update +StandardOutput=truncate:/var/log/shellbook-update.log +StandardError=inherit +TimeoutStartSec=30min +EOF +cat > /etc/systemd/system/shellbook-update.path < /etc/systemd/system/shellbook.service <<'EOF' [Unit] Description=ShellBook runbook server @@ -162,6 +189,7 @@ if [[ -n ${TS_AUTHKEY:-} ]]; then fi systemctl daemon-reload systemctl enable shellbook +systemctl enable --now shellbook-update.path systemctl restart shellbook # Wait until the server answers before reporting success. listen_host=$(sed -n 's/^SHELLBOOK_HOST=//p' /etc/shellbook/env) diff --git a/deploy/test/install-script.test.sh b/deploy/test/install-script.test.sh index f14087a..8e21c19 100755 --- a/deploy/test/install-script.test.sh +++ b/deploy/test/install-script.test.sh @@ -37,4 +37,17 @@ tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT [[ ! -e $tmp/w/notebooks/infra/lxc.md ]] || { echo 'offer_templates: deleted template came back' >&2; exit 1; } [[ $(sort "$tmp/offered" | tr '\n' ' ') == 'notebooks/a.md notebooks/infra/lxc.md ' ]] || { echo 'offer_templates: wrong list' >&2; exit 1; } ) -printf '9 install script checks passed\n' +# Updates from the web UI: the service only touches a request file; root runs the fixed updater. +unit_body() { sed -n "/^cat > \/etc\/systemd\/system\/$1 <<'\{0,1\}EOF'\{0,1\}$/,/^EOF$/p" "$dir/install.sh" | sed '1d;$d'; } +update_service=$(unit_body shellbook-update.service) +update_path=$(unit_body shellbook-update.path) +[[ -n $update_service && -n $update_path ]] || { echo 'install.sh: update units not generated' >&2; exit 1; } +grep -qxF 'ExecStart=/usr/local/sbin/shellbook-update' <<< "$update_service" || { echo 'update unit: wrong ExecStart' >&2; exit 1; } +grep -qxF 'Type=oneshot' <<< "$update_service" || { echo 'update unit: not oneshot' >&2; exit 1; } +[[ $update_service$update_path != */opt/shellbook* ]] || { echo 'update units: reference /opt/shellbook' >&2; exit 1; } +# Root writes its output only below root-owned /var/log, never into the service user's data dir. +grep -qxF 'StandardOutput=truncate:/var/log/shellbook-update.log' <<< "$update_service" || { echo 'update unit: log not in /var/log' >&2; exit 1; } +grep -qxF 'PathChanged=$data_dir/update-request' <<< "$update_path" || { echo 'update path unit: wrong request file' >&2; exit 1; } +grep -qxF 'Unit=shellbook-update.service' <<< "$update_path" || { echo 'update path unit: wrong unit' >&2; exit 1; } +grep -qxF 'systemctl enable --now shellbook-update.path' "$dir/install.sh" || { echo 'install.sh: update trigger not enabled' >&2; exit 1; } +printf '17 install script checks passed\n'