Use the new scheme for zabbix upstart-job.
svn path=/nixos/branches/fix-style/; revision=13329
This commit is contained in:
parent
3a25babf1b
commit
9c751d377d
@ -2320,37 +2320,8 @@ in
|
|||||||
";
|
";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
zabbixAgent = {
|
|
||||||
|
|
||||||
enable = mkOption {
|
|
||||||
default = false;
|
|
||||||
description = "
|
|
||||||
Whether to run the Zabbix monitoring agent on this machine.
|
|
||||||
It will send monitoring data to a Zabbix server.
|
|
||||||
";
|
|
||||||
};
|
|
||||||
|
|
||||||
server = mkOption {
|
|
||||||
default = "127.0.0.1";
|
|
||||||
description = ''
|
|
||||||
The IP address or hostname of the Zabbix server to connect to.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
zabbixServer = {
|
|
||||||
enable = mkOption {
|
|
||||||
default = false;
|
|
||||||
description = "
|
|
||||||
Whether to run the Zabbix server on this machine.
|
|
||||||
";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
postfix = {
|
postfix = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
@ -3111,6 +3082,8 @@ root ALL=(ALL) SETENV: ALL
|
|||||||
(import ../upstart-jobs/pcmcia.nix)
|
(import ../upstart-jobs/pcmcia.nix)
|
||||||
|
|
||||||
# services
|
# services
|
||||||
|
(import ../upstart-jobs/zabbix-agent.nix)
|
||||||
|
(import ../upstart-jobs/zabbix-server.nix.nix)
|
||||||
(import ../upstart-jobs/disnix.nix)
|
(import ../upstart-jobs/disnix.nix)
|
||||||
(import ../upstart-jobs/cron.nix)
|
(import ../upstart-jobs/cron.nix)
|
||||||
(import ../upstart-jobs/cron/locate.nix)
|
(import ../upstart-jobs/cron/locate.nix)
|
||||||
|
@ -418,18 +418,6 @@ let
|
|||||||
inherit config pkgs;
|
inherit config pkgs;
|
||||||
})
|
})
|
||||||
|
|
||||||
# Zabbix agent daemon.
|
|
||||||
++ optional config.services.zabbixAgent.enable
|
|
||||||
(import ../upstart-jobs/zabbix-agent.nix {
|
|
||||||
inherit config pkgs;
|
|
||||||
})
|
|
||||||
|
|
||||||
# Zabbix server daemon.
|
|
||||||
++ optional config.services.zabbixServer.enable
|
|
||||||
(import ../upstart-jobs/zabbix-server.nix {
|
|
||||||
inherit config pkgs;
|
|
||||||
})
|
|
||||||
|
|
||||||
# Postfix mail server.
|
# Postfix mail server.
|
||||||
++ optional config.services.postfix.enable
|
++ optional config.services.postfix.enable
|
||||||
(import ../upstart-jobs/postfix.nix {
|
(import ../upstart-jobs/postfix.nix {
|
||||||
|
@ -1,5 +1,35 @@
|
|||||||
|
# Zabbix agent daemon.
|
||||||
{config, pkgs}:
|
{config, pkgs}:
|
||||||
|
|
||||||
|
###### interface
|
||||||
|
let
|
||||||
|
inherit (pkgs.lib) mkOption;
|
||||||
|
|
||||||
|
options = {
|
||||||
|
services = {
|
||||||
|
zabbixAgent = {
|
||||||
|
|
||||||
|
enable = mkOption {
|
||||||
|
default = false;
|
||||||
|
description = "
|
||||||
|
Whether to run the Zabbix monitoring agent on this machine.
|
||||||
|
It will send monitoring data to a Zabbix server.
|
||||||
|
";
|
||||||
|
};
|
||||||
|
|
||||||
|
server = mkOption {
|
||||||
|
default = "127.0.0.1";
|
||||||
|
description = ''
|
||||||
|
The IP address or hostname of the Zabbix server to connect to.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
|
||||||
|
###### implementation
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.services.zabbixAgent;
|
cfg = config.services.zabbixAgent;
|
||||||
@ -20,44 +50,59 @@ let
|
|||||||
StartAgents = 5
|
StartAgents = 5
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
user = {
|
||||||
|
name = "zabbix";
|
||||||
|
uid = (import ../system/ids.nix).uids.zabbix;
|
||||||
|
description = "Zabbix daemon user";
|
||||||
|
};
|
||||||
|
|
||||||
|
job = {
|
||||||
|
name = "zabbix-agent";
|
||||||
|
|
||||||
|
job = ''
|
||||||
|
start on network-interfaces/started
|
||||||
|
stop on network-interfaces/stop
|
||||||
|
|
||||||
|
description "Zabbix agent daemon"
|
||||||
|
|
||||||
|
start script
|
||||||
|
mkdir -m 0755 -p ${stateDir} ${logDir}
|
||||||
|
chown zabbix ${stateDir} ${logDir}
|
||||||
|
|
||||||
|
export PATH=${pkgs.nettools}/bin:$PATH
|
||||||
|
${pkgs.zabbixAgent}/sbin/zabbix_agentd --config ${configFile}
|
||||||
|
end script
|
||||||
|
|
||||||
|
respawn sleep 100000
|
||||||
|
|
||||||
|
stop script
|
||||||
|
# !!! this seems to leave processes behind.
|
||||||
|
#pid=$(cat ${pidFile})
|
||||||
|
#if test -n "$pid"; then
|
||||||
|
# kill $pid
|
||||||
|
#fi
|
||||||
|
|
||||||
|
# So instead kill the agent in a brutal fashion.
|
||||||
|
while ${pkgs.procps}/bin/pkill -u zabbix zabbix_agentd; do true; done
|
||||||
|
end script
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
ifEnable = pkgs.lib.ifEnable cfg.enable;
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "zabbix-agent";
|
require = [
|
||||||
|
(import ../upstart-jobs/default.nix)
|
||||||
users = [
|
# (import ../system/user.nix) # users = { .. }
|
||||||
{ name = "zabbix";
|
options
|
||||||
uid = (import ../system/ids.nix).uids.zabbix;
|
|
||||||
description = "Zabbix daemon user";
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
job = ''
|
services = {
|
||||||
start on network-interfaces/started
|
extraJobs = ifEnable [job];
|
||||||
stop on network-interfaces/stop
|
};
|
||||||
|
|
||||||
description "Zabbix agent daemon"
|
users = {
|
||||||
|
extraUsers = ifEnable [user];
|
||||||
start script
|
};
|
||||||
mkdir -m 0755 -p ${stateDir} ${logDir}
|
|
||||||
chown zabbix ${stateDir} ${logDir}
|
|
||||||
|
|
||||||
export PATH=${pkgs.nettools}/bin:$PATH
|
|
||||||
${pkgs.zabbixAgent}/sbin/zabbix_agentd --config ${configFile}
|
|
||||||
end script
|
|
||||||
|
|
||||||
respawn sleep 100000
|
|
||||||
|
|
||||||
stop script
|
|
||||||
# !!! this seems to leave processes behind.
|
|
||||||
#pid=$(cat ${pidFile})
|
|
||||||
#if test -n "$pid"; then
|
|
||||||
# kill $pid
|
|
||||||
#fi
|
|
||||||
|
|
||||||
# So instead kill the agent in a brutal fashion.
|
|
||||||
while ${pkgs.procps}/bin/pkill -u zabbix zabbix_agentd; do true; done
|
|
||||||
end script
|
|
||||||
'';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,25 @@
|
|||||||
|
# Zabbix server daemon.
|
||||||
{config, pkgs}:
|
{config, pkgs}:
|
||||||
|
|
||||||
|
###### 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
|
||||||
let
|
let
|
||||||
|
|
||||||
stateDir = "/var/run/zabbix";
|
stateDir = "/var/run/zabbix";
|
||||||
@ -20,46 +40,62 @@ let
|
|||||||
DBUser = zabbix
|
DBUser = zabbix
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
user = {
|
||||||
|
name = "zabbix";
|
||||||
|
uid = (import ../system/ids.nix).uids.zabbix;
|
||||||
|
description = "Zabbix daemon user";
|
||||||
|
};
|
||||||
|
|
||||||
|
job = {
|
||||||
|
name = "zabbix-server";
|
||||||
|
|
||||||
|
job = ''
|
||||||
|
description "Zabbix server daemon"
|
||||||
|
|
||||||
|
start on postgresql/started
|
||||||
|
stop on shutdown
|
||||||
|
|
||||||
|
start script
|
||||||
|
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}
|
||||||
|
end script
|
||||||
|
|
||||||
|
respawn sleep 100000
|
||||||
|
|
||||||
|
stop script
|
||||||
|
while ${pkgs.procps}/bin/pkill -u zabbix zabbix_server; do true; done
|
||||||
|
end script
|
||||||
|
'';
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
ifEnable = pkgs.lib.ifEnable config.services.zabbixServer.enable
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "zabbix-server";
|
require = [
|
||||||
|
(import ../upstart-jobs/default.nix)
|
||||||
users = [
|
# (import ../system/user.nix) # users = { .. }
|
||||||
{ name = "zabbix";
|
options
|
||||||
uid = (import ../system/ids.nix).uids.zabbix;
|
|
||||||
description = "Zabbix daemon user";
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
job = ''
|
services = {
|
||||||
description "Zabbix server daemon"
|
extraJobs = ifEnable [job];
|
||||||
|
};
|
||||||
|
|
||||||
start on postgresql/started
|
users = {
|
||||||
stop on shutdown
|
extraUsers = ifEnable [user];
|
||||||
|
};
|
||||||
start script
|
|
||||||
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}
|
|
||||||
end script
|
|
||||||
|
|
||||||
respawn sleep 100000
|
|
||||||
|
|
||||||
stop script
|
|
||||||
while ${pkgs.procps}/bin/pkill -u zabbix zabbix_server; do true; done
|
|
||||||
end script
|
|
||||||
'';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user