跳转到内容
彼岸论坛
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Django] 请教 Django runserver 开机自启动的问题


小天管理

已推荐帖子

/etc/systemd/system/rc-local.service 文件内容:

 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
 WantedBy=multi-user.target

/etc/rc.local 文件内容

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo "看到这行字,说明添加自启动脚本成功。" > /home/some/Qexo/test.log
a=`lsof -i:8000 | wc -l`
if [ "$a" -eq "0" ];then
       echo "start nohup django:8000" >> /home/some/Qexo/test.log
             nohup  /usr/bin/python3 /home/some/Qexo/manage.py runserver 0.0.0.0:8000 > cmdb.log 2>&1 &
       else
       echo "8000 端口被占用" >> /home/some/Qexo/test.log
fi
#source/home/some/Qexo/
#nohup /usr/bin/python3 /home/some/Qexo/manage.py runserver 0.0.0.0:8000 > cmdb.log 2>&1 &
echo "看到这行字,说明 django.sh 执行过。" >> /home/some/Qexo/test.log
exit 0

重启后,sudo systemctl status rc-local,报如下错误

 rc-local.service - /etc/rc.local Compatibility
    Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; preset: enabled)
   Drop-In: /usr/lib/systemd/system/rc-local.service.d
            └─debian.conf
    Active: failed (Result: exit-code) since Tue 2024-07-23 09:22:23 CST; 15min ago
  Duration: 236ms
   Process: 3617 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
  Main PID: 3621 (code=exited, status=1/FAILURE)
       CPU: 344ms

7 月 23 09:22:23 some-Ubuntu23 systemd[1]: Starting rc-local.service - /etc/rc.local Compatibility...
7 月 23 09:22:23 some-Ubuntu23 systemd[1]: Started rc-local.service - /etc/rc.local Compatibility.
7 月 23 09:22:23 some-Ubuntu23 systemd[1]: rc-local.service: Main process exited, code=exited, status=1/FAILURE
7 月 23 09:22:23 some-Ubuntu23 systemd[1]: rc-local.service: Failed with result 'exit-code'.
意见的链接
分享到其他网站

加入讨论

您现在可以发表并稍后注册. 如果您是会员,请现在登录来参与讨论.

游客
回复主题...

×   粘贴为富文本.   粘贴为纯文本来代替

  只允许使用75个表情符号.

×   您的链接已自动嵌入.   显示为链接来代替

×   您之前的内容已恢复.   清除编辑器

×   您无法直接粘贴图片.要从网址上传或插入图片.

  • 游客注册

    游客注册

  • 会员

    没有会员可显示

  • 最新的状态更新

    没有最新的状态更新
  • 最近查看

    • 没有会员查看此页面.
×
×
  • 创建新的...