
ph4r5h4d/wait4it一个简单的Go应用程序,用于测试端口是否准备好接受连接,或检查MySQL、PostgreSQL、MongoDB、Redis等服务是否就绪。还可进行HTTP调用并检查响应码和响应文本,支持超时设置,可在等待特定时间后失败。
可下载最新发布版,或自行构建。构建命令:go build
支持以下环境变量:
W4IT_TYPE:检查类型(http, tcp, mysql, postgres等)W4IT_TIMEOUT:超时时间(秒)W4IT_HOST:目标主机W4IT_PORT:目标端口W4IT_USERNAME:服务认证用户名W4IT_PASSWORD:服务认证密码W4IT_DBNAME:MySQL/PostgreSQL数据库名W4IT_SSL_MODE:PostgreSQL SSL模式(disable/enable)W4IT_OPERATION_MODE:Redis操作模式(standalone/cluster)W4IT_HTTP_STATUS_CODE:HTTP检查期望状态码W4IT_HTTP_TEXT:HTTP响应中需包含的子字符串W4IT_HTTP_FOLLOW_REDIRECT:HTTP是否跟随重定向(true/false,默认true)支持以下命令行标志:
-type:检查类型(http, tcp, mysql, postgres等)-h:目标主机(默认127.0.0.1)-p:目标端口-t:超时时间(秒,默认30)-u:服务认证用户名-P:服务认证密码-n:MySQL/PostgreSQL数据库名-ssl:PostgreSQL SSL模式(disable/enable)-operation-mode:Redis操作模式(standalone/cluster)-http-status:HTTP检查期望状态码-http-text:HTTP响应中需包含的子字符串-http-follow-redirect:HTTP是否跟随重定向(true/false,默认true)bash./wait4it -type=tcp -h=127.0.0.1 -p=8080 -t=60
bash./wait4it -type=mysql -h=127.0.0.1 -p=3306 -t=60 -u=root -P=secret -n=app
bash./wait4it -type=postgres -h=127.0.0.1 -p=5432 -t=60 -u=postgres -P=secret -ssl=disable
bash./wait4it -type=http -h=[***] -t=60 -http-status=200 -http-text="Software Engineer" ./wait4it -type=http -h=[***] -t=60 -http-status=301 -http-follow-redirect=false
bash./wait4it -type=mongo -p=27017 -t=60 -u=mongoadmin -P=secret -h=127.0.0.1
bash# 带密码的Redis ./wait4it -type=redis -p=6379 -t=60 -P=secret -h=127.0.0.1 # 无密码的Redis ./wait4it -type=redis -p=6379 -t=60 -h=127.0.0.1 # Redis集群 ./wait4it -type=redis -p=6379 -t=60 -P=secret -operation-mode=cluster -h=127.0.0.1
bash# RabbitMQ ./wait4it -type=rabbitmq -p=5267 -t=60 -u=guest -P=guest -h=127.0.0.1 # Memcached ./wait4it -type=memcached -h=127.0.0.1 -p=*** -t=60 # ElasticSearch ./wait4it -type=elasticsearch -h=[***] -p=9200 -t=60 # Aerospike ./wait4it -type=aerospike -h=127.0.0.1 -p=3000 -t=60
可在Docker容器中运行,也可作为K8s/OpenShift初始化容器。镜像地址:docker pull ph4r5h4d/wait4it
bashdocker run ph4r5h4d/wait4it -type=tcp -h=127.0.0.1 -p=8080 -t=60
bashdocker run ph4r5h4d/wait4it -type=mysql -h=127.0.0.1 -p=3306 -t=60 -u=root -P=secret -n=app
bashdocker run ph4r5h4d/wait4it -type=postgres -h=127.0.0.1 -p=5432 -t=60 -u=postgres -P=secret -ssl=disable
bashdocker run ph4r5h4d/wait4it -type=http -h=[***] -t=60 -http-status=200 -http-text="Software Engineer" docker run ph4r5h4d/wait4it -type=http -h=[***] -t=60 -http-status=301 -http-follow-redirect=false
bash# MongoDB docker run ph4r5h4d/wait4it -type=mongo -p=32768 -t=60 -u=mongoadmin -P=secret -h=127.0.0.1 # Redis集群 docker run ph4r5h4d/wait4it -type=redis -p=6379 -t=60 -P=secret -operation-mode=cluster -h=127.0.0.1 # ElasticSearch docker run ph4r5h4d/wait4it -type=elasticsearch -h=[***] -p=9200
环境变量优先级高于命令行参数,若同时设置,以环境变量为准。
http-text时仅检查状态码manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务