Code Monkey home page Code Monkey logo

wait-for-it's Introduction

Issues


wait-for-it

A Golang package to wait on the availability of a TCP host and port.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

About The Project

wait-for-it

This package is adapted from vishnubob/wait-for-it, a popular project used to wait for TCP connections until a service is up. This is commonly used in docker-compose files to make one service wait for another, for example, to make a web server wait for a mysql database.

Since vishnubob/wait-for-it is a bash script, it does not work directly with minimal containers like scratch, which are commonly used to run binaries.

With the help of this package, you can generate a binary, which can run inside minimal Docker containers and wait for a TCP connection such as a mysql database. You can find an example here: csivitu/bl0b.

Built With

Getting Started

A amd64 (64-bit) executables for linux, darwin, and windows are available in the GitHub releases.

If you want to build a binary for a different Operating System / Architecture, you can follow the procedure below.

Prerequisites

The only prerequisite is golang which you can get here.

  • go

Installation

  1. Get the package using go install.
go install github.com/roerohan/wait-for-it

Alternatively, you can follow these steps:

  1. Clone the repository.
git clone https://github.com/roerohan/wait-for-it
  1. Build a go binary from source.
cd wait-for-it
go build -o ./bin/wait-for-it
  1. Use the binary inside the bin folder.
./bin/wait-for-it google.com:80 -- echo "It works\!"

Usage

The usage is similar to vishnubob/wait-for-it.

Use wait-for-it -h to display the following list.

Usage of wait-for-it:
  -q    Quiet, don't output any status messages
  -s    Only execute subcommand if the test succeeds
  -t int
        Timeout in seconds, zero for no timeout (default 15)
  -w host:port
        Services to be waiting for, in the form host:port

You can run any executable after passing --, like in the examples below.

Examples:

  1. Waiting for multiple services in parallel.
wait-for-it -w google.com:80 -w localhost:27017 -t 30 -- echo "Waiting for 30 seconds for google.com:80 and localhost:27017"
  1. Strict mode will not execute the subcommand only if TCP connection was successful.
$ wait-for-it -w abcd:80 -s -t 5 -- echo "Done\!"
wait-for-it: waiting 5 seconds for abcd:80
wait-for-it: timeout occured after waiting for 5 seconds
wait-for-it: strict mode, refusing to execute subprocess

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'feat: Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

You are requested to follow the contribution guidelines specified in CONTRIBUTING.md while contributing to the project 😄.

License

Distributed under the MIT License. See LICENSE for more information.

wait-for-it's People

Contributors

roerohan avatar stupidscience avatar sonya avatar stevanmilic avatar

Stargazers

irieda avatar  avatar Viktor (Icon) VAD 🍀 avatar andoks avatar David Hernandez avatar yujonglee avatar  avatar Brandon Jaus avatar Dennis R Kennetz avatar Ladislav Prskavec avatar Wes McNamee avatar Sylvain Dumont avatar Miles Maddox avatar  avatar Aaron avatar  avatar Dave  avatar Andrew Gerst avatar Kilian von Pflugk avatar Nikita Buyevich avatar Thành Thân Thiện avatar Oscar David Díaz avatar Giovanbattista Amato avatar Willie Möller avatar Patrik Majer avatar Vojtěch Mareš avatar Ondrej Sika avatar Thomas Erhel avatar Prakash Rai avatar David Douglas avatar Ashikka Gupta avatar  avatar

Watchers

James Cloos avatar Adam Yu avatar  avatar

wait-for-it's Issues

Return cmd output on error

Hi, thanks for this nice utility!

Is it possible to exit the wait-for-it program with error exit code in case underlying command returns an error? Doing so would indicate the command we were waiting for has failed, and that we need to address it somehow.

I can submit a PR for this, if this is acceptable behavior.

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.