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?
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With