扁平化企业网源码win8风格精简化源码asp带后台企业网站,网站页面热度,那些网站是php开发的,免费编程软件哪个好用上次学到了在云服务器下如何部署Django项目#xff0c;用到了nginx服务和uwsgi服务#xff0c;需要手工启动这2个服务的命令。
现在考虑如何设置开机自启动#xff0c;为什么要这样考虑#xff1f;因为服务器万一出问题#xff0c;意外重启了#xff0c;那我们部署的Dja…上次学到了在云服务器下如何部署Django项目用到了nginx服务和uwsgi服务需要手工启动这2个服务的命令。
现在考虑如何设置开机自启动为什么要这样考虑因为服务器万一出问题意外重启了那我们部署的Django项目不就挂了吗到时候还是要人工去启动吗
所以最好还是配置开机自启动以防万一。
网上查了很多开机自启动配置最后选择修改系统文件 /etc/rc.d/rc.local ,添加启动命令脚本。
测试过程中发现nginx服务自启动比较容易直接添加就行。但是发现 uwsgi 服务,配置该服务开机自启几种方式reboot后导致云服务器挂掉无法再登录只能通过云服务官网重启才能进入所以谨慎操作
经过多次测试和网上经验总结确定了一个可行方案
1. 在 /etc/init.d/ 路径下面建立 uwsgi.sh 启动命令脚本注意“一定要放到 /etc/init.d/ 路径下面”其他路径容易导致云服务器挂掉我试过多次了。 2. vim /etc/init.d/uwsgi.sh
添加如下内容注意“执行命令的文件一定要用绝对路径”
#!/bin/bash
/usr/python3/bin/uwsgi --ini /home/django_pro/mysite/uwsgi.ini;
esc 退出编辑:wq 保存修改
将 /etc/init.d/uwsgi.sh修改为可执行
chmod 777 /etc/init.d/uwsgi.sh 3. 添加开机自启动脚本 到 /etc/rc.d/rc.local 上。
vim /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run chmod x /etc/rc.d/rc.local to ensure
# that this script will be executed during boot.#开机自启动 nginx 服务
/usr/sbin/nginx
#开机自启动 uwsgi 服务一定要用绝对路径执行该sh
/etc/init.d/uwsgi.sh
esc 退出编辑:wq 保存修改
将rc.local修改为可执行
chmod 777 /etc/rc.d/rc.local 4. reboot 重启检验结果
[root~]# ps -ef|grep uwsgi
root 1056 1 0 16:23 ? 00:00:00 /usr/python3/bin/uwsgi --ini /home/django_pro/mysite/uwsgi.ini
root 1408 1056 0 16:23 ? 00:00:00 /usr/python3/bin/uwsgi --ini /home/django_pro/mysite/uwsgi.ini
root 1572 1473 0 16:48 pts/0 00:00:00 grep --colorauto uwsgi
[root~]# ps -ef|grep nginx
root 1017 1 0 16:23 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 1023 1017 0 16:23 ? 00:00:00 nginx: worker process
root 1574 1473 0 16:49 pts/0 00:00:00 grep --colorauto nginx