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
+28
View File
@@ -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 <<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'
[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)