在执行命令之前等待服务可用。
项目描述
wait-for-it
在执行命令之前等待服务可用。
wait-for-it
是一个脚本,它会在执行用户定义的命令之前等待一个或多个TCP服务(即host:port
)的可用性。它对于同步启动相互依赖的服务非常有用,例如连接的docker容器。
从v2.0.0版本开始,
wait-for-it
将返回执行命令的退出码。
安装
$ 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
-p, --parallel Test services in parallel rather than in serial
-t, --timeout seconds Timeout in seconds, 0 for no timeout [default: 15]
-s, --service host:port Services to test, in one of the formats: ':port',
'hostname:port', 'v4addr:port', '[v6addr]:port' or
'https://...'
示例
测试我们是否可以访问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
通过添加-p
或--parallel
选项,wait-for-it
可以在并行而不是串行中执行相同的操作
$ wait-for-it \
--parallel \
--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.bing.com:80
[*] Waiting 15 seconds for www.duckduckgo.com:80
[*] Waiting 15 seconds for www.google.com:80
[+] www.bing.com:80 is available after 0 seconds
[+] www.duckduckgo.com:80 is available after 0 seconds
[+] www.google.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
相关
许可
MIT © Travis Clarke, Sebastian Pipping
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪一个,请了解更多关于 安装包 的信息。
源代码分发
wait-for-it-2.2.2.tar.gz (18.3 MB 查看哈希值)
构建分发
wait_for_it-2.2.2-py3-none-any.whl (8.1 kB 查看哈希值)