Skip to content

Commit 638aee9

Browse files
authored
Detect when --help is passed to influxdb and skip steps that break. (#486)
1 parent a7aabe0 commit 638aee9

File tree

3 files changed

+109
-12
lines changed

3 files changed

+109
-12
lines changed

influxdb/2.0/alpine/entrypoint.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ function influxd_main () {
298298
exec influxd "${@}"
299299
}
300300

301+
# Check if the --help or -h flag is set in a list of CLI args.
302+
function check_help_flag () {
303+
for arg in "${@}"; do
304+
if [ "${arg}" = --help ] || [ "${arg}" = -h ]; then
305+
return 0
306+
fi
307+
done
308+
return 1
309+
}
310+
301311
function main () {
302312
# Ensure INFLUXD_CONFIG_PATH is set.
303313
# We do this even if we're not running the main influxd server so subcommands
@@ -320,12 +330,15 @@ function main () {
320330
shift 1
321331
fi
322332

323-
# Configure logging for our wrapper.
324-
set_global_log_level "${@}"
325-
# Configure data paths used across functions.
326-
set_data_paths "${@}"
327-
# Ensure volume directories exist w/ correct permissions.
328-
create_directories
333+
334+
if ! check_help_flag "${@}"; then
335+
# Configure logging for our wrapper.
336+
set_global_log_level "${@}"
337+
# Configure data paths used across functions.
338+
set_data_paths "${@}"
339+
# Ensure volume directories exist w/ correct permissions.
340+
create_directories
341+
fi
329342

330343
if [ "$(id -u)" = 0 ]; then
331344
exec gosu influxdb "$BASH_SOURCE" "${@}"

influxdb/2.0/entrypoint.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ function influxd_main () {
298298
exec influxd "${@}"
299299
}
300300

301+
# Check if the --help or -h flag is set in a list of CLI args.
302+
function check_help_flag () {
303+
for arg in "${@}"; do
304+
if [ "${arg}" = --help ] || [ "${arg}" = -h ]; then
305+
return 0
306+
fi
307+
done
308+
return 1
309+
}
310+
301311
function main () {
302312
# Ensure INFLUXD_CONFIG_PATH is set.
303313
# We do this even if we're not running the main influxd server so subcommands
@@ -320,12 +330,15 @@ function main () {
320330
shift 1
321331
fi
322332

323-
# Configure logging for our wrapper.
324-
set_global_log_level "${@}"
325-
# Configure data paths used across functions.
326-
set_data_paths "${@}"
327-
# Ensure volume directories exist w/ correct permissions.
328-
create_directories
333+
334+
if ! check_help_flag "${@}"; then
335+
# Configure logging for our wrapper.
336+
set_global_log_level "${@}"
337+
# Configure data paths used across functions.
338+
set_data_paths "${@}"
339+
# Ensure volume directories exist w/ correct permissions.
340+
create_directories
341+
fi
329342

330343
if [ "$(id -u)" = 0 ]; then
331344
exec gosu influxdb "$BASH_SOURCE" "${@}"

influxdb/test/cases/test-help

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
declare -r SCRIPT_DIR=$(cd $(dirname $0) >/dev/null 2>&1 && pwd)
5+
source ${SCRIPT_DIR}/common.sh
6+
7+
declare -r tag=$1 container_name=$2 data=$3 config=$4 logs=$5
8+
9+
declare -ra docker_run_influxd=(docker run --rm -i influxdb:${tag})
10+
11+
log_msg Checking various --help commands
12+
13+
# Check that --help works.
14+
if ! ${docker_run_influxd[@]} --help > "${logs}/help.txt"; then
15+
log_msg Error: Failed to run --help
16+
exit 1
17+
fi
18+
if ! grep -q 'Start up the daemon' "${logs}/help.txt"; then
19+
log_msg Error: "${logs}/help.txt" missing expected output
20+
exit 1
21+
fi
22+
23+
# Check that -h works.
24+
if ! ${docker_run_influxd[@]} -h > "${logs}/h.txt"; then
25+
log_msg Error: Failed to run -h
26+
exit 1
27+
fi
28+
if ! grep -q 'Start up the daemon' "${logs}/h.txt"; then
29+
log_msg Error: "${logs}/h.txt" missing expected output
30+
exit 1
31+
fi
32+
33+
# Check that influxd --help works.
34+
if ! ${docker_run_influxd[@]} influxd --help > "${logs}/influxd-help.txt"; then
35+
log_msg Error: Failed to run influxd --help
36+
exit 1
37+
fi
38+
if ! grep -q 'Start up the daemon' "${logs}/influxd-help.txt"; then
39+
log_msg Error: "${logs}/influxd-help.txt" missing expected output
40+
exit 1
41+
fi
42+
43+
# Check that influxd -h works.
44+
if ! ${docker_run_influxd[@]} influxd -h > "${logs}/influxd-h.txt"; then
45+
log_msg Error: Failed to run influxd -h
46+
exit 1
47+
fi
48+
if ! grep -q 'Start up the daemon' "${logs}/influxd-h.txt"; then
49+
log_msg Error: "${logs}/influxd-h.txt" missing expected output
50+
exit 1
51+
fi
52+
53+
# Check that influxd print-config --help works.
54+
if ! ${docker_run_influxd[@]} influxd print-config --help > "${logs}/influxd-config-help.txt"; then
55+
log_msg Error: Failed to run influxd pring-config --help
56+
exit 1
57+
fi
58+
if ! grep -q 'Print config (in YAML)' "${logs}/influxd-config-help.txt"; then
59+
log_msg Error: "${logs}/influxd-config-help.txt" missing expected output
60+
exit 1
61+
fi
62+
63+
# Check that influx --help works.
64+
if ! ${docker_run_influxd[@]} influx --help > "${logs}/influx-help.txt"; then
65+
log_msg Error: Failed to run influx --help
66+
exit 1
67+
fi
68+
if ! grep -q 'Influx Client' "${logs}/influx-help.txt"; then
69+
log_msg Error: "${logs}/influx-help.txt" missing expected output
70+
exit 1
71+
fi

0 commit comments

Comments
 (0)