How to wait for Redis before I execute yarn start?

Hey Brody,

Before you suggested this command.

/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"

Now, we made an update to the engine image. How can I add or monitor if the Redis is up and running? Thanks!

8 Replies

What I did is I added the environment variable for the redis and it works!


brody
EMPLOYEE

2 years ago

You have used the same command again, but just with the private host and port of the redis service, correct?


Yeah I used it and just add the redis environment there just like this.

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

brody
EMPLOYEE

2 years ago

Thats super unlikely to be valid syntax, you'd need two nc commands.


How do I do that?


This is the exact command I use.

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

Given that, the service can only accept one command.


brody
EMPLOYEE

2 years ago

You would need to use nc twice separately in the while loop.

But it's likely a safe enough bet to assume redis will be available before postgres so as long as you wait on postgres redis is probably going to be up as well, so please remove the invalid syntax with the private url variable.


Hey brody, done removing the part for redis and yes it is fast enough before the postgres becomes available so it should be fine.


Loading...