nixos/zabbixProxy: fix database initialization logic

This commit is contained in:
Aaron Andersen 2019-08-13 18:35:02 -04:00
parent dae42566db
commit 9af06755f3
2 changed files with 10 additions and 6 deletions

View File

@ -120,7 +120,8 @@ in
name = mkOption {
type = types.str;
default = "zabbix";
default = if cfg.database.type == "sqlite" then "${stateDir}/zabbix.db" else "zabbix";
defaultText = "zabbix";
description = "Database name.";
};
@ -261,17 +262,17 @@ in
preStart = optionalString pgsqlLocal ''
if ! test -e "${stateDir}/db-created"; then
cat ${cfg.package}/share/zabbix/database/postgresql/schema.sql | ${pgsql.package}/bin/psql ${cfg.database.name}
cat ${cfg.package}/share/zabbix/database/postgresql/images.sql | ${pgsql.package}/bin/psql ${cfg.database.name}
cat ${cfg.package}/share/zabbix/database/postgresql/data.sql | ${pgsql.package}/bin/psql ${cfg.database.name}
touch "${stateDir}/db-created"
fi
'' + optionalString mysqlLocal ''
if ! test -e "${stateDir}/db-created"; then
cat ${cfg.package}/share/zabbix/database/mysql/schema.sql | ${mysql.package}/bin/mysql ${cfg.database.name}
cat ${cfg.package}/share/zabbix/database/mysql/images.sql | ${mysql.package}/bin/mysql ${cfg.database.name}
cat ${cfg.package}/share/zabbix/database/mysql/data.sql | ${mysql.package}/bin/mysql ${cfg.database.name}
touch "${stateDir}/db-created"
fi
'' + optionalString (cfg.database.type == "sqlite") ''
if ! test -e "${cfg.database.name}"; then
${pkgs.sqlite}/bin/sqlite3 "${cfg.database.name}" < ${cfg.package}/share/zabbix/database/sqlite3/schema.sql
fi
'' + optionalString (cfg.database.passwordFile != null) ''
# create a copy of the supplied password file in a format zabbix can consume
touch ${passwordFile}

View File

@ -63,7 +63,10 @@ in
mkdir -p $out/share/zabbix/database/
'' + optionalString sqliteSupport ''
mkdir -p $out/share/zabbix/database/sqlite3
cp -prvd database/sqlite3/*.sql $out/share/zabbix/database/sqlite3/
cp -prvd database/sqlite3/schema.sql $out/share/zabbix/database/sqlite3/
'' + optionalString mysqlSupport ''
mkdir -p $out/share/zabbix/database/mysql
cp -prvd database/mysql/schema.sql $out/share/zabbix/database/mysql/
'' + optionalString postgresqlSupport ''
mkdir -p $out/share/zabbix/database/postgresql
cp -prvd database/postgresql/schema.sql $out/share/zabbix/database/postgresql/