diff --git a/deploy/auto-deploy.sh b/deploy/auto-deploy.sh index 7fa799b..4f27f04 100755 --- a/deploy/auto-deploy.sh +++ b/deploy/auto-deploy.sh @@ -94,18 +94,25 @@ add_restart() { *) RESTART="$RESTART $1" ;; esac } +add_restart_if_unit_exists() { + if systemctl list-units --all --full "$1.service" --no-legend 2>/dev/null | grep -q .; then + add_restart "$1" + fi +} if [ "$OLD_SHA" != "none" ]; then if git diff --name-only "$OLD_SHA" "$NEW_SHA" -- lib/ teleo-pipeline.py reweave.py telegram/ 2>/dev/null | grep -q '\.py$'; then add_restart teleo-pipeline fi if git diff --name-only "$OLD_SHA" "$NEW_SHA" -- telegram/ 2>/dev/null | grep -q '\.py$'; then add_restart teleo-agent@leo + add_restart_if_unit_exists teleo-agent@leo-wallet-test fi if git diff --name-only "$OLD_SHA" "$NEW_SHA" -- diagnostics/ 2>/dev/null | grep -q '\.py$'; then add_restart teleo-diagnostics fi else RESTART="teleo-pipeline teleo-diagnostics teleo-agent@leo" + add_restart_if_unit_exists teleo-agent@leo-wallet-test fi if [ -n "$RESTART" ]; then diff --git a/deploy/deploy.sh b/deploy/deploy.sh index d42135b..216ace5 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -104,6 +104,6 @@ echo "Deploy complete." if $RESTART; then echo "" echo "=== Restarting services ===" - ssh "$VPS_HOST" "sudo systemctl restart teleo-pipeline teleo-diagnostics" + ssh "$VPS_HOST" "sudo systemctl restart teleo-pipeline teleo-diagnostics teleo-agent@leo; if systemctl list-units --all --full teleo-agent@leo-wallet-test.service --no-legend | grep -q .; then sudo systemctl restart teleo-agent@leo-wallet-test; fi" echo "Services restarted." fi diff --git a/tests/test_teleo_agent_systemd.py b/tests/test_teleo_agent_systemd.py index 9debbec..11fe699 100644 --- a/tests/test_teleo_agent_systemd.py +++ b/tests/test_teleo_agent_systemd.py @@ -9,3 +9,12 @@ def test_teleo_agent_template_supports_optional_per_agent_env_file(): assert "Environment=PYTHONUNBUFFERED=1" in unit assert "EnvironmentFile=-/opt/teleo-eval/secrets/teleo-agent-%i.env" in unit + + +def test_deploy_scripts_restart_wallet_test_agent_when_present(): + auto_deploy = (REPO_ROOT / "deploy" / "auto-deploy.sh").read_text() + manual_deploy = (REPO_ROOT / "deploy" / "deploy.sh").read_text() + + assert "add_restart_if_unit_exists teleo-agent@leo-wallet-test" in auto_deploy + assert 'systemctl list-units --all --full "$1.service"' in auto_deploy + assert "teleo-agent@leo-wallet-test" in manual_deploy