Post-deployment script cannot be exited

Hi everyone,
I have been wrestling with this issue for a while without being able to find a solution.

I send my Django code to a server using rsync. After updating the code, I need to do a couple of things, such as running migrations and reloading gunicorn.
I put a post_deploy.sh bash script on the server, which contains the tasks that I want to perform. Everything goes well, but I am not able to exit the script. Which means that CircleCI never ends the build ! It just keeps going for ever.

I have tried multiple things, putting exit at the end of my script, running the command in the background, adding && exit in the circle.yml file, and nothing seems to do the trick… Any help is welcomed !

My circle.yml file:

deployment:
  production:
    branch: master
    commands:
      - rsync --update ./post_deploy.sh user@mysite:app/post_deploy.sh
      - rsync -r --update ./myapp/ user@mysite:app/myapp/
      - ssh -i ~/.ssh/id_mysite user@mysite 'app/post_deploy.sh'

The post_deploy.sh file:

source /home/ubuntu/.virtualenvs/venv/bin/activate
cd /home/user/app/
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
ps aux |grep gunicorn |awk '{ print $2 }'|xargs kill
gunicorn -c config/gunicorn.conf.py config.wsgi &
deactivate
echo 'Post deployment script done'
exit
1 Like

pipe the output of your post_deploy.sh script to /dev/null and put the command into the background like:
ssh -i ~/.ssh/id_mysite user@mysite ‘app/post_deploy.sh > /dev/null &’