Happy Coder
Happy Coder

Reputation: 4692

How to wait until services are ready

I have been setting up a Jenkins pipeline using docker images. Now I need to run various services like MySQL, Redis, Memcache, Beanstalkd and Elasticsearch. To wait the job until MySQL is ready, I am using the following command :

sh "while ! mysqladmin ping -u root -h mysqlhost ; do sleep 1; done"
sh 'echo MySQL server is up and running'

Where mysqlhost is the hostname I have provided for the container. Similarly, I need to check and wait for Redis, Memcached, Beanstalkd and Elasticsearch. But pinging to these services are not working as it is done for MySQL . How can I implement this ?

Upvotes: 0

Views: 1640

Answers (2)

sp0gg
sp0gg

Reputation: 4132

The Docker docs mention this script to manage container readiness checks: https://github.com/vishnubob/wait-for-it

I also use this one which is compatible with Alpine: https://github.com/eficode/wait-for

Upvotes: 1

Guel135
Guel135

Reputation: 788

You can do a curl to this services in order to check if they are alive or not. For redis you can also do https://redis.io/commands/ping

Upvotes: 0

Related Questions