Our API server depends on an active instance of Elasticsearch. Therefore, before we start our API server, let's make sure our Elasticsearch service is active. Add the following check under the shebang line:
RETRY_INTERVAL=${RETRY_INTERVAL:-0.2}if ! systemctl --quiet is-active elasticsearch.service; then sudo systemctl start elasticsearch.service # Wait until Elasticsearch is ready to respond until curl --silent $ELASTICSEARCH_HOSTNAME:$ELASTICSEARCH_PORT -w "" -o /dev/null; do sleep $RETRY_INTERVAL donefi
First, we use the is-active command of systemctl to check whether the Elasticsearch service is active; the command will exit with a 0 if it is active, and a non-zero value if not.
Generally, when a process ...