Skip to content

Commit

Permalink
Merge pull request #1104 from flyingcircusio/PL-132901-fix-varnish-re…
Browse files Browse the repository at this point in the history
…load

webproxy/varnish: fix runtime/state dir issues and restart on unit changes
  • Loading branch information
dpausp committed Sep 19, 2024
2 parents 6185312 + 503e925 commit 2449914
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 3 additions & 7 deletions nixos/roles/webproxy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ in
serviceConfig = {
Type = "forking";
Restart = "always";
RuntimeDirectory = "varnish";
PIDFile = "/run/varnish/varnishncsa.pid";
RuntimeDirectory = "varnishncsa";
PIDFile = "/run/varnishncsa/varnishncsa.pid";
User = "varnish";
Group = "varnish";
ExecStart = "${cfg.package}/bin/varnishncsa -D -a -w /var/log/varnish.log -P /run/varnish/varnishncsa.pid";
ExecStart = "${cfg.package}/bin/varnishncsa -n ${cfg.stateDir} -D -a -w /var/log/varnish.log -P /run/varnishncsa/varnishncsa.pid";
ExecReload = "${kill} -HUP $MAINPID";
};
};
Expand All @@ -121,10 +121,6 @@ in
systemd.tmpfiles.rules = [
"d /etc/local/varnish 2775 varnish service"
"f /var/log/varnish.log 644 varnish varnish"
# Link the default dir expected by varnish tools to
# the actual location of the state dir. This makes the commands
# usable without specifying the -n option every time.
"L /run/varnishd - - - - ${cfg.stateDir}"
];

users.groups.varnish.members = [
Expand Down
15 changes: 11 additions & 4 deletions nixos/services/varnish/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ in {
services.varnish = {
enable = true;
enableConfigCheck = false;
extraCommandLine = lib.concatStringsSep " " [ cfg.extraCommandLine "-I ${commandsfile}" ];

stateDir = "/run/varnishd";
extraCommandLine = lib.concatStringsSep " " [ cfg.extraCommandLine "-I /etc/varnish/startup" ];
inherit (cfg) http_address;
config = ''
vcl 4.0;
Expand All @@ -120,14 +122,19 @@ in {
'';
};

environment.etc."varnish/startup".source = commandsfile;

systemd.services.varnish = let
vcfg = config.services.varnish;
in {
reloadIfChanged = true;
restartTriggers = [ cfg.extraCommandLine vcfg.package cfg.http_address ];
preStart = lib.mkBefore ''
rm -rf ${vcfg.stateDir}
'';
stopIfChanged = false;
reloadTriggers = [ commandsfile ];
reload = ''
vadm="${vcfg.package}/bin/varnishadm -n ${vcfg.stateDir}"
cat ${commandsfile} | $vadm
cat /etc/varnish/startup | $vadm
coldvcls=$($vadm vcl.list | grep " cold " | ${pkgs.gawk}/bin/awk {'print $5'})
Expand Down

0 comments on commit 2449914

Please sign in to comment.