Use systemd socket activation
This commit is contained in:
parent
ecb9d23d4c
commit
00decb5f92
1 changed files with 20 additions and 12 deletions
32
module.nix
32
module.nix
|
|
@ -29,19 +29,15 @@ in
|
|||
Whether to enable Strojnadzor
|
||||
";
|
||||
};
|
||||
hostname = mkOption {
|
||||
default = "localhost";
|
||||
description = "Listen to this hostname or ip.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 9000;
|
||||
description = "Listen on this port.";
|
||||
};
|
||||
stateDir = mkOption {
|
||||
default = "/var/lib/strojnadzor";
|
||||
type = types.str;
|
||||
description = "Strojnadzor data directory.";
|
||||
description = "Data directory.";
|
||||
};
|
||||
socketPath = mkOption {
|
||||
default = "/run/strojnadzor.sock";
|
||||
type = types.str;
|
||||
description = "UNIX socket path.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -65,15 +61,27 @@ in
|
|||
"d '${cfg.stateDir}/data' - strojnadzor strojnadzor - -"
|
||||
];
|
||||
|
||||
systemd.sockets.strojnadzor = {
|
||||
description = "Strojnadzor HTTP socket.";
|
||||
wantedBy = [ "sockets.target" ];
|
||||
socketConfig = {
|
||||
User = "nginx";
|
||||
Group = "nginx";
|
||||
ListenStream = "${cfg.socketPath}";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.strojnadzor = {
|
||||
description = "Strojnadzor HTTP server.";
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "strojnadzor.socket" ];
|
||||
serviceConfig = {
|
||||
Type = "notify";
|
||||
User = "strojnadzor";
|
||||
Group = "strojnadzor";
|
||||
ExecStartPre = "${strojnadzor}/bin/strojnadzor-admin migrate";
|
||||
ExecStart = "${strojnadzor}/bin/strojnadzor-admin runserver-gunicorn --bind ${cfg.hostname}:${toString cfg.port}";
|
||||
ExecStart = "${strojnadzor}/bin/strojnadzor-admin runserver-gunicorn";
|
||||
};
|
||||
environment.STROJNADZOR_DATA_DIR = "${cfg.stateDir}/data";
|
||||
environment.STROJNADZOR_STATIC_DIR = "${static}/static";
|
||||
|
|
@ -91,7 +99,7 @@ in
|
|||
'';
|
||||
locations."/static/".alias = "${static}/";
|
||||
locations."/" = {
|
||||
proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
||||
proxyPass = "http://unix:/${cfg.socketPath}";
|
||||
extraConfig = ''
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue