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.
This commit is contained in:
Florian Schmidt
2026-11-16 15:31:01 +01:00
parent 2fc5f99f59
commit 936abbef9d
3 changed files with 50 additions and 1 deletions
+8
View File
@@ -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 can modify. A failed build leaves the running service in place; check
`journalctl -u shellbook`. `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 Configuration is `/etc/shellbook/env`; data is `/var/lib/shellbook` (back it up
along with workspace and service-user home). `SHELLBOOK_SESSION_SECONDS` defaults along with workspace and service-user home). `SHELLBOOK_SESSION_SECONDS` defaults
to 2592000 (30 days). Cookies survive restart. Logout clears the browser cookie; to 2592000 (30 days). Cookies survive restart. Logout clears the browser cookie;
+28
View File
@@ -120,6 +120,33 @@ PATH=/home/shellbook/.local/bin:/usr/local/bin:/usr/bin:/bin
EOF EOF
fi fi
chmod 600 /etc/shellbook/env 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 <<EOF
[Unit]
Description=Start a ShellBook update when the web UI requests one
[Path]
PathChanged=$data_dir/update-request
Unit=shellbook-update.service
[Install]
WantedBy=paths.target
EOF
cat > /etc/systemd/system/shellbook.service <<'EOF' cat > /etc/systemd/system/shellbook.service <<'EOF'
[Unit] [Unit]
Description=ShellBook runbook server Description=ShellBook runbook server
@@ -162,6 +189,7 @@ if [[ -n ${TS_AUTHKEY:-} ]]; then
fi fi
systemctl daemon-reload systemctl daemon-reload
systemctl enable shellbook systemctl enable shellbook
systemctl enable --now shellbook-update.path
systemctl restart shellbook systemctl restart shellbook
# Wait until the server answers before reporting success. # Wait until the server answers before reporting success.
listen_host=$(sed -n 's/^SHELLBOOK_HOST=//p' /etc/shellbook/env) listen_host=$(sed -n 's/^SHELLBOOK_HOST=//p' /etc/shellbook/env)
+14 -1
View File
@@ -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; } [[ ! -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; } [[ $(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'