I have a group with 3 tasks:
- database
- init task
- app
I want to first start database, wait for tcp health check, run the (idempotent) init task that ensures migrations have run, then start the app. This should be relatively simple but I have two problems:
- The companion sidecar docs mention things like log shippers but not databases, and the init task docs show a convoluted wait-for-db example with netcat instead of relying on health check. This makes me think that this is the wrong approach for working with databases.
- If both database and init task are
prestart
then they will start at ~the same time, and the init task will die due not being able to connect to db. This can potentially work if we repeatedly restart the init task with enough grace period for db to likely come up, but this is not a clean or deterministic solution.
Is this the wrong way of approaching this problem? I could potentially move the init logic to the app task, but my actual setup is more complex than this simplified example (multiple app tasks which may enter lock contention if they all try to run init at the same time) so this would not be a clean solution.