简体   繁体   中英

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 ?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM