diff --git a/bin/docker-worker b/bin/docker-worker index 194ca1e7df6..11d090175e4 100755 --- a/bin/docker-worker +++ b/bin/docker-worker @@ -3,5 +3,12 @@ set -e ./bin/migrate-check +# Stop any background jobs on exit +trap 'kill $(jobs -p)' EXIT + ./bin/plugin-server & -./bin/docker-worker-celery --with-scheduler +./bin/docker-worker-celery --with-scheduler & + +# Exit if any processes exit, and exit with it's exit code +wait -n +exit $? diff --git a/bin/docker-worker-celery b/bin/docker-worker-celery index c36511b54e9..1f5166e9524 100755 --- a/bin/docker-worker-celery +++ b/bin/docker-worker-celery @@ -59,6 +59,9 @@ while test $# -gt 0; do esac done +# Stop any background jobs on exit +trap 'kill $(jobs -p)' EXIT + if [ "$with_scheduler" == "true" ]; then ./bin/docker-worker-beat & fi @@ -80,7 +83,9 @@ echo ./bin/migrate-check -SKIP_ASYNC_MIGRATIONS_SETUP=0 celery -A posthog worker ${FLAGS[*]} +SKIP_ASYNC_MIGRATIONS_SETUP=0 celery -A posthog worker ${FLAGS[*]} & + +# Exit if any processes exit, and exit with it's exit code +wait -n +exit $? -# Stop the beat! -trap 'kill $(jobs -p)' EXIT diff --git a/bin/plugin-server b/bin/plugin-server index 96333865d2b..66427756036 100755 --- a/bin/plugin-server +++ b/bin/plugin-server @@ -44,7 +44,7 @@ fi if [[ -n $NO_RESTART_LOOP ]]; then echo "▶️ Starting plugin server..." - trap 'kill -TERM $child 2>/dev/null; while kill -0 $child 2>/dev/null; do sleep 1; done' SIGTERM + trap 'kill -TERM $child 2>/dev/null; while kill -0 $child 2>/dev/null; do sleep 1; done' EXIT yarn $cmd & child=$! wait $child