
只有一个需求,在 ubuntu23 开机后自动运行以下脚本
/usr/bin/python3 /home/some/Qexo/manage.py runserver 0.0.0.0:8000 --noreload 以上脚本,直接在终端是可以运行的,服务也起来了。 但要开机运行,试过了以下三种方法,都不行 1 、https://blog.csdn.net/yuezhilangniao/article/details/113772277 2 、https://www.cnblogs.com/jingzaixin/p/15920472.html 出现的错误是
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'. 3 、使用 supervisor,出现的错误是:
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment? ...... 求助,请教,在 ubuntu23 中如何开机时自动运行上面提到的脚本
1 sky92682 2024 年 7 月 23 日 via iPhone Ubuntu 下用 systemd 做开机自启吧 |
2 Hopetree 2024 年 7 月 23 日 不对啊,哪有直接使用 Python 跑 Django 的,不是要用类似 gunicorn 这种去启动运行吗,比如 supervisor 启动配置 ``` [program:gunicorn-django] command=gunicorn izone.wsgi -b 0.0.0.0:8000 directory=/opt/cloud/izone stdout_logfile=/var/log/supervisor/gunicorn.django.log stderr_logfile=/var/log/supervisor/gunicorn.django.log autostart=true autorestart=true startsecs=2 stopwaitsecs=2 priority=100 ``` |
3 sky92682 2024 年 7 月 23 日 via iPhone journelctl -u rc.local -f 看一下服务的详细日志 |
4 Debin006 2024 年 7 月 23 日 一般是不会直接这样跑的呀,这样跑即不好管理,不都是起一个 docker 容器的吗? `docker pull django` |
5 sagaxu 2024 年 7 月 23 日 多半是环境变量的问题 |
7 lingeo 2024 年 7 月 23 日 你用了虚拟环境? |
8 HashV2 2024 年 7 月 23 日 /you_venv_path/bin/python /home/some/Qexo/manage.py runserver 0.0.0.0:8000 --noreload 、 |
9 simple2025 2024 年 7 月 23 日 你 supervisor 配置怎么写的? |
10 lingeo 2024 年 7 月 23 日 |
11 julyclyde 2024 年 7 月 23 日 |
12 maocat 2024 年 7 月 23 日 via iPhone 楼上这么多人都不提一下 uwsgi 吗 |
13 BeUself 2024 年 7 月 23 日 写个 service 注册一下。不仅能自启动 还能帮你自动重启。不香吗? |
14 awanabe 2024 年 7 月 23 日 你的 python 环境里面没有装依赖库 你是在非 root 里面的 python 装了 django 切换到了 root 就没有了 所以启动的时候找不到 django |
15 mirrornighth 2024 年 7 月 23 日 用 systemd 做开机自启 |
16 vivisidea 2024 年 7 月 23 日 docker |
17 hwhtj OP @lingeo 谢谢你的提醒,确实如你说说,我的 python3.11 装在了~/.local/lib/python311 ,所以才这样。十分感谢 |
18 ytmsdy 2024 年 7 月 23 日 跑个 docker 吧,然后设置成自启动。 |
19 chempotato 2024 年 7 月 23 日 via Android nginx+uwsgi+django |
20 deplives 2024 年 8 月 1 日 好家伙,直接用 runserver 跑 |