diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-04-22 22:48:13 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2020-04-25 00:04:58 +0200 |
commit | 694a90f7b6eb4dd09004c7358ca8e25fe6b08b87 (patch) | |
tree | cd3953a6c699746db596c9c5d77818a97718fd25 | |
parent | 05afd3cf6fa233b95103704c94814635873b7414 (diff) | |
download | NUR-694a90f7b6eb4dd09004c7358ca8e25fe6b08b87.tar.gz NUR-694a90f7b6eb4dd09004c7358ca8e25fe6b08b87.tar.zst NUR-694a90f7b6eb4dd09004c7358ca8e25fe6b08b87.zip |
Reload httpd service instead of restarting it
-rw-r--r-- | modules/websites/default.nix | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/modules/websites/default.nix b/modules/websites/default.nix index d5a0f635..837d838b 100644 --- a/modules/websites/default.nix +++ b/modules/websites/default.nix | |||
@@ -1,4 +1,4 @@ | |||
1 | { lib, config, ... }: with lib; | 1 | { lib, config, pkgs, ... }: with lib; |
2 | let | 2 | let |
3 | cfg = config.services.websites; | 3 | cfg = config.services.websites; |
4 | in | 4 | in |
@@ -274,4 +274,42 @@ in | |||
274 | (name: path: "ln -s ${path} $out/${cfg.webappDirsName}/${name}") cfg.webappDirs) | 274 | (name: path: "ln -s ${path} $out/${cfg.webappDirsName}/${name}") cfg.webappDirs) |
275 | } | 275 | } |
276 | ''; | 276 | ''; |
277 | |||
278 | config.systemd.services = let | ||
279 | package = httpdName: config.services.httpd.${httpdName}.package.out; | ||
280 | cfgFile = httpdName: config.services.httpd.${httpdName}.configFile; | ||
281 | serviceChange = attrsets.mapAttrs' (name: icfg: | ||
282 | attrsets.nameValuePair | ||
283 | "httpd${icfg.httpdName}" { | ||
284 | stopIfChanged = false; | ||
285 | serviceConfig.ExecStart = | ||
286 | lib.mkForce "@${package icfg.httpdName}/bin/httpd httpd -f /etc/httpd/httpd_${icfg.httpdName}.conf"; | ||
287 | serviceConfig.ExecStop = | ||
288 | lib.mkForce "${package icfg.httpdName}/bin/httpd -f /etc/httpd/httpd_${icfg.httpdName}.conf -k graceful-stop"; | ||
289 | serviceConfig.ExecReload = | ||
290 | lib.mkForce "${package icfg.httpdName}/bin/httpd -f /etc/httpd/httpd_${icfg.httpdName}.conf -k graceful"; | ||
291 | } | ||
292 | ) cfg.env; | ||
293 | serviceReload = attrsets.mapAttrs' (name: icfg: | ||
294 | attrsets.nameValuePair | ||
295 | "httpd${icfg.httpdName}-config-reload" { | ||
296 | wants = [ "httpd${icfg.httpdName}.service" ]; | ||
297 | wantedBy = [ "multi-user.target" ]; | ||
298 | restartTriggers = [ (cfgFile icfg.httpdName) ]; | ||
299 | # commented, because can cause extra delays during activate for this config: | ||
300 | # services.nginx.virtualHosts."_".locations."/".proxyPass = "http://blabla:3000"; | ||
301 | # stopIfChanged = false; | ||
302 | serviceConfig.Type = "oneshot"; | ||
303 | serviceConfig.TimeoutSec = 60; | ||
304 | script = '' | ||
305 | if ${pkgs.systemd}/bin/systemctl -q is-active httpd${icfg.httpdName}.service ; then | ||
306 | ${package icfg.httpdName}/bin/httpd -f /etc/httpd/httpd_${icfg.httpdName}.conf -t && \ | ||
307 | ${pkgs.systemd}/bin/systemctl reload httpd${icfg.httpdName}.service | ||
308 | fi | ||
309 | ''; | ||
310 | serviceConfig.RemainAfterExit = true; | ||
311 | } | ||
312 | ) cfg.env; | ||
313 | in | ||
314 | serviceChange // serviceReload; | ||
277 | } | 315 | } |