【问题标题】:Shell script to restart django runserver inside the screen用于在屏幕内重新启动 django runserver 的 Shell 脚本
【发布时间】:2017-07-08 10:06:43
【问题描述】:

如何使用 shell 脚本重新启动 django runserver?我在屏幕内运行 django 服务器。

这是我的 shell 脚本 restartpython.sh:

killall -9 python
screen -r
sleep 5
exec python manage.py runserver 0.0.0.0:8000
ctrl+a d          # how to make this into shell script??

当我执行这个脚本时,我进入屏幕并且 python 服务器被杀死。但脚本没有运行这一行:

exec python manage.py runserver 0.0.0.0:8000

它显示了这个错误:

python: can't open file 'manage.py': [Errno 2] No such file or directory

另外,如何在 shell 脚本中运行 ctrl+a d (退出屏幕)?谢谢。

【问题讨论】:

  • 这听起来像是一个被破解的伪生产配置。 runserver isn't meant to be used in production。你想做什么?
  • @Chris 我正在尝试制作一个脚本来重新启动 django 运行服务器。因为,django runserver 有时会卡住。我现在仍处于开发阶段。我将在生产中使用其他方法。
  • 通常我只运行python manage.py 并让它在打开的终端窗口中运行。通过将screen 和自定义shell 脚本添加到组合中,您是否有任何特殊原因使事情复杂化? (请注意,killall -9 python 几乎肯定不应该在其中。而且您可能也不需要exec……)
  • @Chris 我使用屏幕,因为我想在后台运行 django,我可以退出 ssh 并让它继续运行。
  • 您正在使用远程服务器进行开发?在那种情况下,我会考虑为服务器上的任何操作系统编写一个初始化脚本。不过,在本地开发盒上运行开发服务器可能更容易。

标签: django bash shell gnu-screen


【解决方案1】:

使用gunicornkill -HUP 代替runserver 来重新加载您的服务器。

【讨论】:

猜你喜欢
  • 2019-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-14
  • 2018-11-03
  • 1970-01-01
相关资源
最近更新 更多