From e7e685e4ce8709f075450427b9208d983ffc085b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 23 Nov 2007 10:56:12 +0000 Subject: [PATCH] * Allow Upstart jobs to declare extra configuration for Apache. Did this for Nagios. Soon we can rename upstart-jobs to services/plugins/whatever (i.e. an Upstart job will just be one kind of configuration item that a plugin can declare). svn path=/nixos/trunk/; revision=9778 --- system/options.nix | 18 +++++++++++++++++ upstart-jobs/default.nix | 13 +++++++------ upstart-jobs/httpd.nix | 4 ++-- upstart-jobs/make-job.nix | 4 ++++ upstart-jobs/nagios/default.nix | 34 +++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/system/options.nix b/system/options.nix index 78128a03f22..d525136b5a8 100644 --- a/system/options.nix +++ b/system/options.nix @@ -874,6 +874,7 @@ "; }; + # !!! this is a mis-nomer, should be "extraConfig" or something. extraDirectories = mkOption { default = ""; example = " @@ -1216,6 +1217,23 @@ "; }; + enableWebInterface = mkOption { + default = false; + description = " + Whether to enable the Nagios web interface. You should also + enable Apache (). + "; + }; + + urlPath = mkOption { + default = "/nagios"; + description = " + The URL path under which the Nagios web interface appears. + That is, you can access the Nagios web interface through + http://server/urlPath. + "; + }; + }; diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index 42fc4c0b7d4..a4ab27e001f 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -12,11 +12,7 @@ let (config.services.mingetty.ttys) ++ [10] /* !!! sync with syslog.conf */ ; -in - -import ../upstart-jobs/gather.nix { - inherit (pkgs) runCommand; - + jobs = map makeJob [ # Syslogd. (import ../upstart-jobs/syslogd.nix { @@ -171,6 +167,8 @@ import ../upstart-jobs/gather.nix { (import ../upstart-jobs/httpd.nix { inherit config pkgs; inherit (pkgs) glibc; + extraConfig = pkgs.lib.concatStringsSep "\n" + (map (job: job.extraHttpdConfig) jobs); }) # Samba service. @@ -203,7 +201,6 @@ import ../upstart-jobs/gather.nix { inherit config pkgs; }) - # ALSA sound support. ++ optional config.sound.enable (import ../upstart-jobs/alsa.nix { @@ -285,5 +282,9 @@ import ../upstart-jobs/gather.nix { # For the built-in logd job. ++ [(makeJob { jobDrv = pkgs.upstart; })]; + +in import ../upstart-jobs/gather.nix { + inherit (pkgs) runCommand; + inherit jobs; } diff --git a/upstart-jobs/httpd.nix b/upstart-jobs/httpd.nix index fcc89740b5a..a8f00552fc8 100644 --- a/upstart-jobs/httpd.nix +++ b/upstart-jobs/httpd.nix @@ -1,4 +1,4 @@ -{config, pkgs, glibc}: +{config, pkgs, glibc, extraConfig}: let @@ -18,7 +18,7 @@ let stateDir = cfg.stateDir; enableSSL = false; noUserDir = cfg.noUserDir; - extraDirectories = cfg.extraDirectories; + extraDirectories = cfg.extraDirectories + extraConfig; startingDependency = if config.services.gw6c.enable then "gw6c" else "network-interfaces"; diff --git a/upstart-jobs/make-job.nix b/upstart-jobs/make-job.nix index 14f48ae04d6..5523ad5af93 100644 --- a/upstart-jobs/make-job.nix +++ b/upstart-jobs/make-job.nix @@ -24,6 +24,10 @@ # Allow jobs to declare extra files that should be added to /etc. extraEtc = if job ? extraEtc then job.extraEtc else []; + # Allow jobs to declare extra configuration for Apache (e.g. Nagios + # declaring its web interface). + extraHttpdConfig = if job ? extraHttpdConfig then job.extraHttpdConfig else ""; + # Allow jobs to declare user accounts that should be created. users = if job ? users then job.users else []; diff --git a/upstart-jobs/nagios/default.nix b/upstart-jobs/nagios/default.nix index a9ad05055f5..256693ba072 100644 --- a/upstart-jobs/nagios/default.nix +++ b/upstart-jobs/nagios/default.nix @@ -45,6 +45,37 @@ let "; + # Plain configuration for the Nagios web-interface with no + # authentication. + nagiosCGICfgFile = pkgs.writeText "nagios.cgi.conf" " + main_config_file=${nagiosCfgFile} + use_authentication=0 + url_html_path=/nagios + "; + + urlPath = config.services.nagios.urlPath; + + extraHttpdConfig = " + ScriptAlias ${urlPath}/cgi-bin ${pkgs.nagios}/sbin + + + Options ExecCGI + AllowOverride None + Order allow,deny + Allow from all + SetEnv NAGIOS_CGI_CONFIG ${nagiosCGICfgFile} + + + Alias ${urlPath} ${pkgs.nagios}/share + + + Options None + AllowOverride None + Order allow,deny + Allow from all + + "; + in { @@ -68,6 +99,9 @@ in } ]; + extraHttpdConfig = + if config.services.nagios.enableWebInterface then extraHttpdConfig else ""; + # Run `nagios -v' to check the validity of the configuration file so # that a nixos-rebuild fails *before* we kill the running Nagios # daemon.