prentice
prentice

Reputation: 353

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

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?

Upvotes: 6

Views: 3224

Answers (2)

MattK
MattK

Reputation: 1561

Running nohup inside the ssh command did not work for me when running wireshark. This did:

nohup vagrant ssh -c "wireshark" &

Upvotes: 2

Aickson
Aickson

Reputation: 151

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"

Upvotes: 13

Related Questions