* Upstart jobs for the Zabbix agent and server daemons.

svn path=/nixos/trunk/; revision=11998
This commit is contained in:
Eelco Dolstra 2008-06-06 09:13:16 +00:00
parent ebb43a3f67
commit 96a8dbfd58
6 changed files with 171 additions and 6 deletions

View File

@ -14,6 +14,7 @@
avahi = 10;
portmap = 11;
atd = 12;
zabbix = 13;
nixbld = 30000; # start of range of uids
nobody = 65534;

View File

@ -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 = {

View File

@ -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 {

View File

@ -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 ""
}

View File

@ -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
'';
}

View File

@ -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
'';
}