Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vagrant ssh -c and keeping a background process running after connection closed

Tags:

linux

vagrant

I am writing a script to start and background a process inside a vagrant machine. It seems like every time the script ends and the ssh session ends, the background process also ends.

Here's the command I am running:

vagrant ssh -c "cd /vagrant/src; nohup python hello.py > hello.out > 2>&1 &"

hello.py is actually just a flask development server. If I were to login to ssh interactively and run the nohup command manually, after I close the session, the server will continue to run. However, if I were to run it via vagrant ssh -c, it's almost as if the command never ran at all (i.e. no hello.out file created). What is the difference between running it manually and through vagrant ssh -c, and how to fix it so that it works?

like image 598
prentice Avatar asked Aug 15 '14 18:08

prentice


1 Answers

I faced the same problem when trying to run Django application as a daemon. I don't know why, but adding a "sleep 1" behind works for me.

vagrant ssh -c "nohup python manage.py runserver & sleep 1"
like image 101
Aickson Avatar answered Sep 21 '22 13:09

Aickson