@@ -8,7 +8,7 @@ function log_level () {
8
8
echo 2
9
9
elif [ " $1 " = warn ]; then
10
10
echo 1
11
- else
11
+ elif [ " $1 " = error ] ; then
12
12
echo 0
13
13
fi
14
14
}
@@ -19,7 +19,8 @@ LOG_LEVEL=error
19
19
function log () {
20
20
local level=$1 msg=$2
21
21
shift 2
22
- if [ $( log_level ${level} ) -gt $( log_level ${LOG_LEVEL} ) ]; then
22
+
23
+ if [ " $( log_level ${level} ) " -gt " $( log_level ${LOG_LEVEL} ) " ]; then
23
24
return
24
25
fi
25
26
@@ -29,17 +30,17 @@ function log () {
29
30
shift 2
30
31
done
31
32
32
- local logtime=$( date --utc +' %FT%T.%NZ' )
33
+ local logtime=" $( date --utc +' %FT%T.%NZ' ) "
33
34
1>&2 echo -e " ${logtime} \t${level} \t${msg} \t{${attrs} }"
34
35
}
35
36
36
37
# Set the global log-level for the entry-point to match the config passed to influxd.
37
38
function set_global_log_level () {
38
- local level=" $( influxd print-config --key-name log-level ${@ } ) "
39
- if [ -z " $( log_level ${level} ) " ]; then
40
- log error " Invalid log-level specified, using 'error' " level ${level}
39
+ local level=" $( influxd print-config --key-name log-level " ${@ } " ) "
40
+ if [ -z " ${level} " ] || [ -z " $ ( log_level ${level} ) " ]; then
41
+ return 1
41
42
fi
42
- LOG_LEVEL=${level}
43
+ LOG_LEVEL=" ${level} "
43
44
}
44
45
45
46
# Look for standard config names in the volume configured in our Dockerfile.
@@ -50,40 +51,40 @@ readonly CONFIG_NAMES="config.json config.toml config.yaml config.yml"
50
51
function set_config_path () {
51
52
local config_path=/etc/defaults/influxdb2/config.yml
52
53
53
- if [ -n " $INFLUXD_CONFIG_PATH " ]; then
54
- config_path=${INFLUXD_CONFIG_PATH}
54
+ if [ -n " ${ INFLUXD_CONFIG_PATH} " ]; then
55
+ config_path=" ${INFLUXD_CONFIG_PATH} "
55
56
else
56
- for name in $CONFIG_NAMES ; do
57
- if [ -f ${CONFIG_VOLUME} /${name} ]; then
58
- config_path=${CONFIG_VOLUME} /${name}
57
+ for name in ${ CONFIG_NAMES} ; do
58
+ if [ -f " ${CONFIG_VOLUME} /${name} " ]; then
59
+ config_path=" ${CONFIG_VOLUME} /${name} "
59
60
break
60
61
fi
61
62
done
62
63
fi
63
64
64
- export INFLUXD_CONFIG_PATH=${config_path}
65
+ export INFLUXD_CONFIG_PATH=" ${config_path} "
65
66
}
66
67
67
68
function set_data_paths () {
68
- export BOLT_PATH=$( influxd print-config --key-name bolt-path ${@ } )
69
- export ENGINE_PATH=$( influxd print-config --key-name engine-path ${@ } )
69
+ export BOLT_PATH=" $( influxd print-config --key-name bolt-path " ${@ } " ) "
70
+ export ENGINE_PATH=" $( influxd print-config --key-name engine-path " ${@ } " ) "
70
71
}
71
72
72
73
# Ensure all the data directories needed by influxd exist with the right permissions.
73
74
function create_directories () {
74
- local bolt_dir=$( dirname ${BOLT_PATH} )
75
- local user=$( id -u)
75
+ local bolt_dir=" $( dirname " ${BOLT_PATH} " ) "
76
+ local user=" $( id -u) "
76
77
77
- mkdir -p ${bolt_dir} ${ENGINE_PATH}
78
- chmod 700 ${bolt_dir} ${ENGINE_PATH} || :
78
+ mkdir -p " ${bolt_dir} " " ${ENGINE_PATH} "
79
+ chmod 700 " ${bolt_dir} " " ${ENGINE_PATH} " || :
79
80
80
- mkdir -p ${CONFIG_VOLUME} || :
81
- chmod 775 ${CONFIG_VOLUME} || :
81
+ mkdir -p " ${CONFIG_VOLUME} " || :
82
+ chmod 775 " ${CONFIG_VOLUME} " || :
82
83
83
- if [ ${user} = 0 ]; then
84
- find ${bolt_dir} \! -user influxdb -exec chown influxdb ' {}' +
85
- find ${ENGINE_PATH} \! -user influxdb -exec chown influxdb ' {}' +
86
- find ${CONFIG_VOLUME} \! -user influxdb -exec chown influxdb ' {}' +
84
+ if [ " ${user} " = 0 ]; then
85
+ find " ${bolt_dir} " \! -user influxdb -exec chown influxdb ' {}' +
86
+ find " ${ENGINE_PATH} " \! -user influxdb -exec chown influxdb ' {}' +
87
+ find " ${CONFIG_VOLUME} " \! -user influxdb -exec chown influxdb ' {}' +
87
88
fi
88
89
}
89
90
@@ -93,9 +94,9 @@ readonly REQUIRED_INIT_VARS="INFLUXDB_INIT_USERNAME INFLUXDB_INIT_PASSWORD INFLU
93
94
# Ensure all env vars required to run influx setup or influxd upgrade are set in the env.
94
95
function ensure_init_vars_set () {
95
96
local missing_some=0
96
- for var in $REQUIRED_INIT_VARS ; do
97
+ for var in ${ REQUIRED_INIT_VARS} ; do
97
98
if [ -z " $( printenv ${var} ) " ]; then
98
- log error " missing parameter, cannot init InfluxDB" parameter ${var}
99
+ log error " missing parameter, cannot init InfluxDB" parameter " ${var} "
99
100
missing_some=1
100
101
fi
101
102
done
@@ -108,8 +109,8 @@ function ensure_init_vars_set () {
108
109
# If we didn't do this, the container would see the boltdb file on reboot and assume
109
110
# the DB is already full set up.
110
111
function cleanup_influxd () {
111
- log warn " cleaning bolt and engine files to prevent conflicts on retry" bolt_path ${BOLT_PATH} engine_path ${ENGINE_PATH}
112
- rm -rf ${BOLT_PATH} ${ENGINE_PATH}
112
+ log warn " cleaning bolt and engine files to prevent conflicts on retry" bolt_path " ${BOLT_PATH} " engine_path " ${ENGINE_PATH} "
113
+ rm -rf " ${BOLT_PATH} " " ${ENGINE_PATH} "
113
114
}
114
115
115
116
# Upgrade V1 data into the V2 format using influxd upgrade.
@@ -122,40 +123,40 @@ function cleanup_influxd () {
122
123
function upgrade_influxd () {
123
124
set -- \
124
125
--force \
125
- --username ${INFLUXDB_INIT_USERNAME} \
126
- --password ${INFLUXDB_INIT_PASSWORD} \
127
- --org ${INFLUXDB_INIT_ORG} \
128
- --bucket ${INFLUXDB_INIT_BUCKET} \
129
- --v2-config-path ${CONFIG_VOLUME} /config.toml \
130
- --influx-configs-path ${INFLUX_CONFIGS_PATH} \
131
- --continuous-query-export-path ${CONFIG_VOLUME} /v1-cq-export.txt \
132
- --log-path ${CONFIG_VOLUME} /upgrade.log \
133
- --log-level ${LOG_LEVEL} \
134
- --bolt-path ${BOLT_PATH} \
135
- --engine-path ${ENGINE_PATH} \
126
+ --username " ${INFLUXDB_INIT_USERNAME} " \
127
+ --password " ${INFLUXDB_INIT_PASSWORD} " \
128
+ --org " ${INFLUXDB_INIT_ORG} " \
129
+ --bucket " ${INFLUXDB_INIT_BUCKET} " \
130
+ --v2-config-path " ${CONFIG_VOLUME} /config.toml" \
131
+ --influx-configs-path " ${INFLUX_CONFIGS_PATH} " \
132
+ --continuous-query-export-path " ${CONFIG_VOLUME} /v1-cq-export.txt" \
133
+ --log-path " ${CONFIG_VOLUME} /upgrade.log" \
134
+ --log-level " ${LOG_LEVEL} " \
135
+ --bolt-path " ${BOLT_PATH} " \
136
+ --engine-path " ${ENGINE_PATH} " \
136
137
--overwrite-existing-v2
137
138
138
- if [ -n " $INFLUXDB_INIT_RETENTION " ]; then
139
- set -- ${@ } --retention ${INFLUXDB_INIT_RETENTION}
139
+ if [ -n " ${ INFLUXDB_INIT_RETENTION} " ]; then
140
+ set -- " ${@ } " --retention " ${INFLUXDB_INIT_RETENTION} "
140
141
fi
141
- if [ -n " $INFLUXDB_INIT_ADMIN_TOKEN " ]; then
142
- set -- ${@ } --token ${INFLUXDB_INIT_ADMIN_TOKEN}
142
+ if [ -n " ${ INFLUXDB_INIT_ADMIN_TOKEN} " ]; then
143
+ set -- " ${@ } " --token " ${INFLUXDB_INIT_ADMIN_TOKEN} "
143
144
fi
144
145
145
- if [[ -n " $INFLUXDB_INIT_UPGRADE_V1_CONFIG " && -f ${INFLUXDB_INIT_UPGRADE_V1_CONFIG} ]]; then
146
- set -- ${@ } --config-file ${INFLUXDB_INIT_UPGRADE_V1_CONFIG}
147
- elif [[ -n " $INFLUXDB_INIT_UPGRADE_V1_DIR " && -d ${INFLUXDB_INIT_UPGRADE_V1_DIR} ]]; then
148
- set -- ${@ } --v1-dir ${INFLUXDB_INIT_UPGRADE_V1_DIR}
146
+ if [[ -n " ${ INFLUXDB_INIT_UPGRADE_V1_CONFIG} " && -f " ${INFLUXDB_INIT_UPGRADE_V1_CONFIG} " ]]; then
147
+ set -- " ${@ } " --config-file " ${INFLUXDB_INIT_UPGRADE_V1_CONFIG} "
148
+ elif [[ -n " ${ INFLUXDB_INIT_UPGRADE_V1_DIR} " && -d " ${INFLUXDB_INIT_UPGRADE_V1_DIR} " ]]; then
149
+ set -- " ${@ } " --v1-dir " ${INFLUXDB_INIT_UPGRADE_V1_DIR} "
149
150
elif [ -f /etc/influxdb/influxdb.conf ]; then
150
- set -- ${@ } --config-file /etc/influxdb/influxdb.conf
151
+ set -- " ${@ } " --config-file /etc/influxdb/influxdb.conf
151
152
elif [ -d /var/lib/influxdb ]; then
152
- set -- ${@ } --v1-dir /var/lib/influxdb
153
+ set -- " ${@ } " --v1-dir /var/lib/influxdb
153
154
else
154
155
log error " failed to autodetect usable V1 config or data dir, aborting upgrade"
155
156
exit 1
156
157
fi
157
158
158
- influxd upgrade ${@ }
159
+ influxd upgrade " ${@ } "
159
160
160
161
# Reset global influxd config to pick up new file written by the upgrade process.
161
162
set_config_path
@@ -185,27 +186,27 @@ function wait_for_influxd () {
185
186
function setup_influxd () {
186
187
set -- \
187
188
--force \
188
- --username ${INFLUXDB_INIT_USERNAME} \
189
- --password ${INFLUXDB_INIT_PASSWORD} \
190
- --org ${INFLUXDB_INIT_ORG} \
191
- --bucket ${INFLUXDB_INIT_BUCKET}
189
+ --username " ${INFLUXDB_INIT_USERNAME} " \
190
+ --password " ${INFLUXDB_INIT_PASSWORD} " \
191
+ --org " ${INFLUXDB_INIT_ORG} " \
192
+ --bucket " ${INFLUXDB_INIT_BUCKET} "
192
193
193
- if [ -n " $INFLUXDB_INIT_RETENTION " ]; then
194
- set -- ${@ } --retention ${INFLUXDB_INIT_RETENTION}
194
+ if [ -n " ${ INFLUXDB_INIT_RETENTION} " ]; then
195
+ set -- " ${@ } " --retention " ${INFLUXDB_INIT_RETENTION} "
195
196
fi
196
- if [ -n " $INFLUXDB_INIT_ADMIN_TOKEN " ]; then
197
- set -- ${@ } --token ${INFLUXDB_INIT_ADMIN_TOKEN}
197
+ if [ -n " ${ INFLUXDB_INIT_ADMIN_TOKEN} " ]; then
198
+ set -- " ${@ } " --token " ${INFLUXDB_INIT_ADMIN_TOKEN} "
198
199
fi
199
200
200
- influx setup ${@ }
201
+ influx setup " ${@ } "
201
202
}
202
203
203
204
# Get the IDs of the initial user/org/bucket created during setup, and export them into the env.
204
205
# We do this to help with arbitrary user scripts, since many influx CLI commands only take IDs.
205
206
function set_init_resource_ids () {
206
- export INFLUXDB_INIT_USER_ID=$( influx user list -n ${INFLUXDB_INIT_USER} --hide-headers | cut -f 1)
207
- export INFLUXDB_INIT_ORG_ID=$( influx org list -n ${INFLUXDB_INIT_ORG} --hide-headers | cut -f 1)
208
- export INFLUXDB_INIT_BUCKET_ID=$( influx bucket list -n ${INFLUXDB_INIT_BUCKET} --hide-headers | cut -f 1)
207
+ export INFLUXDB_INIT_USER_ID=" $( influx user list -n " ${INFLUXDB_INIT_USER} " --hide-headers | cut -f 1) "
208
+ export INFLUXDB_INIT_ORG_ID=" $( influx org list -n " ${INFLUXDB_INIT_ORG} " --hide-headers | cut -f 1) "
209
+ export INFLUXDB_INIT_BUCKET_ID=" $( influx bucket list -n " ${INFLUXDB_INIT_BUCKET} " --hide-headers | cut -f 1) "
209
210
}
210
211
211
212
# Allow users to mount arbitrary startup scripts into the container,
@@ -230,31 +231,31 @@ function handle_signal () {
230
231
# Perform initial setup on the InfluxDB instance, either by setting up fresh metadata
231
232
# or by upgrading existing V1 data.
232
233
function init_influxd () {
233
- if [[ ${INFLUXDB_INIT_MODE} != setup && ${INFLUXDB_INIT_MODE} != upgrade ]]; then
234
- log error " found invalid INFLUXDB_INIT_MODE, valid values are 'setup' and 'upgrade'" INFLUXDB_INIT_MODE ${INFLUXDB_INIT_MODE}
234
+ if [[ " ${INFLUXDB_INIT_MODE} " != setup && " ${INFLUXDB_INIT_MODE} " != upgrade ]]; then
235
+ log error " found invalid INFLUXDB_INIT_MODE, valid values are 'setup' and 'upgrade'" INFLUXDB_INIT_MODE " ${INFLUXDB_INIT_MODE} "
235
236
exit 1
236
237
fi
237
238
ensure_init_vars_set
238
239
trap " cleanup_influxd" EXIT
239
240
240
241
# The upgrade process needs to run before we boot the server, otherwise the
241
242
# boltdb file will be generated and cause conflicts.
242
- if [ ${INFLUXDB_INIT_MODE} = upgrade ]; then
243
+ if [ " ${INFLUXDB_INIT_MODE} " = upgrade ]; then
243
244
upgrade_influxd
244
245
fi
245
246
246
247
# Generate a config file with a known HTTP port
247
248
local init_config=/tmp/config.yml
248
- local final_bind_addr=$( influxd print-config --key-name http-bind-address ${@ } )
249
+ local final_bind_addr=" $( influxd print-config --key-name http-bind-address " ${@ } " ) "
249
250
local init_bind_addr=" :${INFLUXD_INIT_PORT} "
250
- if [ ${init_bind_addr} = ${final_bind_addr} ]; then
251
- log warn " influxd setup binding to same addr as final config, server will be exposed before ready" addr ${init_bind_addr}
251
+ if [ " ${init_bind_addr} " = " ${final_bind_addr} " ]; then
252
+ log warn " influxd setup binding to same addr as final config, server will be exposed before ready" addr " ${init_bind_addr} "
252
253
fi
253
- influxd print-config ${@ } | sed " s#${final_bind_addr} #${init_bind_addr} #" > ${init_config}
254
+ influxd print-config " ${@ } " | sed " s#${final_bind_addr} #${init_bind_addr} #" > ${init_config}
254
255
255
256
# Start influxd in the background.
256
257
log info " booting influxd server in the background"
257
- INFLUXD_CONFIG_PATH=${init_config} influxd ${@ } &
258
+ INFLUXD_CONFIG_PATH=${init_config} influxd " ${@ } " &
258
259
local influxd_init_pid=" $! "
259
260
trap " handle_signal TERM ${influxd_init_pid} " TERM
260
261
trap " handle_signal INT ${influxd_init_pid} " INT
@@ -263,34 +264,34 @@ function init_influxd () {
263
264
wait_for_influxd
264
265
265
266
# Use the influx CLI to create an initial user/org/bucket.
266
- if [ ${INFLUXDB_INIT_MODE} = setup ]; then
267
+ if [ " ${INFLUXDB_INIT_MODE} " = setup ]; then
267
268
setup_influxd
268
269
fi
269
270
270
271
set_init_resource_ids
271
272
run_user_scripts
272
273
273
274
log info " initialization complete, shutting down background influxd"
274
- kill -TERM ${influxd_init_pid}
275
- wait ${influxd_init_pid} || true
276
- trap - EXIT
275
+ kill -TERM " ${influxd_init_pid} "
276
+ wait " ${influxd_init_pid} " || true
277
+ trap - EXIT INT TERM
277
278
278
279
# Rewrite the ClI configs to point at the server's final HTTP address.
279
- local final_port=$( echo ${final_bind_addr} | sed -E ' s#[^:]*:(.*)#\1#' )
280
- sed -i " s#http://localhost:${INFLUXD_INIT_PORT} #http://localhost:${final_port} #g" ${INFLUX_CONFIGS_PATH}
280
+ local final_port=" $( echo ${final_bind_addr} | sed -E ' s#[^:]*:(.*)#\1#' ) "
281
+ sed -i " s#http://localhost:${INFLUXD_INIT_PORT} #http://localhost:${final_port} #g" " ${INFLUX_CONFIGS_PATH} "
281
282
}
282
283
283
284
# Run influxd, with optional setup logic.
284
285
function influxd_main () {
285
- if test -f ${BOLT_PATH} ; then
286
- log info " found existing boltdb file, skipping setup wrapper" bolt_path ${BOLT_PATH}
287
- elif [ -z " $INFLUXDB_INIT_MODE " ]; then
288
- log warn " boltdb not found at configured path, but INFLUXDB_INIT_MODE not specified, skipping setup wrapper" bolt_path ${bolt_path}
286
+ if test -f " ${BOLT_PATH} " ; then
287
+ log info " found existing boltdb file, skipping setup wrapper" bolt_path " ${BOLT_PATH} "
288
+ elif [ -z " ${ INFLUXDB_INIT_MODE} " ]; then
289
+ log warn " boltdb not found at configured path, but INFLUXDB_INIT_MODE not specified, skipping setup wrapper" bolt_path " ${bolt_path} "
289
290
else
290
- init_influxd ${@ }
291
+ init_influxd " ${@ } "
291
292
fi
292
293
293
- exec influxd ${@ }
294
+ exec influxd " ${@ } "
294
295
}
295
296
296
297
function main () {
@@ -313,23 +314,23 @@ function main () {
313
314
fi
314
315
315
316
# Configure logging for our wrapper.
316
- set_global_log_level ${@ }
317
+ set_global_log_level " ${@ } "
317
318
# Configure data paths used across functions.
318
- set_data_paths ${@ }
319
+ set_data_paths " ${@ } "
319
320
# Ensure volume directories exist w/ correct permissions.
320
321
create_directories
321
322
fi
322
323
323
- if [ $( id -u) = 0 ]; then
324
- exec gosu influxdb " $0 " ${@ }
324
+ if [ " $( id -u) " = 0 ]; then
325
+ exec gosu influxdb " $0 " " ${@ } "
325
326
return
326
327
fi
327
328
328
329
if ${run_influxd} ; then
329
- influxd_main ${@ }
330
+ influxd_main " ${@ } "
330
331
else
331
- exec ${@ }
332
+ exec " ${@ } "
332
333
fi
333
334
}
334
335
335
- main ${@ }
336
+ main " ${@ } "
0 commit comments