Tuesday, March 29, 2022

[SOLVED] Why nohup on execute resource doesn't work - Chef recipe

Issue

I'm trying to deploy a django app (dev mode) using chef. The problem is, when execute the recipe the server doesn't kept alive.The command works when I log in, but because it doesn't change the session. Any suggestions are helpful.

execute 'django_run' do
  user 'root'
  cwd '/var/www/my-app/'
  command 'source ./.venv/bin/activate && sudo -E nohup python2 ./manage.py runserver 0.0.0.0:8000 > /dev/null 2>&1 &'
end

Solution

I suspect some weirdness with sudo and & is at-play here. Try to use sudo -b instead of ampersand. Also a better way to do this may be to use the service chef resource instead of execute: https://docs.chef.io/resources/service/



Answered By - Tony
Answer Checked By - Gilberto Lyons (WPSolving Admin)