Last active
June 8, 2016 18:05
-
-
Save jmny/c19d404781d27cbe352b9f647600e0c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
influx: | |
build: ./docker/influxdb | |
environment: | |
ADMIN_PASSWORD: 'blabla' | |
DATABASE_NAME: 'testdb' | |
USERNAME: 'simpleuser' | |
PASSWORD: 'securepass' | |
INFLUXDB_HTTP_AUTH_ENABLED: 'true' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
influx: | |
build: ./docker/influxdb | |
environment: | |
ADMIN_PASSWORD: 'blabla' | |
DATABASE_NAME: 'testdb' | |
INFLUXDB_HTTP_AUTH_ENABLED: 'true' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM influxdb:0.13 | |
ADD setup_and_start.sh /root/setup_and_start.sh | |
RUN chmod u+x /root/setup_and_start.sh | |
ENTRYPOINT /root/setup_and_start.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -m | |
INFLUX_HOST="localhost" | |
INFLUX_API_PORT="8086" | |
API_URL="http://${INFLUX_HOST}:${INFLUX_API_PORT}" | |
wait_for_start_of_influxdb(){ | |
#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 | |
} | |
if [ ! -f "/var/lib/influxdb/.init_script_executed" ] && [ -n "$ADMIN_PASSWORD" ]; then | |
echo "=> Init script : starting InfluxDB in background ..." | |
BACKUP_INFLUXDB_HTTP_AUTH_ENABLED=$INFLUXDB_HTTP_AUTH_ENABLED | |
INFLUXDB_HTTP_AUTH_ENABLED=false | |
exec influxd & | |
wait_for_start_of_influxdb | |
influx -execute "CREATE USER admin WITH PASSWORD '${ADMIN_PASSWORD}' WITH ALL PRIVILEGES;" | |
if [ -n "$USERNAME" ] && [ -n "$PASSWORD" ]; then | |
influx -execute "CREATE USER ${USERNAME} WITH PASSWORD '${PASSWORD}';" | |
fi; | |
if [ -n "$DATABASE_NAME" ] && [ -n "$ADMIN_PASSWORD" ]; then | |
influx -execute "CREATE DATABASE ${DATABASE_NAME};" | |
fi | |
if [ -n "$DATABASE_NAME" ] && [ -n "$USERNAME" ]; then | |
influx -execute "GRANT ALL on ${DATABASE_NAME} to ${USERNAME};" | |
fi; | |
INFLUXDB_HTTP_AUTH_ENABLED=$BACKUP_INFLUXDB_HTTP_AUTH_ENABLED | |
touch "/var/lib/influxdb/.init_script_executed" | |
if ! kill -s TERM %1 || ! wait %1; then | |
echo >&2 'InfluxDB init process failed.' | |
exit 1 | |
fi | |
fi | |
echo "=> Starting InfluxDB in foreground ..." | |
#if [ "${1:0:1}" = '-' ]; then | |
# set -- influxd "$@" | |
#fi | |
# exec $@ | |
exec "influxd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment