2010-01-11 16:58:15 +01:00
|
|
|
{ pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
backend =
|
2010-01-11 16:58:15 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
{
|
2010-03-11 18:02:53 +01:00
|
|
|
services.openssh.enable = true;
|
2010-01-11 16:58:15 +01:00
|
|
|
|
|
|
|
services.httpd.enable = true;
|
|
|
|
services.httpd.adminAddr = "foo@example.org";
|
|
|
|
services.httpd.documentRoot = "${pkgs.valgrind}/share/doc/valgrind/html";
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nodes =
|
|
|
|
{ proxy =
|
|
|
|
{ config, pkgs, nodes, ... }:
|
|
|
|
|
|
|
|
{
|
|
|
|
services.httpd.enable = true;
|
|
|
|
services.httpd.adminAddr = "bar@example.org";
|
|
|
|
services.httpd.extraModules = ["proxy_balancer"];
|
|
|
|
|
|
|
|
services.httpd.extraConfig =
|
|
|
|
''
|
|
|
|
ExtendedStatus on
|
|
|
|
|
|
|
|
<Location /server-status>
|
|
|
|
Order deny,allow
|
|
|
|
Allow from all
|
|
|
|
SetHandler server-status
|
|
|
|
</Location>
|
|
|
|
|
|
|
|
<Proxy balancer://cluster>
|
|
|
|
Allow from all
|
|
|
|
BalancerMember http://${nodes.backend1.config.networking.hostName} retry=0
|
|
|
|
BalancerMember http://${nodes.backend2.config.networking.hostName} retry=0
|
|
|
|
</Proxy>
|
|
|
|
|
|
|
|
ProxyStatus full
|
|
|
|
ProxyPass /server-status !
|
|
|
|
ProxyPass / balancer://cluster/
|
|
|
|
ProxyPassReverse / balancer://cluster/
|
|
|
|
|
|
|
|
# For testing; don't want to wait forever for dead backend servers.
|
|
|
|
ProxyTimeout 5
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
backend1 = backend;
|
|
|
|
backend2 = backend;
|
|
|
|
|
|
|
|
client = { config, pkgs, ... }: { };
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
|
|
|
startAll;
|
|
|
|
|
2012-10-24 18:22:53 +02:00
|
|
|
$proxy->waitForUnit("httpd");
|
|
|
|
$backend1->waitForUnit("httpd");
|
|
|
|
$backend2->waitForUnit("httpd");
|
2010-01-11 16:58:15 +01:00
|
|
|
|
|
|
|
# With the back-ends up, the proxy should work.
|
2012-10-24 18:22:53 +02:00
|
|
|
$client->succeed("curl --fail http://proxy/");
|
2010-01-11 16:58:15 +01:00
|
|
|
|
2012-10-24 18:22:53 +02:00
|
|
|
$client->succeed("curl --fail http://proxy/server-status");
|
2010-01-11 16:58:15 +01:00
|
|
|
|
|
|
|
# Block the first back-end.
|
|
|
|
$backend1->block;
|
|
|
|
|
|
|
|
# The proxy should still work.
|
2012-10-24 18:22:53 +02:00
|
|
|
$client->succeed("curl --fail http://proxy/");
|
2010-01-11 16:58:15 +01:00
|
|
|
|
2012-10-24 18:22:53 +02:00
|
|
|
$client->succeed("curl --fail http://proxy/");
|
2010-01-11 16:58:15 +01:00
|
|
|
|
|
|
|
# Block the second back-end.
|
|
|
|
$backend2->block;
|
|
|
|
|
|
|
|
# Now the proxy should fail as well.
|
2012-10-24 18:22:53 +02:00
|
|
|
$client->fail("curl --fail http://proxy/");
|
2010-01-11 16:58:15 +01:00
|
|
|
|
|
|
|
# But if the second back-end comes back, the proxy should start
|
|
|
|
# working again.
|
|
|
|
$backend2->unblock;
|
2012-10-24 18:22:53 +02:00
|
|
|
$client->succeed("curl --fail http://proxy/");
|
2010-01-11 16:58:15 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
}
|