/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'.
1
byaiu 46 天前
猜测是 pythonpath 的问题
依赖是不是全局装的? 而且不是有 log 么,看看 log 就好了 |
![]() |
2
Vegetable 46 天前
一方面,你至少把你的 test.log 放出来,免得大家肉眼检查脑内运行帮你看问题。
另一方面,你这个需求其实很适合将服务放在 dcoker 里边自动启动,全是好处。 |
![]() |
3
lingeo 46 天前
1.直接 bash 运行 rc.local 脚本试一下有没有报错。
2.推荐你使用 supervisor 管理进程。 |
![]() |
4
Spute 46 天前
1 、切到项目目录,以前台模式直接执行/usr/bin/python3 /home/some/Qexo/manage.py runserver 0.0.0.0:8000 ,进行 debug
2 、建议使用 docker 部署这种 web 服务器 |
![]() |
5
dolphintwo 46 天前
写一个 django 的 service 再 enable 它
|
6
djasdjds 46 天前
人才
|
![]() |
7
hwhtj OP |
![]() |
9
hwhtj OP |
10
pililink 46 天前
推荐你使用 supervisor 管理进程
|
11
skyrim61 45 天前
使用 gunicorn 部署
|
![]() |
12
zcybupt2016 45 天前
建议打 docker + 1 ,省事得多
|
13
elboble 45 天前
supervisor +1 ,或者 unicron ,代拉服务。runserver 是调试用法
|