Skip to content

Commit

Permalink
fix: handle https in systemd wrapper, and prevent it from looping for…
Browse files Browse the repository at this point in the history
…ever
  • Loading branch information
codyshepherd committed Aug 3, 2021
1 parent df8d3d3 commit a06e751
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions scripts/influxd-systemd-start.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
#!/bin/bash -e

/usr/bin/influxd -config /etc/influxdb/influxdb.conf $INFLUXD_OPTS &
echo $! > /var/lib/influxdb/influxd.pid
PID=$!
echo $PID > /var/lib/influxdb/influxd.pid

PROTOCOL="http"
BIND_ADDRESS=$(influxd config | grep -A5 "\[http\]" | grep '^ bind-address' | cut -d ' ' -f5 | tr -d '"')
HTTPS_ENABLED_FOUND=$(influxd config | grep "https-enabled = true" | sed 's/^ *//g' | cut -d ' ' -f3)
HTTPS_ENABLED=${HTTPS_ENABLED_FOUND:-"false"}
if [ $HTTPS_ENABLED = "true" ]; then
HTTPS_CERT=$(influxd config | grep "https-certificate" | sed 's/^ *//g' | cut -d ' ' -f3 | tr -d '"')
if [ ! -f "${HTTPS_CERT}" ]; then
echo "${HTTPS_CERT} not found! Exiting..."
exit 1
fi
echo "$HTTPS_CERT found"
PROTOCOL="https"
fi
HOST=${BIND_ADDRESS%%:*}
HOST=${HOST:-"localhost"}
PORT=${BIND_ADDRESS##*:}

set +e
result=$(curl -s -o /dev/null http://$HOST:$PORT/health -w %{http_code})
max_attempts=10
url="$PROTOCOL://$HOST:$PORT/health"
result=$(curl -k -s -o /dev/null $url -w %{http_code})
while [ "$result" != "200" ]; do
sleep 1
result=$(curl -s -o /dev/null http://$HOST:$PORT/health -w %{http_code})
result=$(curl -k -s -o /dev/null $url -w %{http_code})
max_attempts=$(($max_attempts-1))
if [ $max_attempts -le 0 ]; then
echo "Failed to reach influxdb $PROTOCOL endpoint at $url"
exit 1
fi
done
set -e

0 comments on commit a06e751

Please sign in to comment.