0

I was always thinking that nothing should execute after bash exec command but recently I found this Google Cloud example

#!/usr/bin/env bash
set -eo pipefail

# Create mount directory for service.
mkdir -p $MNT_DIR

echo "Mounting Cloud Filestore."
mount -o nolock $FILESTORE_IP_ADDRESS:/$FILE_SHARE_NAME $MNT_DIR
echo "Mounting completed."

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app

# Exit immediately when one of the background processes terminate.
wait -n

Maybe my memory was wrong so I searched about this and found this and this. It looks like my memory was correct but maybe there are some exceptions from this.

Will this wait -n actually work in this example?

Thanks.

piotrekkr
  • 2,785
  • 2
  • 21
  • 35
  • I'd say it won't. If exec works, the rest of the script is ignored, if it fails, the script stops because we're running under `set -e`. – choroba Feb 22 '23 at 09:26
  • I've added [bug report to docs](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/9165) but it was closed soon after because apparently when command exits it will go back to original shell process... Idk who is right here but I tested it locally and it seems nothing happens after `exec` – piotrekkr Feb 24 '23 at 08:34
  • 1
    I commented on the closed bug. This is weird. – choroba Feb 24 '23 at 08:52
  • maybe this whole example was meant to be done with gunicorn running as daemon or with `&`. I suppose this `wait -n` could work then. – piotrekkr Feb 24 '23 at 08:57

0 Answers0