-
-
Notifications
You must be signed in to change notification settings - Fork 18k
nixos/switch-to-configuration: restart changed socket units #50340
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,28 +20,44 @@ in { | |
| description = "Number of processes to prefork."; | ||
| }; | ||
|
|
||
| socketType = mkOption { | ||
| type = types.enum [ "unix" "tcp" "tcp6" ]; | ||
| default = "unix"; | ||
| description = "Socket type: 'unix', 'tcp' or 'tcp6'."; | ||
| }; | ||
|
|
||
| socketAddress = mkOption { | ||
| type = types.str; | ||
| default = "/run/fcgiwrap.sock"; | ||
| example = "1.2.3.4:5678"; | ||
| description = "Socket address. In case of a UNIX socket, this should be its filesystem path."; | ||
| description = '' | ||
| Socket address as defined in | ||
| <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry> | ||
fpletz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for <literal>ListemStream</literal>. | ||
| ''; | ||
| }; | ||
|
|
||
| socketUser = mkOption { | ||
| type = types.str; | ||
| default = "root"; | ||
| description = "Owner of the socket if it is defined as a Unix socket."; | ||
| }; | ||
|
|
||
| socketGroup = mkOption { | ||
| type = types.str; | ||
| default = "root"; | ||
| description = "Group of the socket if it is defined as a Unix socket."; | ||
| }; | ||
|
|
||
| socketMode = mkOption { | ||
| type = types.str; | ||
| default = "0660"; | ||
| description = "File mode of the socket if it is defined as a Unix socket."; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest we don't bikeshed this PR on this discussion, but… Would it maybe make sense to make a |
||
| }; | ||
|
|
||
| user = mkOption { | ||
| type = types.nullOr types.str; | ||
| default = null; | ||
| type = types.str; | ||
| default = "nobody"; | ||
| description = "User permissions for the socket."; | ||
| }; | ||
|
|
||
| group = mkOption { | ||
| type = types.nullOr types.str; | ||
| default = null; | ||
| type = types.str; | ||
| default = "nogroup"; | ||
| description = "Group permissions for the socket."; | ||
| }; | ||
| }; | ||
|
|
@@ -50,23 +66,21 @@ in { | |
| config = mkIf cfg.enable { | ||
| systemd.services.fcgiwrap = { | ||
| after = [ "nss-user-lookup.target" ]; | ||
| wantedBy = optional (cfg.socketType != "unix") "multi-user.target"; | ||
|
|
||
| serviceConfig = { | ||
| ExecStart = "${pkgs.fcgiwrap}/sbin/fcgiwrap -c ${builtins.toString cfg.preforkProcesses} ${ | ||
| if (cfg.socketType != "unix") then "-s ${cfg.socketType}:${cfg.socketAddress}" else "" | ||
| }"; | ||
| } // (if cfg.user != null && cfg.group != null then { | ||
| ExecStart = "${pkgs.fcgiwrap}/sbin/fcgiwrap -c ${toString cfg.preforkProcesses}"; | ||
| User = cfg.user; | ||
| Group = cfg.group; | ||
| } else { } ); | ||
| }; | ||
| }; | ||
|
|
||
| systemd.sockets = if (cfg.socketType == "unix") then { | ||
| fcgiwrap = { | ||
| wantedBy = [ "sockets.target" ]; | ||
| socketConfig.ListenStream = cfg.socketAddress; | ||
| systemd.sockets.fcgiwrap = { | ||
| wantedBy = [ "sockets.target" ]; | ||
| socketConfig = { | ||
| ListenStream = cfg.socketAddress; | ||
| SocketUser = cfg.socketUser; | ||
| SocketGroup = cfg.socketGroup; | ||
| SocketMode = cfg.socketMode; | ||
| }; | ||
| } else { }; | ||
| }; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import ./make-test.nix ({ pkgs, lib, ... }: | ||
|
|
||
| let | ||
| helloScript = pkgs.writeShellScriptBin "hello" '' | ||
| echo "Status: 200 OK" | ||
| echo | ||
| echo "$out says: Hello World!" | ||
| ''; | ||
|
|
||
| mkServer = extraConfig: { ... }: | ||
| lib.mkMerge [ | ||
| { services.fcgiwrap.enable = true; | ||
| services.nginx.enable = true; | ||
| services.nginx.commonHttpConfig = '' | ||
| error_log syslog:server=unix:/dev/log; | ||
| access_log syslog:server=unix:/dev/log; | ||
| ''; | ||
| services.nginx.virtualHosts."_".locations."/".extraConfig = '' | ||
| fastcgi_param SCRIPT_FILENAME ${helloScript}/bin/hello; | ||
| fastcgi_pass unix:/run/fcgiwrap.sock; | ||
| ''; | ||
| } | ||
| extraConfig | ||
| ]; | ||
|
|
||
| in | ||
|
|
||
| { name = "fcgiwrap"; | ||
| meta = with pkgs.stdenv.lib.maintainers; | ||
| { maintainers = [ fpletz ]; }; | ||
|
|
||
| nodes = { | ||
| working = mkServer { | ||
| services.fcgiwrap.socketGroup = "nginx"; | ||
| }; | ||
|
|
||
| permissionfail = mkServer { | ||
| services.fcgiwrap.socketGroup = "root"; | ||
| }; | ||
| }; | ||
|
|
||
| testScript = { nodes, ... }: let | ||
| permissionfail = nodes.permissionfail.config.system.build.toplevel; | ||
| in '' | ||
| $working->start; | ||
|
|
||
| $working->waitForUnit("nginx"); | ||
| $working->waitForOpenPort("80"); | ||
| $working->succeed("curl http://localhost/ | tee /dev/stderr | grep 'Hello World!'"); | ||
|
|
||
| $working->succeed("${permissionfail}/bin/switch-to-configuration test"); | ||
| $working->fail("curl -f http://localhost/"); | ||
| ''; | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there also be a note about socket restarts in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah. you're right. Adding socking restart support is kind of a bugfix though. I'll add a paragraph.