Skip privileged systemd work when units already match (#181)
Some checks are pending
CI / lint-and-test (push) Waiting to run

This commit is contained in:
twentyOne2x 2026-07-17 23:16:41 +02:00 committed by GitHub
parent 415669c2e4
commit 6a4209475b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 7 deletions

View file

@ -187,17 +187,27 @@ done
log "Files synced"
if [ "$OLD_SHA" = "none" ] || git diff --name-only "$OLD_SHA" "$NEW_SHA" -- systemd/ 2>/dev/null | grep -q .; then
log "Installing systemd units"
SYSTEMD_CHANGED=false
for unit in systemd/*.service systemd/*.timer; do
[ -f "$unit" ] || continue
installed_unit="$SYSTEMD_DIR/$(basename "$unit")"
if [ -f "$installed_unit" ] && cmp -s "$unit" "$installed_unit"; then
continue
fi
SYSTEMD_CHANGED=true
log "Installing changed systemd unit: $(basename "$unit")"
sudo install -m 0644 "$unit" "$SYSTEMD_DIR/$(basename "$unit")"
done
sudo systemctl daemon-reload
if [ -f systemd/teleo-auto-deploy.timer ]; then
sudo systemctl enable --now teleo-auto-deploy.timer >/dev/null
fi
if [ -f systemd/teleo-agent-healthcheck.timer ]; then
sudo systemctl enable --now teleo-agent-healthcheck.timer >/dev/null
if $SYSTEMD_CHANGED; then
sudo systemctl daemon-reload
if [ -f systemd/teleo-auto-deploy.timer ]; then
sudo systemctl enable --now teleo-auto-deploy.timer >/dev/null
fi
if [ -f systemd/teleo-agent-healthcheck.timer ]; then
sudo systemctl enable --now teleo-agent-healthcheck.timer >/dev/null
fi
else
log "Systemd units already match the repository; skipping privileged installation"
fi
fi

View file

@ -95,6 +95,9 @@ def test_deploy_scripts_install_systemd_units_and_enable_agent_healthcheck():
manual_deploy = (REPO_ROOT / "deploy" / "deploy.sh").read_text()
assert 'SYSTEMD_DIR="/etc/systemd/system"' in auto_deploy
assert 'cmp -s "$unit" "$installed_unit"' in auto_deploy
assert "if $SYSTEMD_CHANGED; then" in auto_deploy
assert "Systemd units already match the repository; skipping privileged installation" in auto_deploy
assert 'sudo install -m 0644 "$unit" "$SYSTEMD_DIR/$(basename "$unit")"' in auto_deploy
assert "sudo systemctl daemon-reload" in auto_deploy
assert "sudo systemctl enable --now teleo-agent-healthcheck.timer" in auto_deploy