-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle https in systemd wrapper, and prevent it from looping for…
…ever
- Loading branch information
1 parent
df8d3d3
commit a06e751
Showing
1 changed file
with
26 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|