From e3c01f8afd42c656ff3d54b5f395e0743abc2b34 Mon Sep 17 00:00:00 2001 From: William Pain Date: Fri, 29 Jan 2016 11:19:10 +0100 Subject: [PATCH 1/3] Fix: start daemon directly in foreground for signal handling --- 0.9/run.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/0.9/run.sh b/0.9/run.sh index a95cfa8..9a9e477 100755 --- a/0.9/run.sh +++ b/0.9/run.sh @@ -90,12 +90,6 @@ fi echo "influxdb configuration: " cat ${CONFIG_FILE} -echo "=> Starting InfluxDB ..." -if [ -n "${JOIN}" ]; then - exec influxd -config=${CONFIG_FILE} -join ${JOIN} & -else - exec influxd -config=${CONFIG_FILE} & -fi # Pre create database on the initiation of the container if [ -n "${PRE_CREATE_DB}" ]; then @@ -103,6 +97,10 @@ if [ -n "${PRE_CREATE_DB}" ]; then if [ -f "/data/.pre_db_created" ]; then echo "=> Database had been created before, skipping ..." else + echo "=> Starting InfluxDB in background ..." + influxd -config=${CONFIG_FILE} & + pid="$!" + arr=$(echo ${PRE_CREATE_DB} | tr ";" "\n") #wait for the startup of influxdb @@ -135,9 +133,20 @@ if [ -n "${PRE_CREATE_DB}" ]; then fi touch "/data/.pre_db_created" + + echo "=> Stopping InfluxDB ..." + if ! kill -s TERM "$pid" || ! wait "$pid"; then + echo >&2 'InfluxDB init process failed.' + exit 1 + fi fi else echo "=> No database need to be pre-created" fi -fg +echo "=> Starting InfluxDB in foreground ..." +if [ -n "${JOIN}" ]; then + exec influxd -config=${CONFIG_FILE} -join ${JOIN} +else + exec influxd -config=${CONFIG_FILE} +fi From e51485873c58bff7cdf5b50574f10156406c460f Mon Sep 17 00:00:00 2001 From: William Pain Date: Wed, 10 Feb 2016 16:18:13 +0100 Subject: [PATCH 2/3] Fix indentation --- 0.9/run.sh | 76 +++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/0.9/run.sh b/0.9/run.sh index 1eaf6a9..20e6418 100755 --- a/0.9/run.sh +++ b/0.9/run.sh @@ -106,49 +106,49 @@ echo "influxdb configuration: " cat ${CONFIG_FILE} echo "=> Starting InfluxDB ..." if [ -n "${JOIN}" ]; then - exec influxd -config=${CONFIG_FILE} -join ${JOIN} & + exec influxd -config=${CONFIG_FILE} -join ${JOIN} & else - exec influxd -config=${CONFIG_FILE} & + exec influxd -config=${CONFIG_FILE} & fi if [ -f "/data/.init_script_executed" ]; then - echo "=> The initialization script had been executed before, skipping ..." + echo "=> The initialization script had been executed before, skipping ..." else - #Create the admin user - if [ -n "${ADMIN_USER}" ] || [ -n "${INFLUXDB_INIT_PWD}" ]; then - wait_for_start_of_influxdb - echo "=> Creating admin user" - influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -execute="CREATE USER ${ADMIN} WITH PASSWORD '${PASS}' WITH ALL PRIVILEGES" - fi - - # 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}" - arr=$(echo ${PRE_CREATE_DB} | tr ";" "\n") - - for x in $arr - do - echo "=> Creating database: ${x}" - echo "CREATE DATABASE ${x}" >> /tmp/init_script.influxql - done - fi - - # Execute influxql queries contained inside /init_script.influxql - if [ -f "/init_script.influxql" ] || [ -f "/tmp/init_script.influxql" ]; then - echo "=> About to execute the initialization script" - - cat /init_script.influxql >> /tmp/init_script.influxql - - wait_for_start_of_influxdb - - echo "=> Executing the influxql script..." - influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -username=${ADMIN} -password="${PASS}" -import -path /tmp/init_script.influxql - - echo "=> Influxql script executed." - touch "/data/.init_script_executed" - else - echo "=> No initialization script need to be executed" - fi + #Create the admin user + if [ -n "${ADMIN_USER}" ] || [ -n "${INFLUXDB_INIT_PWD}" ]; then + wait_for_start_of_influxdb + echo "=> Creating admin user" + influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -execute="CREATE USER ${ADMIN} WITH PASSWORD '${PASS}' WITH ALL PRIVILEGES" + fi + + # 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}" + arr=$(echo ${PRE_CREATE_DB} | tr ";" "\n") + + for x in $arr + do + echo "=> Creating database: ${x}" + echo "CREATE DATABASE ${x}" >> /tmp/init_script.influxql + done + fi + + # Execute influxql queries contained inside /init_script.influxql + if [ -f "/init_script.influxql" ] || [ -f "/tmp/init_script.influxql" ]; then + echo "=> About to execute the initialization script" + + cat /init_script.influxql >> /tmp/init_script.influxql + + wait_for_start_of_influxdb + + echo "=> Executing the influxql script..." + influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -username=${ADMIN} -password="${PASS}" -import -path /tmp/init_script.influxql + + echo "=> Influxql script executed." + touch "/data/.init_script_executed" + else + echo "=> No initialization script need to be executed" + fi fi fg From b7b434e839e1a8e87022db092ca24e4ba5aa91bd Mon Sep 17 00:00:00 2001 From: William Pain Date: Wed, 10 Feb 2016 16:38:12 +0100 Subject: [PATCH 3/3] Start Influxdb in foreground --- 0.9/run.sh | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/0.9/run.sh b/0.9/run.sh index 20e6418..9081439 100755 --- a/0.9/run.sh +++ b/0.9/run.sh @@ -102,21 +102,20 @@ if [ -n "${UDP_PORT}" ]; then fi -echo "influxdb configuration: " -cat ${CONFIG_FILE} -echo "=> Starting InfluxDB ..." -if [ -n "${JOIN}" ]; then - exec influxd -config=${CONFIG_FILE} -join ${JOIN} & -else - exec influxd -config=${CONFIG_FILE} & -fi - if [ -f "/data/.init_script_executed" ]; then echo "=> The initialization script had been executed before, skipping ..." else + echo "=> Starting InfluxDB in background ..." + if [ -n "${JOIN}" ]; then + exec influxd -config=${CONFIG_FILE} -join ${JOIN} & + else + exec influxd -config=${CONFIG_FILE} & + fi + + wait_for_start_of_influxdb + #Create the admin user if [ -n "${ADMIN_USER}" ] || [ -n "${INFLUXDB_INIT_PWD}" ]; then - wait_for_start_of_influxdb echo "=> Creating admin user" influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -execute="CREATE USER ${ADMIN} WITH PASSWORD '${PASS}' WITH ALL PRIVILEGES" fi @@ -139,8 +138,6 @@ else cat /init_script.influxql >> /tmp/init_script.influxql - wait_for_start_of_influxdb - echo "=> Executing the influxql script..." influx -host=${INFLUX_HOST} -port=${INFLUX_API_PORT} -username=${ADMIN} -password="${PASS}" -import -path /tmp/init_script.influxql @@ -149,6 +146,17 @@ else else echo "=> No initialization script need to be executed" fi + + echo "=> Stopping InfluxDB ..." + if ! kill -s TERM %1 || ! wait %1; then + echo >&2 'InfluxDB init process failed.' + exit 1 + fi fi -fg +echo "=> Starting InfluxDB in foreground ..." +if [ -n "${JOIN}" ]; then + exec influxd -config=${CONFIG_FILE} -join ${JOIN} +else + exec influxd -config=${CONFIG_FILE} +fi