From 8b165fc1f4f664074d344b1b6afc0ebcaecbeab0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 19 Feb 2008 17:37:05 +0000 Subject: [PATCH] * 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 --- upstart-jobs/apache-httpd/default.nix | 52 ++++++++++++++-------- upstart-jobs/apache-httpd/dist-manager.nix | 1 + upstart-jobs/apache-httpd/subversion.nix | 5 +++ 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/upstart-jobs/apache-httpd/default.nix b/upstart-jobs/apache-httpd/default.nix index 5c93a674da14..3efa1fc1a0ce 100644 --- a/upstart-jobs/apache-httpd/default.nix +++ b/upstart-jobs/apache-httpd/default.nix @@ -23,11 +23,26 @@ let # a virtual host. adminAddr = if cfg.adminAddr != "" then cfg.adminAddr else mainCfg.adminAddr; - serverConfig = cfg; + vhostConfig = cfg; + serverConfig = mainCfg; 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: let f = svc: let config = addDefaultOptionValues res.options svc.config; @@ -36,9 +51,12 @@ let 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 @@ -293,20 +311,12 @@ let NameVirtualHost *:* ${let - perServerOptions = import ./per-server-options.nix { - inherit (pkgs.lib) mkOption; - forMainServer = false; - }; - makeVirtualHost = vhostIn: - let - # Fill in defaults for missing options. - vhost = addDefaultOptionValues perServerOptions vhostIn; - in '' - - ${perServerConf false vhost} - - ''; - in concatMapStrings makeVirtualHost cfg.virtualHosts} + makeVirtualHost = cfg: '' + + ${perServerConf false cfg} + + ''; + in concatMapStrings makeVirtualHost vhosts} ''; @@ -351,7 +361,13 @@ in # server restarts, eventually preventing it from restarting # succesfully. 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 end script diff --git a/upstart-jobs/apache-httpd/dist-manager.nix b/upstart-jobs/apache-httpd/dist-manager.nix index 58db2b5ff865..966fdab9b857 100644 --- a/upstart-jobs/apache-httpd/dist-manager.nix +++ b/upstart-jobs/apache-httpd/dist-manager.nix @@ -87,6 +87,7 @@ in { globalEnvVars = []; extraServerPath = []; extraPath = []; + startupScript = null; options = { diff --git a/upstart-jobs/apache-httpd/subversion.nix b/upstart-jobs/apache-httpd/subversion.nix index d75e69c55247..f11f1af77dcf 100644 --- a/upstart-jobs/apache-httpd/subversion.nix +++ b/upstart-jobs/apache-httpd/subversion.nix @@ -50,6 +50,8 @@ let inherit (pkgs) libxslt enscript db4 coreutils bzip2; inherit (serverInfo) canonicalName; + + inherit (serverInfo.serverConfig) user group; # Urgh, most of these are dependencies of Email::Send, should figure them out automatically. perlFlags = map (x: "-I${x}/lib/site_perl") [ @@ -335,6 +337,9 @@ in { extraPath = [scripts]; + + + startupScript = "${scripts}/bin/svn-server-startup-hook.sh"; options = {