Coder Social home page Coder Social logo

bgsrb / wait4it Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ph4r5h4d/wait4it

0.0 1.0 0.0 202 KB

A simple go application to test whether a port or a service is ready or not

License: GNU General Public License v3.0

Go 98.48% Dockerfile 1.52%

wait4it's Introduction

wait4it

LICENSE Docker Pull GO Version TAG LICENSE

A simple go application to test whether a port is ready to accept a connection or check MySQL, PostgreSQL, MongoDB or Redis server is ready or not, Also you can do Http call and check the response code and text in response.
It also supports timeout so it can wait for a particular time and then fail.

Supported Modules

  • TCP port
  • MySQL
  • PostgresQL
  • Http
  • MongoDB
  • Redis
  • RabbitMQ
  • Memcached
  • ElasticSearch
  • Aerospike

Install

You can download the latest release, or you can build it yourself. To build just run go build -o wait4it

Configuration

Environment variables

The following environment variables are supported:

  • W4IT_TYPE (check type [http, tcp, mysql, postgres])
  • W4IT_TIMEOUT (timeout in seconds)
  • W4IT_HOST (the host to check)
  • W4IT_PORT (port to check on the host)
  • W4IT_USERNAME (username for the services that needs username)
  • W4IT_PASSWORD (password for the services that needs password)
  • W4IT_DBNAME (database name for MySQL or PostgreSQL)
  • W4IT_SSL_MODE (whether to enable or disable ssl-mode for Postgres [disable, enable])
  • W4IT_OPERATION_MODE (to select operation mode for redis [standalone, cluster])
  • W4IT_HTTP_STATUS_CODE (for Http check, which status code to expect)
  • W4IT_HTTP_TEXT (for Http check, find substring inside the response)

Command Line Args

The following command-line flags are supported

  • -type (check type [http, tcp, mysql, postgres])
  • -h (the host to check, default is 127.0.0.1)
  • -p (port to check on the host)
  • -t (timeout in seconds, time to wait before considering the operation as failed. default is 30)
  • -u (username for the services that needs username)
  • -P (password for the services that needs password)
  • -n (database name for MySQL or PostgreSQL)
  • -ssl (whether to enable or disable ssl-mode for Postgres [disable, enable])
  • -operation-mode (to select operation mode for redis [standalone, cluster])
  • -http-status (for Http check, which status code to expect)
  • -http-text (for Http check, find substring inside the response)

Sample

Check a TCP port

./wait4it -h=127.0.0.1 -p=8080 -t=60

Check a MySQL instance

./wait4it -h=127.0.0.1 -p=3306 -t=60 -u=root -P=secret -n=app 

Check a PostgresQL instance

./wait4it -type=postgres -h=127.0.0.1 -p=5432 -t=60 -u=postgres -P=secret -ssl=disable

Check HTTP response and text

./wait4it -type=http -h=https://farshad.nematdoust.com -t=60 -status-code=200 -http-text="Software Engineer" 

Check a MongoDB instance

./wait4it -type=mongo -p=27017 -t=60  -u=mongoadmin -P=secret -h=127.0.0.1

Check a Redis instance

./wait4it -type=redis -p=6379 -t=60 -P=secret -h=127.0.0.1

# if your redis is not password protected
./wait4it -type=redis -p=6379 -t=60 -h=127.0.0.1

# if you use redis cluster
./wait4it -type=redis -p=6379 -t=60 -P=secret -operation-mode=cluster -h=127.0.0.1

Check a RabbitMQ instance

./wait4it -type=rabbitmq -p=5267 -t=60  -u=guest -P=guest -h=127.0.0.1

Check a Memcached instance

./wait4it -type=memcached -h=127.0.0.1 -p=11211 -t=60

Check ElasticSearch instance

./wait4it -type=elasticsearch -h=http://127.0.0.1 -p=9200 -t=60

Check a Aerospike instance

./wait4it -type=aerospike -h=127.0.0.1 -p=3000 -t=60

Docker

You can run this wait4it inside a docker container, and it's possible to run this container as init container inside K8s and Openshift.
You can use the following image in Docker Hub:
docker pull ph4r5h4d/wait4it

Inside container you can do the following:

Sample

Check a TCP port

docker run ph4r5h4d/wait4it -h=127.0.0.1 -p=8080 -t=60

Check a MySQL instance

docker run ph4r5h4d/wait4it -h=127.0.0.1 -p=3306 -t=60 -u=root -P=secret -n=app 

Check a PostgresQL instance

docker run ph4r5h4d/wait4it -type=postgres -h=127.0.0.1 -p=5432 -t=60 -u=postgres -P=secret -ssl=disable

Check HTTP response and text

docker run ph4r5h4d/wait4it -type=http -h=https://farshad.nematdoust.com -t=60 -status-code=200 -http-text="Software Engineer" 

Check a MongoDB instance

docker run ph4r5h4d/wait4it -type=mongo -p=32768 -t=60  -u=mongoadmin -P=secret -h=127.0.0.1

Check a RabbitMQ instance

docker run ph4r5h4d/wait4it -type=rabbitmq -p=5267 -t=60  -u=guest -P=guest -h=127.0.0.1

Check a Redis instance

docker run ph4r5h4d/wait4it -type=redis -p=6379 -t=60 -P=secret -h=127.0.0.1

# if your redis is not password protected
docker run ph4r5h4d/wait4it -type=redis -p=6379 -t=60 -h=127.0.0.1

# if you use redis cluster
docker run ph4r5h4d/wait4it -type=redis -p=6379 -t=60 -P=secret -operation-mode=cluster -h=127.0.0.1

Check a Memcached instance

docker run ph4r5h4d/wait4it -type=memcached -h=127.0.0.1 -p=11211

Check a ElasticSearch instance

docker run ph4r5h4d/wait4it -type=elasticsearch -h=http://127.0.0.1 -p=9200

Check a Aerospike instance

docker run ph4r5h4d/wait4it -type=aerospike -h=127.0.0.1 -p=3000 -t=60

Notes

Configuration

  • note that environment variables have higher priority than command-line arguments. This means if you define both W4IT_TYPE and -type, the application takes the value of the environment variable into account.

Exit codes

  • 0: connection established successfully
  • 1: timed out
  • 2: mostly means a validation error or something wrong with the input data

Http check

  • for the Http check if you do not define status code it will check for 200 status code
  • if http-text is not defined then wait4it will check the status code

Postgres check

  • if ssl is not defined then it's disable by default

MongoDB check

  • for the moment only username/password authentication mechanism is supported.

Redis check

  • if operation-mode is not defined then it's standalone by default. Redis Sentinel is not supported yet.
  • this version can only check one host within Redis cluster, using multiple hosts to check cluster status for Redis will be added in the next version.

Memcached check

  • for the moment multiple hosts and cluster checks are not supported.

ElasticSearch

  • for the moment multiple hosts and cluster checks are not supported.
  • as you know, username/password authentication mechanism is only supported along with the X-Pack extension and if the X-Pack extension wasn't activated, filling username/password won't have any effect. According to these reasons, username/password isn't required.

wait4it's People

Contributors

2hamed avatar amirsoleimani avatar itsmatinx avatar mhmazrooei avatar ph4r5h4d avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.