How to wait for the service before spin another service?

Just wondering how to do that. Instead of deploying the services at the same time. Is this possible?

18 Replies

2 years ago

It's not currently possible natively with Railway, the best you could do would be to use nc to wait for the database (since I'm pretty sure I know the context of this question)


Yup you know the context, we want to make sure that the database is running before deploying the source image.

Btw, it is working successfully now, there's an issue with our dashboard that it says that the instance or the service is not publicly accessible.


2 years ago

What happens when you visit the domain generated for the service?


It works here's the example: http://viaduct.proxy.rlwy.net:10511/json


2 years ago

You wouldn't want to be using the TCP proxy for HTTP, you'd want to use the HTTP proxy for HTTP.


How can I setup the HTTP proxy for HTTP? Generate domain?


2 years ago

Correct. But it sounds like you are using the v1 template composer, I would highly recommend you use the v2 composer -

https://railway.app/compose


Yeah tried that but it doesn't show a response from the browser is that intended?

In addition, how to make the public network HTTPS?


I'm using the compose from the dashboard.


2 years ago

Sure it does! - https://thirdweb-engine-production-ee27.up.railway.app/json

HTTPS is automatically done by Railway.


It works now Brody!

We can now publish the template.


2 years ago

Awsome, I look forward to giving feedback on that!


How about the nc thing how to do that with the setup? Where can I put that?


2 years ago

You could update the service's start command to -

/bin/sh -c "echo 'Waiting for database...'; while ! nc -z ${PGHOST_PRIVATE} ${PGPORT_PRIVATE}; do sleep 0.5; done; echo 'Database is now available'; exec /sbin/tini -- yarn start"

This means you need two additional variables on the service -

PGHOST_PRIVATE=${{Postgres.PGPRIVATEHOST}}
PGPORT_PRIVATE=5432

Tini would also like you to set a TINI_SUBREAPER variable to 1


Alright, the above start command will also work with "source image" not a github repo?

Tini would also like you to set a TINI_SUBREAPER variable to 1

Do I need to add this too in the env?


2 years ago

Alright, the above start command will also work with "source image" not a github repo?

If the image is built using that Dockerfile in your repo, yes absolutely!

Tini would also like you to set a TINI_SUBREAPER variable to 1

Do I need to add this too in the env?

Yeah as a service variable!


Hey Brody works!

Finalizing and will publish in a minute, thanks for all the help!


2 years ago

Awsome!


Loading...