2008-11-18 19:00:21 +01:00
|
|
|
# Zabbix server daemon.
|
2009-01-25 16:48:39 +01:00
|
|
|
{config, pkgs, ...}:
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
###### interface
|
|
|
|
let
|
|
|
|
inherit (pkgs.lib) mkOption;
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services = {
|
|
|
|
zabbixServer = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to run the Zabbix server on this machine.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
|
|
|
|
###### implementation
|
2008-06-06 11:13:16 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
PidFile = ${pidFile}
|
|
|
|
|
|
|
|
DBName = zabbix
|
|
|
|
|
|
|
|
DBUser = zabbix
|
|
|
|
'';
|
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
user = {
|
|
|
|
name = "zabbix";
|
2009-05-29 16:25:56 +02:00
|
|
|
uid = config.ids.uids.zabbix;
|
2008-11-18 19:00:21 +01:00
|
|
|
description = "Zabbix daemon user";
|
|
|
|
};
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
job = {
|
|
|
|
name = "zabbix-server";
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
job = ''
|
|
|
|
description "Zabbix server daemon"
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
start on postgresql/started
|
|
|
|
stop on shutdown
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
start script
|
|
|
|
mkdir -m 0755 -p ${stateDir} ${logDir} ${libDir}
|
|
|
|
chown zabbix ${stateDir} ${logDir} ${libDir}
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
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'
|
|
|
|
touch "${libDir}/db-created"
|
|
|
|
fi
|
|
|
|
|
|
|
|
export PATH=${pkgs.nettools}/bin:$PATH
|
|
|
|
${pkgs.zabbixServer}/sbin/zabbix_server --config ${configFile}
|
|
|
|
end script
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
respawn sleep 100000
|
|
|
|
|
|
|
|
stop script
|
|
|
|
while ${pkgs.procps}/bin/pkill -u zabbix zabbix_server; do true; done
|
|
|
|
end script
|
|
|
|
'';
|
2008-06-06 11:13:16 +02:00
|
|
|
|
2008-11-18 19:00:21 +01:00
|
|
|
};
|
|
|
|
|
2008-11-23 02:28:25 +01:00
|
|
|
ifEnable = pkgs.lib.ifEnable config.services.zabbixServer.enable;
|
2008-11-18 19:00:21 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
require = [
|
2009-05-25 01:13:23 +02:00
|
|
|
# ../upstart-jobs/default.nix
|
2009-05-20 01:14:45 +02:00
|
|
|
# ../system/user.nix # users = { .. }
|
2008-11-18 19:00:21 +01:00
|
|
|
options
|
|
|
|
];
|
|
|
|
|
|
|
|
services = {
|
|
|
|
extraJobs = ifEnable [job];
|
|
|
|
};
|
|
|
|
|
|
|
|
users = {
|
|
|
|
extraUsers = ifEnable [user];
|
|
|
|
};
|
2008-06-06 11:13:16 +02:00
|
|
|
}
|