【问题标题】:How to wait until services are ready如何等到服务准备好
【发布时间】:2018-12-03 23:28:44
【问题描述】:

我一直在使用 docker 映像设置 Jenkins 管道。现在我需要运行各种服务,如 MySQL、Redis、Memcache、Beanstalkd 和 Elasticsearch。为了等到 MySQL 准备就绪,我正在使用以下命令:

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

mysqlhost 是我为容器提供的主机名。同样,我需要检查并等待Redis, Memcached, Beanstalkd and Elasticsearch。但是 ping 这些服务并没有像 MySQL 那样工作。我该如何实现呢?

【问题讨论】:

    标签: linux shell docker jenkins sh


    【解决方案1】:

    Docker docs 提到此脚本来管理容器就绪检查:https://github.com/vishnubob/wait-for-it

    我也使用与 Alpine 兼容的这个: https://github.com/eficode/wait-for

    【讨论】:

      【解决方案2】:

      您可以对此服务进行 curl 以检查它们是否还活着。 对于redis你也可以https://redis.io/commands/ping

      【讨论】:

      • 您可以循环执行,直到获得所需的回复。对于 kubernetes pod,我们做类似的事情。我们循环 curl 到一个端点,直到我们没有得到 200 并且我们不继续。
      猜你喜欢
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 2019-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多