Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refresh service only based on drop-in file changes #406

Merged
merged 2 commits into from
Jun 2, 2024

Conversation

shieldwed
Copy link
Contributor

Pull Request (PR) description

Since multiple drop-in files of the same unit notify the same Systemd::Daemon_reload resource, changing a drop in file without notify_service still triggers a service refresh if at least one other drop-in file has notify_service set (default) regardless of it being changed.

Therefore, the Systemd::Daemon_reload should only be ordered before the Service but not notify it. The service will already be refreshed if the drop-in file changes and notify_service is set (default).

This Pull Request (PR) addresses the following issues

Consider the following Puppet code snippet with two drop-in files for the service nginx.service:

  systemd::dropin_file {
    default:
      unit => 'nginx.service',
      ;
    "restart.conf":
      notify_service => false,
      content        => @(EOT)
        [Service]
        Restart=on-failure
        | EOT
      ,
    ;
    "ulimit.conf":
      content => @(EOT)
        [Service]
        LimitNOFILE=4096
        | EOT
      ,
  }

On the first Puppet-run, this code will correctly refresh the service, as the ulimit.conf-file will be written. Once the drop-in files are in sync with this configuration, no more SystemD daemon reloads and service refreshes happen.

Now, changing the Restart configuration of nginx.service doesn't need the service itself to be restarted.

However, due to the second drop-in file specifying notify_service => true (default), this will lead to Systemd::Daemon_reload[$unit] being triggered (expected due to daemon_reload => true (default)), which then in turn triggers Service[nginx.service] and Service[nginx] if they exist.

Since multiple drop-in files of the same unit notify the same
Systemd::Daemon_reload resource, changing a drop in file without
notify_service still triggers a service refresh if at least one other
drop-in file has notify_service set (default) regardless of it being changed.

Therefore the Systemd::Daemon_reload should only be ordered before
the Service but not notify it.
@shieldwed
Copy link
Contributor Author

I am quite uncertain on how to test these changes. Especially since tests for absence of certain relationships seem to be asked for in this case.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably impossible to test due to rspec-puppet having different transitive dependencies than real Puppet: puppetlabs/rspec-puppet#35 and also missing matchers (puppetlabs/rspec-puppet#28).

@@ -81,15 +81,15 @@
File[$full_filename] ~> Service <| title == $unit or name == $unit |>

if $daemon_reload {
Systemd::Daemon_reload[$unit] ~> Service <| title == $unit or name == $unit |>
Systemd::Daemon_reload[$unit] -> Service <| title == $unit or name == $unit |>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this isn't a notify anymore, should this be around line 77 instead? I think the ordering is still correct. Same for the other case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look at this @ekohl. The conditions stay the same. The ordering of the Daemon_reload in relation to the Service still only needs to happen when both $notify_service and $daemon_reload are true.

@shieldwed shieldwed force-pushed the fix_service_dependency branch 2 times, most recently from d8a93f0 to c798ae1 Compare February 8, 2024 07:57
@shieldwed
Copy link
Contributor Author

shieldwed commented Feb 8, 2024

This probably impossible to test due to rspec-puppet having different transitive dependencies than real Puppet ...

I've implemented some tests for the changed cases. Can you please look at them again?

@shieldwed shieldwed requested a review from ekohl February 16, 2024 14:35
@shieldwed
Copy link
Contributor Author

@ekohl can you please have another look at this PR? Thank you

@TheMeier TheMeier added the enhancement New feature or request label Mar 28, 2024
@shieldwed
Copy link
Contributor Author

Can someone please have a look at this again (e.g. @bastelfreak or @TheMeier perhaps)? Thank you.

@TheMeier TheMeier merged commit 67fc2df into voxpupuli:master Jun 2, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants