-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·69 lines (59 loc) · 2.28 KB
/
run.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
#!/bin/bash
set -m
# Name of .conf file AFTER envtpl is done modifying it.
CONFIG_FILE="/config/influxdb.conf"
INFLUX_HOST="localhost"
INFLUX_API_PORT="8086"
API_URL="http://${INFLUX_HOST}:${INFLUX_API_PORT}"
# Add Collectd support
envtpl /config/influxdb.conf.tpl
# donn: In all prev servers, max-open-shards was absent from .conf
# Dynamically change the value of 'max-open-shards' to what 'ulimit -n' returns
#sed -i "s/^max-open-shards.*/max-open-shards = $(ulimit -n)/" ${CONFIG_FILE}
if [ "${PRE_CREATE_DB}" == "**None**" ]; then
unset PRE_CREATE_DB
fi
echo "influxdb configuration: "
cat ${CONFIG_FILE}
echo "=> Starting InfluxDB ..."
exec influxd -config=${CONFIG_FILE} &
# Pre create database on the initiation of the container
if [ -n "${PRE_CREATE_DB}" ]; then
echo "=> About to create the following database: ${PRE_CREATE_DB}"
if [ -f "/data/.pre_db_created" ]; then
echo "=> Database had been created before, skipping ..."
else
arr=$(echo ${PRE_CREATE_DB} | tr ";" "\n")
#wait for the startup of influxdb
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 ""
PASS=${INFLUXDB_INIT_PWD:-root}
if [ -n "${ADMIN_USER}" ]; then
echo "=> Creating admin user"
influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -execute="CREATE USER ${ADMIN_USER} WITH PASSWORD '${PASS}' WITH ALL PRIVILEGES"
for x in $arr
do
echo "=> Creating database: ${x}"
influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -username=${ADMIN_USER} -password="${PASS}" -execute="create database ${x}"
influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -username=${ADMIN_USER} -password="${PASS}" -execute="grant all PRIVILEGES on ${x} to ${ADMIN_USER}"
done
echo ""
else
for x in $arr
do
echo "=> Creating database: ${x}"
influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -execute="create database \"${x}\""
done
fi
touch "/data/.pre_db_created"
fi
else
echo "=> No database need to be pre-created"
fi
fg