diff options
-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 | } |