Convert Zabbix agent/server to systemd
Note all the crap systemd doesn't need :-)
This commit is contained in:
parent
b3c5d42b1d
commit
6705358ede
@ -73,15 +73,12 @@ in
|
|||||||
description = "Zabbix daemon user";
|
description = "Zabbix daemon user";
|
||||||
};
|
};
|
||||||
|
|
||||||
jobs.zabbix_agent =
|
boot.systemd.services."zabbix-agent" =
|
||||||
{ name = "zabbix-agent";
|
{ description = "Zabbix Agent";
|
||||||
|
|
||||||
description = "Zabbix agent daemon";
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
startOn = "ip-up";
|
path = [ pkgs.nettools ];
|
||||||
stopOn = "stopping network-interfaces";
|
|
||||||
|
|
||||||
path = [ pkgs.zabbix.agent ];
|
|
||||||
|
|
||||||
preStart =
|
preStart =
|
||||||
''
|
''
|
||||||
@ -89,30 +86,10 @@ in
|
|||||||
chown zabbix ${stateDir} ${logDir}
|
chown zabbix ${stateDir} ${logDir}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Zabbix doesn't have an option not to daemonize, and doesn't
|
serviceConfig.ExecStart = "@${pkgs.zabbix.agent}/sbin/zabbix_agentd zabbix_agentd --config ${configFile}";
|
||||||
# daemonize in a way that allows Upstart to track it. So to
|
serviceConfig.Type = "forking";
|
||||||
# make sure that we notice when it goes down, we start Zabbix
|
serviceConfig.Restart = "always";
|
||||||
# with an open connection to a fifo, with a `cat' on the other
|
serviceConfig.RestartSec = 2;
|
||||||
# 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
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = [ pkgs.zabbix.agent ];
|
environment.systemPackages = [ pkgs.zabbix.agent ];
|
||||||
|
@ -73,12 +73,11 @@ in
|
|||||||
description = "Zabbix daemon user";
|
description = "Zabbix daemon user";
|
||||||
};
|
};
|
||||||
|
|
||||||
jobs.zabbix_server =
|
boot.systemd.services."zabbix-server" =
|
||||||
{ name = "zabbix-server";
|
{ description = "Zabbix Server";
|
||||||
|
|
||||||
description = "Zabbix server daemon";
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = optional (cfg.dbServer == "localhost") "postgresql.service";
|
||||||
startOn = "filesystem";
|
|
||||||
|
|
||||||
preStart =
|
preStart =
|
||||||
''
|
''
|
||||||
@ -95,31 +94,12 @@ in
|
|||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
path = [ pkgs.nettools pkgs.zabbix.server ];
|
path = [ pkgs.nettools ];
|
||||||
|
|
||||||
# Zabbix doesn't have an option not to daemonize, and doesn't
|
serviceConfig.ExecStart = "@${pkgs.zabbix.server}/sbin/zabbix_server zabbix_server --config ${configFile}";
|
||||||
# daemonize in a way that allows Upstart to track it. So to
|
serviceConfig.Type = "forking";
|
||||||
# make sure that we notice when it goes down, we start Zabbix
|
serviceConfig.Restart = "always";
|
||||||
# with an open connection to a fifo, with a `cat' on the other
|
serviceConfig.RestartSec = 2;
|
||||||
# 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
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user