关闭我的ssh会话后,如何保持Django服务器的运行? [英] How do I keep my Django server running even after I close my ssh session?

查看:841
本文介绍了关闭我的ssh会话后,如何保持Django服务器的运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想出如何通过 sudo python /home/david/myproject/manage.py runserver 68.164.125.221:80 运行我的Django应用程序。但是,在我退出终端后,服务器停止运行。



我在后台运行这个进程,但服务器在执行 sudo python /home/david/myproject/manage.py runserver 68.164.125.221:80&



我如何保持我的Django应用程序即使在终端终止我的ssh会话之后仍在运行?



PS - 如果这个问题引起了你的关注,对不起,当前端的JavaScript程序员必须变成服务器管理员时,这种愚蠢的事情就是分崩离析的。

解决方案

认识屏幕



通过ssh连接,开始画面这个在ssh提供的虚拟控制台模拟器上打开。启动您的服务器。



然后按Ctrl-a,然后按d。这将分离屏幕会话,使其在后台运行。



要[R]附加到它,请使用屏幕-r。



如果屏幕未安装,您无法安装,您还可以在后台启动应用程序,添加&按照你的想法,但你不应该关闭终端窗口;只需断开连接,使用bash命令退出或Ctrl-d。



屏幕的优点是您仍然可以从服务器读取输出,以防万一有错误或任何东西。



屏幕是一个非常强大的工具,还有更多的命令。您可以使用Ctrl-a添加新的虚拟窗口,然后添加c(用于创建);切换到带有Ctrl-a,然后是n(下一个)或p(上一个)的窗口,...



但是您需要安装才能使用它。因为你似乎有root权限,这不应该是一个问题。



编辑: tmux 是同一用例的另一个很好的解决方案。


I figured out how to run my Django application via sudo python /home/david/myproject/manage.py runserver 68.164.125.221:80. However, after I quit terminal, the server stops running.

I tried to run this process in the background, but the server just shuts down quickly after I execute sudo python /home/david/myproject/manage.py runserver 68.164.125.221:80 &.

How do I keep my Django application running even after I quit my ssh session in terminal?

PS - Sorry if this question strikes you as elementary. Such sillyness ensues when a front-end javascript programmer must turn into a server administrator in break-neck speed.

解决方案

Meet screen.

Connect through ssh, start screen. This open a virtual console emulator on top of the one provided by ssh. Start your server there.

Then press Ctrl-a, then d. This detach the screen session, keeping it running in the background.

To [R]e-attach to it, use screen -r.

If screen is not installed and you can't install it, you can also start an application in the background by adding a & to the command, as you tried. But you should not close the terminal window then ; just disconnect, with the bash command exit, or Ctrl-d.

The advantage of screen is that you can still read the output from the server, in case there is an error or anything.

Screen is a really powerful tool, with many more commands. You can add a new virtual window with Ctrl-a, then c (for Create) ; switch through windows with Ctrl-a, then n (next) or p (previous), ...

But you need it to be installed to use it. Since you seem to have root access, this shouldn't be a problem.

EDIT: tmux is another great solution for the same use-case.

这篇关于关闭我的ssh会话后,如何保持Django服务器的运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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