在执行命令之前等待服务可用。
wait-for-it的Python项目详细描述
wait-for-it
在执行命令之前等待服务可用。
wait-for-it
是在执行用户定义的命令之前等待一个或多个TCP服务(即host:port
)可用性的脚本。
它对于同步相互依赖的服务(如链接的Docker容器)的启动非常有用。
Check out the wait-for-it docs
安装
$ pip install wait-for-it
演示
用法
Usage: wait-for-it [OPTIONS] [COMMANDS]... Wait for service(s) to be available before executing a command. Options: -h, --help Show this message and exit. -v, --version Show the version and exit. -q, --quiet Do not output any status messages -s, --service host:port Services to test, in the format host:port -t, --timeout seconds Timeout in seconds, 0 for no timeout [default: 15]
示例
测试是否可以访问www.google.com上的端口80,如果可用,则回显消息google is up:
$ wait-for-it \ --service www.google.com:80 \ -- echo"google is up"
waiting 15 seconds for www.google.com:80 www.google.com:80 is available after 0 seconds google is up
您可以使用-t
或--timeout
选项设置自己的超时。将超时值设置为0将禁用超时:
$ wait-for-it \ --service www.google.com:80 \ --timeout 0\ -- echo"google is up"
waiting for www.google.com:80 without a timeout www.google.com:80 is available after 0 seconds google is up
可以通过添加附加的-s
或--service
选项来测试多个服务:
$ wait-for-it \ --service www.google.com:80 \ --service www.bing.com:80 \ --service www.duckduckgo.com:80 \ -- echo"google, bing, and duckduckgo are up"
waiting 15 seconds for www.google.com:80 www.google.com:80 is available after 0 seconds waiting 15 seconds for www.bing.com:80 www.bing.com:80 is available after 0 seconds waiting 15 seconds for www.duckduckgo.com:80 www.duckduckgo.com:80 is available after 0 seconds google, bing, and duckduckgo are up
可以使用-q
或--quiet
选项抑制状态消息输出:
$ wait-for-it \ --quiet \ --service www.google.com:80 \ -- echo"google is up"
google is up
相关
许可证
麻省理工学院Travis Clarke