Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for multiple services #2

Closed
andrewshawcare opened this issue Mar 7, 2016 · 13 comments
Closed

Wait for multiple services #2

andrewshawcare opened this issue Mar 7, 2016 · 13 comments

Comments

@andrewshawcare
Copy link

It would be ideal if multiple services (i.e. multiple host:port combinations) could be declared such that the command is executed only after all dependent services are available.

@vishnubob
Copy link
Owner

I feel like this is better solved by either a top level script that orchestrates the logic of such a situation or chaining multiple wait-for-it commands together.

@andrewshawcare
Copy link
Author

Yeah, I did that but that approach is potentially misleading.

For example:

./wait-for-it.sh service-a:1234 -- ./wait-for-it.sh service-b:1234 -- docker-entrypoint.sh

Logically, is service-b dependent on service-a? In my case it isn't (so they shouldn't be chained). In my view, it would be clearer to have:

./wait-for-it.sh service-a:1234 service-b:1234 -- docker-entrypoint.sh

Structurally, there should be two options:

container -> {service-a, service-b} // set denotes mutually-exclusive dependencies
container -> [service-a, service-b] // list denotes dependency order

A chain provides a list mechanism and multiple host:port arguments provides a set mechanism.

@vishnubob
Copy link
Owner

A high-level script is your best option to solving this particular use case, as it allows you the flexibility you need in testing and interpreting the various states that arise in your specific scenario. wait-for-it is intentionally designed to keep-it-simple, leaving the use-case you describe as an exercise for the reader. Feel free to fork and tailor to your needs.

@jlordiales
Copy link

@vishnubob did you get to implement your use case? I was looking to do exactly the same

@vishnubob
Copy link
Owner

@jlordiales: i think you meant to ask @andrewshawcare, since he originally posted the issue.

@jlordiales
Copy link

Yes @vishnubob, sorry it was late :)

@jlordiales
Copy link

@andrewshawcare FWIW I implemented this on https://github.com/jlordiales/wait-for-it/blob/master/wait-for-it.sh (for my use case at least). You can specify multiple host:port pairs and the whole thing will fail as soon as the first host times out

@Forever-Young
Copy link

Didn't see this issue, also implemented this: Forever-Young@f9aa0c1

@frastel
Copy link

frastel commented Mar 8, 2017

Could this issue be closed as "won't fix" so it is clear that this high-level functionality shouldn't be integrated in this project?
As vishnubob already mentioned it makes totally sense to keep this script as simple as possible and to not patch this script for this reason.

@Forever-Young
Copy link

I guess it's enough to have some receipts just in the issue comments.

@clarketm
Copy link

clarketm commented Oct 2, 2019

There is a python version of wait-for-it that supports waiting for multiple services. It is blocking and will wait for the services to be available in sequential order.

e.g.

Assuming both python3 and wait-for-it are installed.

$ 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 (in that order)"

Here are the docs!

@Feche-314
Copy link

Feche-314 commented Sep 10, 2021

There is also a shell script called docker-compose-wait which allows this required behaviour:

version: "3"

services:
  mongo:
    image: mongo:3.4
    hostname: mongo
    ports:
      - "27017:27017"

  postgres:
    image: "postgres:9.4"
    hostname: postgres
    ports:
      - "5432:5432"

  mysql:
    image: "mysql:5.7"
    hostname: mysql
    ports:
      - "3306:3306"

  mySuperApp:
    image: "mySuperApp:latest"
    hostname: mySuperApp
    environment:
      WAIT_HOSTS: postgres:5432, mysql:3306, mongo:27017

@codan84
Copy link

codan84 commented Aug 17, 2022

There is also a shell script called docker-compose-wait which allows this required behaviour:

version: "3"

services:
  mongo:
    image: mongo:3.4
    hostname: mongo
    ports:
      - "27017:27017"

  postgres:
    image: "postgres:9.4"
    hostname: postgres
    ports:
      - "5432:5432"

  mysql:
    image: "mysql:5.7"
    hostname: mysql
    ports:
      - "3306:3306"

  mySuperApp:
    image: "mySuperApp:latest"
    hostname: mySuperApp
    environment:
      WAIT_HOSTS: postgres:5432, mysql:3306, mongo:27017

Thanks for this tip, much better imo and not dependant on bash present in the image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants