* Allow subservices to declare a script that will be run before

the server start.  Useful to initialise necessary state.

svn path=/nixos/trunk/; revision=10761
This commit is contained in:
Eelco Dolstra 2008-02-19 17:37:05 +00:00
parent 5d2435d460
commit 8b165fc1f4
3 changed files with 40 additions and 18 deletions

View File

@ -23,11 +23,26 @@ let
# a virtual host. # a virtual host.
adminAddr = if cfg.adminAddr != "" then cfg.adminAddr else mainCfg.adminAddr; adminAddr = if cfg.adminAddr != "" then cfg.adminAddr else mainCfg.adminAddr;
serverConfig = cfg; vhostConfig = cfg;
serverConfig = mainCfg;
fullConfig = config; # machine config fullConfig = config; # machine config
}; };
vhostOptions = import ./per-server-options.nix {
inherit (pkgs.lib) mkOption;
forMainServer = false;
};
vhosts = let
makeVirtualHost = cfgIn:
let
# Fill in defaults for missing options.
cfg = addDefaultOptionValues vhostOptions cfgIn;
in cfg;
in map makeVirtualHost cfg.virtualHosts;
callSubservices = serverInfo: defs: callSubservices = serverInfo: defs:
let f = svc: let f = svc:
let config = addDefaultOptionValues res.options svc.config; let config = addDefaultOptionValues res.options svc.config;
@ -36,9 +51,12 @@ let
in map f defs; in map f defs;
mainSubservices = callSubservices (makeServerInfo cfg) cfg.extraSubservices; # !!! callSubservices is expensive
subservicesFor = cfg: callSubservices (makeServerInfo cfg) cfg.extraSubservices;
allSubservices = mainSubservices; mainSubservices = subservicesFor mainCfg;
allSubservices = mainSubservices ++ pkgs.lib.concatMap subservicesFor vhosts;
# !!! should be in lib # !!! should be in lib
@ -293,20 +311,12 @@ let
NameVirtualHost *:* NameVirtualHost *:*
${let ${let
perServerOptions = import ./per-server-options.nix { makeVirtualHost = cfg: ''
inherit (pkgs.lib) mkOption; <VirtualHost *:*>
forMainServer = false; ${perServerConf false cfg}
}; </VirtualHost>
makeVirtualHost = vhostIn: '';
let in concatMapStrings makeVirtualHost vhosts}
# Fill in defaults for missing options.
vhost = addDefaultOptionValues perServerOptions vhostIn;
in ''
<VirtualHost *:*>
${perServerConf false vhost}
</VirtualHost>
'';
in concatMapStrings makeVirtualHost cfg.virtualHosts}
''; '';
@ -351,7 +361,13 @@ in
# server restarts, eventually preventing it from restarting # server restarts, eventually preventing it from restarting
# succesfully. # succesfully.
for i in $(${pkgs.utillinux}/bin/ipcs -s | grep ' ${cfg.user} ' | cut -f2 -d ' '); do for i in $(${pkgs.utillinux}/bin/ipcs -s | grep ' ${cfg.user} ' | cut -f2 -d ' '); do
${pkgs.utillinux}/bin/ipcrm -s $i ${pkgs.utillinux}/bin/ipcrm -s $i
done
# Run the startup hooks for the subservices.
for i in ${toString (map (svn: svn.startupScript) allSubservices)}; do
echo Running Apache startup hook $i...
$i
done done
end script end script

View File

@ -87,6 +87,7 @@ in {
globalEnvVars = []; globalEnvVars = [];
extraServerPath = []; extraServerPath = [];
extraPath = []; extraPath = [];
startupScript = null;
options = { options = {

View File

@ -51,6 +51,8 @@ let
inherit (serverInfo) canonicalName; inherit (serverInfo) canonicalName;
inherit (serverInfo.serverConfig) user group;
# Urgh, most of these are dependencies of Email::Send, should figure them out automatically. # Urgh, most of these are dependencies of Email::Send, should figure them out automatically.
perlFlags = map (x: "-I${x}/lib/site_perl") [ perlFlags = map (x: "-I${x}/lib/site_perl") [
pkgs.perlBerkeleyDB pkgs.perlEmailSend pkgs.perlEmailSimple pkgs.perlBerkeleyDB pkgs.perlEmailSend pkgs.perlEmailSimple
@ -337,6 +339,9 @@ in {
extraPath = [scripts]; extraPath = [scripts];
startupScript = "${scripts}/bin/svn-server-startup-hook.sh";
options = { options = {
urlPrefix = mkOption { urlPrefix = mkOption {