From 9127795e4adc53c7d95da37e11c246f9cf18b997 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 16 Feb 2010 10:10:59 +0000 Subject: [PATCH] * Make sure that Upstart notices when the Zabbix server crashes so that it can be restarted. Zabbix is kind of hard to monitor, so use a trick with an open fifo to detect when it goes down. svn path=/nixos/trunk/; revision=20039 --- modules/services/monitoring/zabbix-server.nix | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/services/monitoring/zabbix-server.nix b/modules/services/monitoring/zabbix-server.nix index fa38cc0a048..65b1a3cafa9 100644 --- a/modules/services/monitoring/zabbix-server.nix +++ b/modules/services/monitoring/zabbix-server.nix @@ -74,15 +74,29 @@ in cat ${pkgs.zabbix.server}/share/zabbix/db/data/images_pgsql.sql | ${pkgs.su}/bin/su -s "$SHELL" zabbix -c '${pkgs.postgresql}/bin/psql zabbix' touch "${libDir}/db-created" fi + ''; + # 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 - ${pkgs.zabbix.server}/sbin/zabbix_server --config ${configFile} + rm -f ${stateDir}/dummy + mkfifo ${stateDir}/dummy + cat ${stateDir}/dummy & + pid=$! + ${pkgs.zabbix.server}/sbin/zabbix_server --config ${configFile} 100>${stateDir}/dummy + wait "$pid" ''; postStop = '' - pid=$(cat ${pidFile}) - test -n "$pid" && kill "$pid" + 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 '';