fix(stop): clean up systemd service and data on unit removal#773
Merged
fix(stop): clean up systemd service and data on unit removal#773
Conversation
On co-located machines with multiple github-runner charms, removing a unit left its systemd service file enabled. Systemd would restart the stale service, which — if the binary was still compatible — silently kept managing runners with outdated configuration. The stop hook now disables the service, removes the service file, reloads systemd, and cleans up the per-unit data and log files.
Replace 'per-unit' with 'the unit' and backtick-quote 'systemd'.
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the charm’s unit removal (stop hook) behavior to fully clean up per-unit systemd artifacts and on-disk state so co-located units don’t leave behind enabled/restarting stale services.
Changes:
- Add
manager_service.cleanup()to stop, disable, remove the unit systemd service file, reload systemd, and remove per-unit data/logs. - Switch the charm’s
_on_stophandler to callcleanup()instead ofstop(). - Add unit tests for
cleanup(), and bump manager version + changelog entry.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/manager_service.py |
Introduces cleanup() and per-unit data removal logic. |
src/charm.py |
Uses cleanup() during the stop hook. |
tests/unit/test_manager_service.py |
Adds coverage for cleanup success/idempotency/systemd error. |
tests/unit/test_charm.py |
Updates stop-hook assertion to expect cleanup(). |
github-runner-manager/pyproject.toml |
Bumps package version to 0.17.1. |
docs/changelog.md |
Records the unit-removal cleanup fix. |
Catch OSError from service file unlink in cleanup(), and replace shutil.rmtree(ignore_errors=True) with explicit FileNotFoundError handling so permission errors surface as RunnerManagerApplicationStopError.
Distinguish cleanup errors from stop errors in log output to make diagnosing unit removal failures easier.
Skip service_disable when the service file is already absent to ensure idempotent cleanup. Wrap log file unlink in OSError handling for consistent error reporting.
Reuse instance_service to build the service file path, removing duplicated naming logic. Rename charm test to reflect cleanup behavior.
Call service_disable regardless of service file presence to clean up dangling enablement symlinks from partial manual cleanup. Treat SystemdError from disable as non-fatal (log warning), matching the pattern in _disable_legacy_service().
yanksyoon
approved these changes
Mar 31, 2026
florentianayuwono
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Applicable spec: N/A
Overview
On unit removal (
stophook), disable and remove the per-unit systemd service file, reload the daemon, and clean up the per-unit data directory and log file.Rationale
On co-located machines (dedicated machine shared by multiple github-runner charms), removing a unit left its systemd service file enabled with
Restart=on-failure. Systemd would restart the stale service, and if the binary was still compatible (installed by another charm unit on the same machine), it silently kept managing runners with outdated configuration.Juju Events Changes
No new events. The existing
stophook handler now callsmanager_service.cleanup()instead ofmanager_service.stop().Module Changes
manager_service.py: Addedcleanup()(public) and_remove_unit_data()(private helper).cleanup()stops the service, disables it, removes the service file, reloads systemd, and removes the per-unit data dir and log file.charm.py:_on_stopcallscleanup()instead ofstop().Library Changes
None.
Checklist
github-runner-manager/pyproject.toml.