From 96a8dbfd5829951aa1c246ef2e70ede6edccc8c3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 6 Jun 2008 09:13:16 +0000 Subject: [PATCH] * Upstart jobs for the Zabbix agent and server daemons. svn path=/nixos/trunk/; revision=11998 --- system/ids.nix | 1 + system/options.nix | 26 ++++++++++++++ upstart-jobs/default.nix | 14 +++++++- upstart-jobs/xserver.nix | 10 +++--- upstart-jobs/zabbix-agent.nix | 60 +++++++++++++++++++++++++++++++ upstart-jobs/zabbix-server.nix | 66 ++++++++++++++++++++++++++++++++++ 6 files changed, 171 insertions(+), 6 deletions(-) create mode 100644 upstart-jobs/zabbix-agent.nix create mode 100644 upstart-jobs/zabbix-server.nix diff --git a/system/ids.nix b/system/ids.nix index 6c6df24dd90f..473f8202e68e 100644 --- a/system/ids.nix +++ b/system/ids.nix @@ -14,6 +14,7 @@ avahi = 10; portmap = 11; atd = 12; + zabbix = 13; nixbld = 30000; # start of range of uids nobody = 65534; diff --git a/system/options.nix b/system/options.nix index 9be4ce1c3847..d216c58f994c 100644 --- a/system/options.nix +++ b/system/options.nix @@ -1918,6 +1918,7 @@ }; + mysql = { enable = mkOption { default = false; @@ -1952,6 +1953,7 @@ }; }; + postgresql = { enable = mkOption { default = false; @@ -2009,6 +2011,7 @@ }; }; + openfire = { enable = mkOption { default = false; @@ -2024,6 +2027,7 @@ }; }; + gpm = { enable = mkOption { default = false; @@ -2039,6 +2043,28 @@ }; }; + + zabbixAgent = { + enable = mkOption { + default = false; + description = " + Whether to run the Zabbix monitoring agent on this machine. + It will send monitoring data to a Zabbix server. + "; + }; + }; + + + zabbixServer = { + enable = mkOption { + default = false; + description = " + Whether to run the Zabbix server on this machine. + "; + }; + }; + + }; installer = { diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index d16b5b160840..f7117f616aec 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.nix @@ -245,7 +245,7 @@ let # X server. ++ optional config.services.xserver.enable (import ../upstart-jobs/xserver.nix { - inherit config pkgs; + inherit config pkgs kernelPackages; fontDirectories = import ../system/fonts.nix {inherit pkgs config;}; }) @@ -377,6 +377,18 @@ let inherit config pkgs; }) + # Zabbix agent daemon. + ++ optional config.services.zabbixAgent.enable + (import ../upstart-jobs/zabbix-agent.nix { + inherit config pkgs; + }) + + # Zabbix server daemon. + ++ optional config.services.zabbixServer.enable + (import ../upstart-jobs/zabbix-server.nix { + inherit config pkgs; + }) + # Handles the reboot/halt events. ++ (map (event: makeJob (import ../upstart-jobs/halt.nix { diff --git a/upstart-jobs/xserver.nix b/upstart-jobs/xserver.nix index 29ae21ac076b..182996a9dd93 100644 --- a/upstart-jobs/xserver.nix +++ b/upstart-jobs/xserver.nix @@ -1,4 +1,4 @@ -{ config, pkgs +{ config, pkgs, kernelPackages , # List of font directories. fontDirectories @@ -36,7 +36,7 @@ let modules = - optional (videoDriver == "nvidia") nvidiaDrivers #make sure it first loads the nvidia libs + optional (videoDriver == "nvidia") kernelPackages.nvidiaDrivers #make sure it first loads the nvidia libs ++ [ xorg.xorgserver xorg.xf86inputkeyboard @@ -352,7 +352,7 @@ rec { xorg.xset # used by startkde, non-essential ] ++ optional (videoDriver == "nvidia") [ - nvidiaDrivers + kernelPackages.nvidiaDrivers ]; @@ -376,7 +376,7 @@ rec { rm -f /var/run/opengl-driver ${if videoDriver == "nvidia" then '' - ln -sf ${nvidiaDrivers} /var/run/opengl-driver + ln -sf ${kernelPackages.nvidiaDrivers} /var/run/opengl-driver '' else if cfg.driSupport then "ln -sf ${pkgs.mesa} /var/run/opengl-driver" @@ -393,7 +393,7 @@ rec { env XKB_BINDIR=${xorg.xkbcomp}/bin # Needed for the Xkb extension. ${if videoDriver == "nvidia" - then "env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:${nvidiaDrivers}/lib" + then "env LD_LIBRARY_PATH=${xorg.libX11}/lib:${xorg.libXext}/lib:${kernelPackages.nvidiaDrivers}/lib" else "" } diff --git a/upstart-jobs/zabbix-agent.nix b/upstart-jobs/zabbix-agent.nix new file mode 100644 index 000000000000..83c0562e3178 --- /dev/null +++ b/upstart-jobs/zabbix-agent.nix @@ -0,0 +1,60 @@ +{config, pkgs}: + +let + + stateDir = "/var/run/zabbix"; + + logDir = "/var/log/zabbix"; + + pidFile = "${stateDir}/zabbix_agentd.pid"; + + configFile = pkgs.writeText "zabbix_agentd.conf" '' + Server = 127.0.0.1 + + LogFile = ${logDir}/zabbix_agentd + + DebugLevel = 4 + + PidFile = ${pidFile} + + StartAgents = 1 + ''; + +in + +{ + name = "zabbix-agent"; + + users = [ + { name = "zabbix"; + uid = (import ../system/ids.nix).uids.zabbix; + description = "Zabbix daemon user"; + } + ]; + + job = '' + description "Zabbix agent daemon" + + start script + mkdir -m 0755 -p ${stateDir} ${logDir} + chown zabbix ${stateDir} ${logDir} + + export PATH=${pkgs.nettools}/bin:$PATH + ${pkgs.zabbixAgent}/sbin/zabbix_agentd --config ${configFile} + end script + + respawn sleep 100000 + + stop script + # !!! this seems to leave processes behind. + #pid=$(cat ${pidFile}) + #if test -n "$pid"; then + # kill $pid + #fi + + # So instead kill the agent in a brutal fashion. + while ${pkgs.procps}/bin/pkill -u zabbix zabbix_agentd; do true; done + end script + ''; + +} diff --git a/upstart-jobs/zabbix-server.nix b/upstart-jobs/zabbix-server.nix new file mode 100644 index 000000000000..7cd0d6e7c200 --- /dev/null +++ b/upstart-jobs/zabbix-server.nix @@ -0,0 +1,66 @@ +{config, pkgs}: + +let + + stateDir = "/var/run/zabbix"; + + logDir = "/var/log/zabbix"; + + libDir = "/var/lib/zabbix"; + + pidFile = "${stateDir}/zabbix_server.pid"; + + configFile = pkgs.writeText "zabbix_server.conf" '' + LogFile = ${logDir}/zabbix_server + + DebugLevel = 4 + + PidFile = ${pidFile} + + DBName = zabbix + + DBUser = zabbix + ''; + +in + +{ + name = "zabbix-server"; + + users = [ + { name = "zabbix"; + uid = (import ../system/ids.nix).uids.zabbix; + description = "Zabbix daemon user"; + } + ]; + + job = '' + description "Zabbix server daemon" + + start on postgresql/started + stop on shutdown + + start script + mkdir -m 0755 -p ${stateDir} ${logDir} ${libDir} + chown zabbix ${stateDir} ${logDir} ${libDir} + + if ! test -e "${libDir}/db-created"; then + ${pkgs.postgresql}/bin/createuser --no-superuser --no-createdb --no-createrole zabbix || true + ${pkgs.postgresql}/bin/createdb --owner zabbix zabbix || true + cat ${pkgs.zabbixServer}/share/zabbix/db/schema/postgresql.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c 'psql zabbix' + cat ${pkgs.zabbixServer}/share/zabbix/db/data/data.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c 'psql zabbix' + cat ${pkgs.zabbixServer}/share/zabbix/db/data/images_pgsql.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c 'psql zabbix' + fi + + export PATH=${pkgs.nettools}/bin:$PATH + ${pkgs.zabbixServer}/sbin/zabbix_server --config ${configFile} + end script + + respawn sleep 100000 + + stop script + while ${pkgs.procps}/bin/pkill -u zabbix zabbix_server; do true; done + end script + ''; + +}