@@ -154,24 +154,21 @@ function upgrade_influxd () {
154
154
set_config_path
155
155
}
156
156
157
- # Wait up to a minute for the DB to boot
158
- declare -r STARTUP_PING_WAIT_SECONDS=2
159
- declare -r STARTUP_PING_ATTEMPTS=30
160
-
161
- # Ping influxd until it responds.
157
+ # Ping influxd until it responds or crashes.
162
158
# Used to block execution until the server is ready to process setup requests.
163
159
function wait_for_influxd () {
160
+ local -r influxd_pid=$1
164
161
local ping_count=0
165
- while [ ${ping_count} -lt ${STARTUP_PING_ATTEMPTS} ]; do
166
- sleep ${STARTUP_PING_WAIT_SECONDS}
167
- log info " pinging influxd..."
162
+ while kill -0 " ${influxd_pid} " ; do
163
+ sleep 1
164
+ log info " pinging influxd..." ping_attempt ${ping_count}
165
+ ping_count=$(( ping_count+ 1 ))
168
166
if influx ping & > /dev/null; then
169
- log info " got response from influxd, proceeding"
167
+ log info " got response from influxd, proceeding" total_pings ${ping_count}
170
168
return
171
169
fi
172
- ping_count=$(( ping_count+ 1 ))
173
170
done
174
- log error " failed to detect influxd startup" ping_attempts ${ping_count}
171
+ log error " influxd crashed during startup" total_pings ${ping_count}
175
172
exit 1
176
173
}
177
174
@@ -207,6 +204,14 @@ function set_init_resource_ids () {
207
204
# for execution after initial setup/upgrade.
208
205
declare -r USER_SCRIPT_DIR=/docker-entrypoint-initdb.d
209
206
207
+ # Check if user-defined setup scripts have been mounted into the container.
208
+ function user_scripts_present () {
209
+ if [ ! -d ${USER_SCRIPT_DIR} ]; then
210
+ return 1
211
+ fi
212
+ test -n " $( find ${USER_SCRIPT_DIR} -name " *.sh" -type f -executable) "
213
+ }
214
+
210
215
# Execute all shell files mounted into the expected path for user-defined startup scripts.
211
216
function run_user_scripts () {
212
217
if [ -d ${USER_SCRIPT_DIR} ]; then
@@ -238,6 +243,13 @@ function init_influxd () {
238
243
upgrade_influxd
239
244
fi
240
245
246
+ # Short-circuit if using upgrade mode and user didn't define any custom scripts,
247
+ # to save startup time from booting & shutting down the server.
248
+ if [ " ${DOCKER_INFLUXDB_INIT_MODE} " = upgrade ] && ! user_scripts_present; then
249
+ trap - EXIT
250
+ return
251
+ fi
252
+
241
253
# Capture final bind address, and check it is distinct from init addr
242
254
local -r final_bind_addr=" $( influxd print-config --key-name http-bind-address " ${@ } " ) "
243
255
local -r init_bind_addr=" :${INFLUXD_INIT_PORT} "
@@ -253,7 +265,7 @@ function init_influxd () {
253
265
trap " handle_signal INT ${influxd_init_pid} " INT
254
266
255
267
export INFLUX_HOST=" http://localhost:${INFLUXD_INIT_PORT} "
256
- wait_for_influxd
268
+ wait_for_influxd " ${influxd_init_pid} "
257
269
258
270
# Use the influx CLI to create an initial user/org/bucket.
259
271
if [ " ${DOCKER_INFLUXDB_INIT_MODE} " = setup ]; then
0 commit comments