2008-11-18 18:00:21 +00:00
|
|
|
# Zabbix server daemon.
|
2009-10-12 17:36:19 +01:00
|
|
|
{ config, pkgs, ... }:
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
with pkgs.lib;
|
2008-11-18 18:00:21 +00:00
|
|
|
|
2008-06-06 10:13:16 +01:00
|
|
|
let
|
|
|
|
|
|
|
|
stateDir = "/var/run/zabbix";
|
|
|
|
|
|
|
|
logDir = "/var/log/zabbix";
|
|
|
|
|
|
|
|
libDir = "/var/lib/zabbix";
|
|
|
|
|
|
|
|
pidFile = "${stateDir}/zabbix_server.pid";
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
configFile = pkgs.writeText "zabbix_server.conf"
|
|
|
|
''
|
|
|
|
LogFile = ${logDir}/zabbix_server
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
PidFile = ${pidFile}
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
DBName = zabbix
|
2008-06-06 10:13:16 +01:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
DBUser = zabbix
|
2008-11-18 18:00:21 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2008-11-18 18:00:21 +00:00
|
|
|
{
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.zabbixServer.enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run the Zabbix server on this machine.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2008-11-18 18:00:21 +00:00
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.zabbixServer.enable {
|
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = "zabbix";
|
|
|
|
uid = config.ids.uids.zabbix;
|
|
|
|
description = "Zabbix daemon user";
|
|
|
|
};
|
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.zabbix_server =
|
2009-10-12 17:36:19 +01:00
|
|
|
{ #name = "zabbix-server"; !!! mkIf bug
|
|
|
|
|
|
|
|
description = "Zabbix server daemon";
|
|
|
|
|
2009-11-06 22:19:17 +00:00
|
|
|
startOn = "started postgresql";
|
|
|
|
stopOn = "stopping postgresql";
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
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'
|
|
|
|
touch "${libDir}/db-created"
|
|
|
|
fi
|
|
|
|
|
|
|
|
export PATH=${pkgs.nettools}/bin:$PATH
|
|
|
|
${pkgs.zabbixServer}/sbin/zabbix_server --config ${configFile}
|
|
|
|
'';
|
|
|
|
|
|
|
|
postStop =
|
|
|
|
''
|
|
|
|
while ${pkgs.procps}/bin/pkill -u zabbix zabbix_server; do true; done
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2008-11-18 18:00:21 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2008-06-06 10:13:16 +01:00
|
|
|
}
|