Unverified Commit 15be453e authored by Will Fancher's avatar Will Fancher Committed by GitHub
Browse files

switch-to-configuration: Better handling of socket-activated units (#359724)

parents b25a2b5f bc1cfec9
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -58,11 +58,16 @@ checks:
    before the activation script is run. This behavior is different when the
    service is socket-activated, as outlined in the following steps.

  - The last thing that is taken into account is whether the unit is a service
    and socket-activated. If `X-StopIfChanged` is **not** set, the service
    is **restart**ed with the others. If it is set, both the service and the
    socket are **stop**ped and the socket is **start**ed, leaving socket
    activation to start the service when it's needed.
  - The last thing that is taken into account is whether the unit is a
    service and socket-activated. A correspondence between a
    `.service` and its `.socket` unit is detected automatically, but
    services can **opt out** of that detection by setting
    `X-NotSocketActivated` to `yes` in their `[Service]`
    section. Otherwise, if `X-StopIfChanged` is **not** set, the
    service is **restart**ed with the others. If it is set, both the
    service and the socket are **stop**ped and the socket is
    **start**ed, leaving socket activation to start the service when
    it's needed.

## Sysinit reactivation {#sec-sysinit-reactivation}

+3 −0
Original line number Diff line number Diff line
@@ -579,6 +579,9 @@ in rec {
      '' else "")
       + optionalString (def ? stopIfChanged && !def.stopIfChanged) ''
         X-StopIfChanged=false
      ''
       + optionalString (def ? notSocketActivated && def.notSocketActivated) ''
         X-NotSocketActivated=true
      '' + attrsToSection def.serviceConfig);
    };

+12 −0
Original line number Diff line number Diff line
@@ -535,6 +535,18 @@ in rec {
        '';
      };

      notSocketActivated = mkOption {
        type = types.bool;
        default = false;
        description = ''
          If set, a changed unit is never assumed to be
          socket-activated on configuration switch, even if
          it might have associated socket units. Instead, the unit
          will be restarted (or stopped/started) as if it had no
          associated sockets.
        '';
      };

      startAt = mkOption {
        type = with types; either str (listOf str);
        default = [];
+4 −4
Original line number Diff line number Diff line
@@ -459,10 +459,10 @@ in
      fi
    '';

    systemd.services.systemd-udevd =
      { restartTriggers = [ config.environment.etc."udev/rules.d".source ];
    systemd.services.systemd-udevd = {
      restartTriggers = [ config.environment.etc."udev/rules.d".source ];
      notSocketActivated = true;
    };

  };

  imports = [
+7 −0
Original line number Diff line number Diff line
@@ -544,6 +544,13 @@ sub handle_modified_unit { ## no critic(Subroutines::ProhibitManyArgs, Subroutin
                    }
                }

                if (parse_systemd_bool(\%new_unit_info, "Service", "X-NotSocketActivated", 0)) {
                    # If the unit explicitly opts out of socket
                    # activation, restart it as if it weren't (but do
                    # restart its sockets, that's fine):
                    $socket_activated = 0;
                }

                # If the unit is not socket-activated, record
                # that this unit needs to be started below.
                # We write this to a file to ensure that the
Loading