How do I keep my Django server running even after I close my ssh session?

后端 未结 3 1768
遥遥无期
遥遥无期 2021-01-30 18:02

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 serv

3条回答
  •  礼貌的吻别
    2021-01-30 18:30

    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.

提交回复
热议问题