fix: regression in disable and stop sshd service#8596
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes Linux CSE service shutdown logic by avoiding expensive retry loops when a systemd unit doesn’t actually exist (notably sshd on Ubuntu), improving provisioning time without changing the functional outcome (missing units are still treated as non-fatal).
Changes:
- Update
systemctlDisableAndStopto gate stop/disable calls onsystemctl cat <unit>instead ofsystemctl list-units | grep.
djsly
approved these changes
May 27, 2026
djsly
approved these changes
May 27, 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.
There's the problem. On Ubuntu, sshd.service shows up in systemctl list-units --full --all (likely as "not-found" or "inactive"), so the guard check passes — but systemctl stop sshd fails every time with "not loaded."
It then retries 20 times with 5s sleep = 100 seconds wasted just on stop, plus another 100s on disable = ~3.3 minutes for a service that simply doesn't exist on Ubuntu.
The ssh call succeeds quickly (first try), but the sshd call burns through all retries pointlessly. The fix would be to either:
For the sshd call on Ubuntu (where it doesn't exist):
120s
Total: ~4 minutes wasted on sshd alone.
The ssh call succeeds on first try (1-2s), so the combined wall time for both lines is roughly 4 minutes.
list-unit-files only shows units with actual files on disk, unlike list-units --full --all which includes "not-found" phantom entries.
systemctl cat returns non-zero if the unit file doesn't exist — no grep needed.
Regression risk is very low. Here's why:
One minor thing to verify: systemctl cat has been available since systemd 209+ (Ubuntu 16.04+, all supported AzureLinux). No concern there.
No regression risk — it's strictly a performance improvement with identical functional outcome