From c8de72ddbc5fdf20f821ca473f1fdf92820f9ac3 Mon Sep 17 00:00:00 2001 From: Cody Shepherd Date: Fri, 16 Jul 2021 08:13:26 -0700 Subject: [PATCH] fix: systemd unit should block on startup until http endpoint is ready (#21850) * fix: systemd unit should block on startup until http endpoint is ready * chore: update changelog --- .goreleaser.yml | 2 ++ CHANGELOG.md | 1 + scripts/influxd-systemd-start.sh | 17 +++++++++++++++++ scripts/influxdb.service | 4 +++- 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 scripts/influxd-systemd-start.sh diff --git a/.goreleaser.yml b/.goreleaser.yml index 2fe7e520625..c417eaa0d01 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -45,6 +45,8 @@ nfpms: dst: /etc/logrotate.d/influxdb - src: scripts/influxdb2-upgrade.sh dst: /usr/share/influxdb/influxdb2-upgrade.sh + - src: scripts/influxd-systemd-start.sh + dst: /usr/lib/influxdb/scripts/influxd-systemd-start.sh scripts: preinstall: "scripts/pre-install.sh" postinstall: "scripts/post-install.sh" diff --git a/CHANGELOG.md b/CHANGELOG.md index 78bd1ab3dba..5ce5efd2781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ This release adds an embedded SQLite database for storing metadata required by t 1. [21844](https://github.com/influxdata/influxdb/pull/21844): Upgrade to latest version of `influxdata/cron` so that tasks can be created with interval of `every: 1w`. 1. [21849](https://github.com/influxdata/influxdb/pull/21849): Specify which fields are missing when rejecting an incomplete onboarding request. 1. [21839](https://github.com/influxdata/influxdb/pull/21839): Fix display and parsing of `influxd upgrade` CLI prompts in PowerShell. +1. [21850](https://github.com/influxdata/influxdb/pull/21850): Systemd unit should block on startup until http endpoint is ready ## v2.0.7 [2021-06-04] diff --git a/scripts/influxd-systemd-start.sh b/scripts/influxd-systemd-start.sh new file mode 100755 index 00000000000..7162768fa17 --- /dev/null +++ b/scripts/influxd-systemd-start.sh @@ -0,0 +1,17 @@ +#!/bin/bash -e + +/usr/bin/influxd & +echo $! > /var/lib/influxdb/influxd.pid + +BIND_ADDRESS=$(influxd print-config --key-name http-bind-address) +HOST=${BIND_ADDRESS%%:*} +HOST=${HOST:-"localhost"} +PORT=${BIND_ADDRESS##*:} + +set +e +result=$(curl -s -o /dev/null http://$HOST:$PORT/ready -w %{http_code}) +while [ "$result" != "200" ]; do + sleep 1 + result=$(curl -s -o /dev/null http://$HOST:$PORT/ready -w %{http_code}) +done +set -e diff --git a/scripts/influxdb.service b/scripts/influxdb.service index 063d7034a51..ee48e6ced49 100644 --- a/scripts/influxdb.service +++ b/scripts/influxdb.service @@ -10,9 +10,11 @@ User=influxdb Group=influxdb LimitNOFILE=65536 EnvironmentFile=-/etc/default/influxdb2 -ExecStart=/usr/bin/influxd +ExecStart=/usr/lib/influxdb/scripts/influxd-systemd-start.sh KillMode=control-group Restart=on-failure +Type=forking +PIDFile=/var/lib/influxdb/influxd.pid [Install] WantedBy=multi-user.target