流浪ssh -c并在关闭连接后保持后台进程运行 [英] vagrant ssh -c and keeping a background process running after connection closed

查看:95
本文介绍了流浪ssh -c并在关闭连接后保持后台进程运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本来启动和运行无业游民的机器内部的进程.似乎每次脚本结束和ssh会话结束时,后台进程也结束.

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实际上只是一个flask开发服务器.如果我要交互式登录ssh并手动运行nohup命令,则在关闭会话后,服务器将继续运行.但是,如果我要通过vagrant ssh -c运行它,几乎就像该命令根本没有运行过(即未创建hello.out文件).手动和通过流浪的ssh -c运行它有什么区别,以及如何对其进行修复以使其起作用?

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?

推荐答案

在尝试将Django应用程序作为守护程序运行时,我遇到了同样的问题.我不知道为什么,但是在我后面添加"sleep 1"对我有用.

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"

这篇关于流浪ssh -c并在关闭连接后保持后台进程运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆