feat: auto-defer systemctl restart/start/reload for unordered modules#64
Draft
troglodyne-bot wants to merge 1 commit into
Draft
Conversation
Closes Troglodyne-Internet-Widgets#32. Modules with `order` set in recipes.yaml run their systemctl calls immediately during `make` (they're dependencies, everything must be ready before other targets start). Modules without `order` now have bare `systemctl restart/start/reload` calls automatically wrapped in `queue_postrun_task` by `_defer_systemctl_calls` in `new_config`. This defers service starts until post_install, so services come up only after the entire provisioning run completes. Template authors no longer need to manually write `queue_postrun_task systemctl` for the common case. Exceptions: - `systemctl daemon-reload` / `enable` / `stop` / `disable` / `mask`: left immediate — safe idempotent setup ops that don't start services. - tpsgi: `daemon-reload` and `enable` remain explicitly queued because they must follow the queued `build_service` task that creates the unit file. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
What
new_confignow automatically wraps baresystemctl restart/start/reloadcalls inqueue_postrun_taskfor any recipe module that has noorderdefined in recipes.yaml.Why
Closes #32. Service restarts during provisioning are fragile — they fire before all config is in place and before dependent services are ready. The existing workaround was for every template author to manually write
[% script_dir %]/queue_postrun_task systemctl restart foo, which was easy to forget and created boilerplate noise.The
orderkey already signals intent: an ordered module (e.g.nostubresolver: order: 0) runs first because others depend on it, so its service calls are correctly left immediate. Unordered modules have no such urgency and should always defer.How
_defer_systemctl_calls($fragment, $script_dir)post-processes each rendered module fragment: replacessystemctl (restart|start|reload)with$script_dir/queue_postrun_task systemctl $1. A fixed-width lookbehind ((?<!queue_postrun_task )) guards against double-deferral.daemon-reload,enable,stop,disable,maskare intentionally left immediate — safe setup ops that don't start services.tpsgikeeps explicitqueue_postrun_task systemctl daemon-reload/enablebecausebuild_service(which creates the unit file) is itself queued — ordering dependency is real.[% script_dir %]/queue_postrun_task systemctl restart/start/reloadwrappers.Testing
8 unit tests in Perl for
_defer_systemctl_calls: bare restart/start/reload deferred, already-deferred not double-deferred, daemon-reload/enable/stop not deferred,--userflag not matched.