-
Notifications
You must be signed in to change notification settings - Fork 83
/
set_influxdb.sh
executable file
·78 lines (69 loc) · 2.41 KB
/
set_influxdb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -m
CONFIG_FILE="/etc/influxdb/config.toml"
API_URL="http://localhost:8086"
#if [ -n "${FORCE_HOSTNAME}" ]; then
# if [ "${FORCE_HOSTNAME}" == "auto" ]; then
# #set hostname with IPv4 eth0
# HOSTIPNAME=$(ip a show dev eth0 | grep inet | grep eth0 | sed -e 's/^.*inet.//g' -e 's/\/.*$//g')
# /usr/bin/perl -p -i -e "s/^# hostname.*$/hostname = \"${HOSTIPNAME}\"/g" ${CONFIG_FILE}
# else
# /usr/bin/perl -p -i -e "s/^# hostname.*$/hostname = \"${FORCE_HOSTNAME}\"/g" ${CONFIG_FILE}
# fi
#fi
#
#if [ -n "${SEEDS}" ]; then
# /usr/bin/perl -p -i -e "s/^# seed-servers.*$/seed-servers = [${SEEDS}]/g" ${CONFIG_FILE}
#fi
#
#if [ -n "${REPLI_FACTOR}" ]; then
# /usr/bin/perl -p -i -e "s/replication-factor = 1/replication-factor = ${REPLI_FACTOR}/g" ${CONFIG_FILE}
#fi
#
#if [ "${PRE_CREATE_DB}" == "**None**" ]; then
# unset PRE_CREATE_DB
#fi
#
#if [ "${SSL_CERT}" == "**None**" ]; then
# unset SSL_CERT
#fi
#
#API_URL="http://localhost:8086"
#if [ -n "${SSL_CERT}" ]; then
# echo "=> Found ssl cert file, using ssl api instead"
# echo "=> Listening on port 8084(https api), disabling port 8086(http api)"
# echo -e "${SSL_CERT}" > /cert.pem
# sed -i -r -e 's/^# ssl-/ssl-/g' -e 's/^port *= * 8086/# port = 8086/' ${CONFIG_FILE}
# API_URL="https://localhost:8084"
#fi
echo "=> About to create the following database: ${PRE_CREATE_DB}"
if [ -f "/.influxdb_configured" ]; then
echo "=> Database had been created before, skipping ..."
else
echo "=> Starting InfluxDB ..."
exec /usr/bin/influxd -config=${CONFIG_FILE} &
arr=$(echo ${PRE_CREATE_DB} | tr ";" "\n")
#wait for the startup of influxd
RET=1
while [[ RET -ne 0 ]]; do
echo "=> Waiting for confirmation of InfluxDB service startup ..."
sleep 3
curl -k ${API_URL}/ping 2> /dev/null
RET=$?
done
echo ""
for x in $arr
do
echo "=> Creating database: ${x}"
curl -s -k -XPOST ${API_URL}/query --data-urlencode "q=CREATE DATABASE ${x}"
done
echo ""
echo "=> Creating User for database: data"
curl -s -k -XPOST ${API_URL}/query --data-urlencode "q=CREATE USER \"${INFLUXDB_DATA_USER}\" WITH PASSWORD '${ROOT_PW}'"
echo "=> Creating User for database: grafana"
curl -s -k -XPOST ${API_URL}/query --data-urlencode "q=CREATE USER \"${INFLUXDB_GRAFANA_USER}\" WITH PASSWORD '${ROOT_PW}'"
echo ""
touch "/.influxdb_configured"
exit 0
fi
exit 0