Code Monkey home page Code Monkey logo

Comments (18)

ettore26 avatar ettore26 commented on July 2, 2024 16

In the meantime wait-for-command can help. It is a Posix sh compliant which receives a command an waits for a specific exit status to finish waiting. It does not depend on a specific command so you could use whatever your distribution has available.

In Alpine Linux for port 5432 you could do:

  • ./wait-for-command.sh -c 'nc -z db 5432' && [your-after-the-wait-commands]

Also for other distributions you could use:

  • wait-for-command.sh -c 'echo > /dev/tcp/127.0.0.1/5432' && [your-after-the-wait-commands]
  • wait-for-command.sh -s 0 57 -c 'curl 127.0.0.1:5432' && [your-after-the-wait-commands]

Notice you can specify the matching exit status with -s.

from wait-for-it.

maxcnunes avatar maxcnunes commented on July 2, 2024 10

Let me share a tool I have written in Go with cross platform support and which has the same purpose of this project (even the name is the same) https://github.com/maxcnunes/waitforit.

from wait-for-it.

ohsun0405 avatar ohsun0405 commented on July 2, 2024 5

I'd rather using nc command on alpine to wait for tcp connection.

while ! nc -z rails 3000 ; do sleep 1 ; done

from wait-for-it.

yakhyadabo avatar yakhyadabo commented on July 2, 2024 3

It doesn't work for Alpine Linux.

from wait-for-it.

raphaelahrens avatar raphaelahrens commented on July 2, 2024 2

I made an POSIX version, which you can find here.
It uses nc and @vishnubob prefers a version that has minimum dependencies, so it was not merged.
See the closed pull request

from wait-for-it.

typekpb avatar typekpb commented on July 2, 2024 2

hey guys, maybe a bit late for the party, but there is another (POSIX shell compliant) alternative capable of waiting for any type of command called: wtfc.
It's heavily inspired by @ettore26 solution and well tested on different envs (Busybox, Alpine, Debian, OSX, see: https://travis-ci.org/typekpb/wtfc)

from wait-for-it.

raphaelahrens avatar raphaelahrens commented on July 2, 2024 1

@blacktop Ah ok I will take a look at it seems like alpine doesn't have timeout either.

from wait-for-it.

eddieajau avatar eddieajau commented on July 2, 2024 1

@raphaelahrens so the problem is that when our Docker machine is spinning up, some of the containers take time to register their host names. While wait-for-it will genuinely wait for a port to open, it exits immediately if the host is not yet resolvable. This is because nc will exit with a code of 1 immediately, causing timeout to exit as well.

So the issue is that wait-for-it also needs to be able to wait for a host to be available within the given TIMEOUT.

from wait-for-it.

blacktop avatar blacktop commented on July 2, 2024

First off thank you @raphaelahrens that is awesome! second off @vishnubob I understand your desire to keep the dependancies to 0, but nc is included in alpine and with the docker community all moving to alpine I think it would still be valuable?

@raphaelahrens when I run your script with no timeout setting I kept getting the error: timeout: can't execute '15': No such file or directory 15 being the default TIMEOUT. However, when I used -1 no-timeout it worked?

from wait-for-it.

raphaelahrens avatar raphaelahrens commented on July 2, 2024

@blacktop could you create an issue on my fork and describe how you call the script and under which OS/distro?

from wait-for-it.

blacktop avatar blacktop commented on July 2, 2024

it looks like it is the same thing that happened here #5

from wait-for-it.

blacktop avatar blacktop commented on July 2, 2024

also there is no UI in github for issues on forks.

from wait-for-it.

blacktop avatar blacktop commented on July 2, 2024

Pull Requests #17 fixes it for me, but requires I install bash :(

from wait-for-it.

blacktop avatar blacktop commented on July 2, 2024

@maxcnunes that is a really nice solution to this problem πŸ‘

from wait-for-it.

james-turner avatar james-turner commented on July 2, 2024

There is always https://github.com/depop/wait-for-it but it has a reliance on bash shell. It also supports multiple host waits

from wait-for-it.

eddieajau avatar eddieajau commented on July 2, 2024

@raphaelahrens have you had any trouble with nc returning a "bad address" error?

from wait-for-it.

raphaelahrens avatar raphaelahrens commented on July 2, 2024

@eddieajau no I haven't. Sounds like an address resolution problem. Is the address reachable from the machine/vm?

from wait-for-it.

MichaelMackus avatar MichaelMackus commented on July 2, 2024

πŸ‘

Would much prefer a POSIX version, but @ettore26's solution should be good enough for now.

from wait-for-it.

Related Issues (20)

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.