Skip to content

Run mod_watch in service.running when only enable changed - #70974

Open
mitar wants to merge 1 commit into
saltstack:masterfrom
mitar:service-running
Open

mitar wants to merge 1 commit into
saltstack:masterfrom
mitar:service-running

Conversation

@mitar

@mitar mitar commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

When service.running finds the service already running but has to enable or disable it, its normal run reports changes without restarting or reloading the service. A watch requisite then skips mod_watch, because the watching state made changes of its own, so a changed configuration file is not loaded.

This PR makes service.running return force_mod_watch: True in that case, the opt-in added by #68960, so that the state system runs mod_watch as well. Starting a service which was not running already loads its configuration, so the flag is not set then.

It also updates doc/ref/states/requisites.rst, which described this case as a limitation and recommended splitting service.running and service.enabled into separate states. The example of a state which opts in now points to service.running instead of docker_container.running, which is no longer part of Salt.

This change targets master because #68960 exists only there. The related fixes in #70972 remove force_mod_watch from state results; without them, a run which only enables the service shows the key in its result.

What issues does this PR fix or reference?

Fixes #47361. It was closed as not planned in October 2026, so I ask to reopen it.

Related issues, closed without a fix: #59688 (closed as expected behavior because of the requisites rule which #68960 made opt-in), #54952 and #55098.

Previous Behavior

httpd:
  service.running:
    - enable: True
    - watch:
      - file: httpd-config

httpd-config:
  file.managed:
    - name: /etc/httpd/conf/httpd.conf
    - source: salt://httpd/files/apache.conf

When httpd is running but disabled and the configuration file changes, the service is enabled but not restarted, so the new configuration is not loaded. A dry run (test=True) reports "Service is set to be restarted", which the real run then does not do.

New Behavior

The service is enabled and restarted (or reloaded with reload: True). A service which was already enabled, and a service which was not running, behave as before.

Tested on master with systemd as PID 1 (Ubuntu 24.04 container) and a test unit, detecting restarts with the unit's InvocationID:

Starting state Without this PR With this PR
disabled, running, config changes enabled, not restarted enabled and restarted
enabled, running, config changes restarted restarted
disabled, running, config unchanged enabled, not restarted enabled, not restarted
enabled, running, config unchanged no changes no changes

With reload: True and a unit whose ExecReload records each reload, the first case enables the service and reloads it once, without restarting it (its start time stays the same). Without this PR it is neither reloaded nor restarted.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

  • Docs: doc/ref/states/requisites.rst and the module documentation of salt/states/service.py.
  • Changelog: changelog/47361.fixed.md.
  • Tests written/updated: two unit tests in tests/pytests/unit/states/test_service.py, and a functional test in tests/pytests/functional/states/test_service.py which enables a running service while a watched file changes and checks with ExecMainStartTimestampMonotonic that systemd restarted it. With systemd and cron as root, all 4 functional service tests pass, and the new one fails without this change.

Commits signed with GPG?

Yes

When service.running finds the service already running but has to
enable or disable it, its normal run reports changes without restarting
or reloading the service. A watch requisite then skips mod_watch,
because the watching state made changes of its own, so a changed
configuration file is not loaded. A dry run still reports that the
service would be restarted, because enabling makes no changes in test
mode.

Set force_mod_watch in this case, so that the state system runs
mod_watch as well (saltstack#68960). Starting a service which was not running
already loads its configuration, so the flag is not set then.

Update the requisites documentation, which described this case as a
limitation and recommended splitting service.running and
service.enabled into separate states.

Fixes saltstack#47361
@mitar

mitar commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

BTW, I think this finally addresses one long standing issue with Salt which can now be properly addressed without workarounds one has to document for users to properly do. Now things just work as expected without surprises.

@dwoz dwoz added the test:full Run the full test suite label Nov 29, 2026

This branch was previously deployed

1 inactive deployment
ci — 6b5c992d Deployed Nov 29, 2026 by dwoz via Build Onedir Packages / Windows (amd64) #29763
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

2 participants