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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/systemd: Support notify-reload service Type #288821

Merged
merged 1 commit into from Feb 19, 2024

Conversation

infinisil
Copy link
Member

Description of changes

Support for this was added in systemd 253:
https://github.com/systemd/systemd/releases/tag/v253

But the NixOS module never started supporting it.

I discovered this in Nix Hour 62

Things done

Tested that notify-reload works correctly:

{ pkgs, config, ... }:
{

  # This file determines what the service prints,
  # changing the text just requires a reload of the service, not a restart!
  environment.etc.output.source =
    pkgs.writeText "output" "Hello Silvan!";

  systemd.services.myService = {
    serviceConfig.Type = "notify-reload";
    # Not necessary with notify-reload and the systemd-notify below!
    #serviceConfig.ExecReload = "${lib.getBin pkgs.coreutils}/bin/kill -HUP $MAINPID";
    reloadTriggers = [ config.environment.etc.output.source ];
    wantedBy = [ "multi-user.target" ];
    script = ''

      outputFile=$(mktemp)
      loadOutput() {
        echo "Loading output"
        cp -f /etc/output "$outputFile"
      }
      reloadOutput() {
        systemd-notify --reloading
        loadOutput
        systemd-notify --ready
      }
      loadOutput
      trap reloadOutput HUP

      trap 'echo "Stopping"' EXIT
      echo "Starting"

      cat "$outputFile"
      systemd-notify --ready
      while true; do
        sleep 5
        cat "$outputFile"
      done
    '';
  };

}

Add a 馃憤 reaction to pull requests you find important.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-54/39990/1

@arianvp arianvp merged commit 8986caf into NixOS:master Feb 19, 2024
22 checks passed
@infinisil infinisil deleted the systemd-notify-reload branch February 19, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants