inspark-data-center/docker/docker-entrypoint.d/insert_collector.sh
2024-11-08 20:18:03 +03:00

14 lines
567 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
export PGPASSWORD=${PG_PASS}
if [ "$(psql -h ${PG_HOST} -p ${PG_PORT} -U ${PG_USER} -d ${PG_DB} -At -c 'SELECT * FROM sem.collectorserver WHERE serverid = 2;' | cut -d \| -f 1 | grep -wc 2)" = '1' ];
then
echo "DB ${PG_DB}.Collector emqx exist"
else
echo "Create collector"
psql -v ON_ERROR_STOP=1 -h ${PG_HOST} -p ${PG_PORT} -U ${PG_USER} -d ${PG_DB} <<-EOSQL
INSERT INTO sem.collectorserver (serverid, ip, host, dn, port, comment) VALUES (2, 'emqx', 'emqx', 'emqx', 1883, 'Сервер сбора по умолчанию');
EOSQL
fi