Vagrant ssh -c and saving the background process after closing the connection

I am writing a script to run and a background process inside a stray computer. It seems that every time the script ends and the ssh session ends, the background process also ends.

The command is executed here:

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

hello.pyin fact, it is only a flask development server. If I were to log in to ssh interactively and run the command nohupmanually, after the session was closed, the server would continue to work. However, if I were to run it through vagrant ssh -c, it is almost as if the command had never been run at all (i.e. the hello.out file was not created). What is the difference between starting it manually and using the ssh -c firewall, and how to fix it so that it works?

+4
source share
2 answers

I encountered the same problem when trying to run a Django application as a daemon. I don’t know why, but adding “sleep 1” at work is for me.

vagrant ssh -c "nohup python manage.py runserver & sleep 1"
+10
source

Running nohup inside the ssh command did not work for me when running wirehark. It is happened:

nohup vagrant ssh -c "wireshark" &
0
source

All Articles