From 6705358edecde94b14f5bcd0b7ef78dc66daf3bf Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 26 Oct 2012 15:15:26 +0200 Subject: [PATCH] Convert Zabbix agent/server to systemd Note all the crap systemd doesn't need :-) --- modules/services/monitoring/zabbix-agent.nix | 39 ++++--------------- modules/services/monitoring/zabbix-server.nix | 38 +++++------------- 2 files changed, 17 insertions(+), 60 deletions(-) diff --git a/modules/services/monitoring/zabbix-agent.nix b/modules/services/monitoring/zabbix-agent.nix index ce8e1843d4c8..e5e27bb0c9a0 100644 --- a/modules/services/monitoring/zabbix-agent.nix +++ b/modules/services/monitoring/zabbix-agent.nix @@ -73,15 +73,12 @@ in description = "Zabbix daemon user"; }; - jobs.zabbix_agent = - { name = "zabbix-agent"; + boot.systemd.services."zabbix-agent" = + { description = "Zabbix Agent"; - description = "Zabbix agent daemon"; + wantedBy = [ "multi-user.target" ]; - startOn = "ip-up"; - stopOn = "stopping network-interfaces"; - - path = [ pkgs.zabbix.agent ]; + path = [ pkgs.nettools ]; preStart = '' @@ -89,30 +86,10 @@ in chown zabbix ${stateDir} ${logDir} ''; - # Zabbix doesn't have an option not to daemonize, and doesn't - # daemonize in a way that allows Upstart to track it. So to - # make sure that we notice when it goes down, we start Zabbix - # with an open connection to a fifo, with a `cat' on the other - # side. If Zabbix dies, then `cat' will exit as well, so we - # just monitor `cat'. - script = - '' - export PATH=${pkgs.nettools}/bin:$PATH - rm -f ${stateDir}/dummy2 - mkfifo ${stateDir}/dummy2 - cat ${stateDir}/dummy2 & - pid=$! - zabbix_agentd --config ${configFile} 100>${stateDir}/dummy2 - wait "$pid" - ''; - - postStop = - '' - pid=$(cat ${pidFile} 2> /dev/null || true) - (test -n "$pid" && kill "$pid") || true - # Wait until they're really gone. - while ${pkgs.procps}/bin/pgrep -u zabbix zabbix_agentd > /dev/null; do sleep 1; done - ''; + serviceConfig.ExecStart = "@${pkgs.zabbix.agent}/sbin/zabbix_agentd zabbix_agentd --config ${configFile}"; + serviceConfig.Type = "forking"; + serviceConfig.Restart = "always"; + serviceConfig.RestartSec = 2; }; environment.systemPackages = [ pkgs.zabbix.agent ]; diff --git a/modules/services/monitoring/zabbix-server.nix b/modules/services/monitoring/zabbix-server.nix index 57fc69b32709..085fb022c1c9 100644 --- a/modules/services/monitoring/zabbix-server.nix +++ b/modules/services/monitoring/zabbix-server.nix @@ -73,12 +73,11 @@ in description = "Zabbix daemon user"; }; - jobs.zabbix_server = - { name = "zabbix-server"; + boot.systemd.services."zabbix-server" = + { description = "Zabbix Server"; - description = "Zabbix server daemon"; - - startOn = "filesystem"; + wantedBy = [ "multi-user.target" ]; + after = optional (cfg.dbServer == "localhost") "postgresql.service"; preStart = '' @@ -95,31 +94,12 @@ in fi ''; - path = [ pkgs.nettools pkgs.zabbix.server ]; + path = [ pkgs.nettools ]; - # Zabbix doesn't have an option not to daemonize, and doesn't - # daemonize in a way that allows Upstart to track it. So to - # make sure that we notice when it goes down, we start Zabbix - # with an open connection to a fifo, with a `cat' on the other - # side. If Zabbix dies, then `cat' will exit as well, so we - # just monitor `cat'. - script = - '' - rm -f ${stateDir}/dummy - mkfifo ${stateDir}/dummy - cat ${stateDir}/dummy & - pid=$! - zabbix_server --config ${configFile} 100>${stateDir}/dummy - wait "$pid" - ''; - - postStop = - '' - pid=$(cat ${pidFile} 2> /dev/null || true) - (test -n "$pid" && kill "$pid") || true - # Wait until they're really gone. - while ${pkgs.procps}/bin/pkill -u zabbix zabbix_server; do true; done - ''; + serviceConfig.ExecStart = "@${pkgs.zabbix.server}/sbin/zabbix_server zabbix_server --config ${configFile}"; + serviceConfig.Type = "forking"; + serviceConfig.Restart = "always"; + serviceConfig.RestartSec = 2; }; };