Skip to content

Commit

Permalink
fix: systemd unit should block on startup until http endpoint is ready (
Browse files Browse the repository at this point in the history
  • Loading branch information
codyshepherd committed Jul 16, 2021
1 parent b01c5f0 commit 9ff6828
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,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"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
1. [21748](https://github.com/influxdata/influxdb/pull/21748): rename arm rpms with yum-compatible names
1. [21851](https://github.com/influxdata/influxdb/pull/21851): Upgrade to latest version of `influxdata/cron` so that tasks can be created with interval of `every: 1w`.
1. [21859](https://github.com/influxdata/influxdb/pull/21859): Avoid rewriting `fields.idx` unnecessarily
1. [xxxxx](https://github.com/influxdata/influxdb/pull/xxxxx): Systemd unit should block on startup until http endpoint is ready

## v2.0.7 [2021-06-04]
----------------------
Expand Down
17 changes: 17 additions & 0 deletions scripts/influxd-systemd-start.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion scripts/influxdb.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ff6828

Please sign in to comment.