From 6a4209475bb41ba1646c3465ad6982eb3755d1b0 Mon Sep 17 00:00:00 2001 From: twentyOne2x Date: Fri, 17 Jul 2026 23:16:41 +0200 Subject: [PATCH] Skip privileged systemd work when units already match (#181) --- deploy/auto-deploy.sh | 24 +++++++++++++++++------- tests/test_teleo_agent_systemd.py | 3 +++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/deploy/auto-deploy.sh b/deploy/auto-deploy.sh index cc2da8c..d4399f4 100755 --- a/deploy/auto-deploy.sh +++ b/deploy/auto-deploy.sh @@ -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 diff --git a/tests/test_teleo_agent_systemd.py b/tests/test_teleo_agent_systemd.py index 2d2f643..4643c29 100644 --- a/tests/test_teleo_agent_systemd.py +++ b/tests/test_teleo_agent_systemd.py @@ -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