惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
T
Tailwind CSS Blog
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
博客园 - 叶小钗
N
Netflix TechBlog - Medium
罗磊的独立博客
量子位
MyScale Blog
MyScale Blog
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
B
Blog
腾讯CDC
爱范儿
爱范儿
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
雷峰网
雷峰网
G
Google Developers Blog
Google DeepMind News
Google DeepMind News

博客园 - 吾非无心

MSB4019 找不到导入的项目“C:\Users\...\AppData\Local\QtMsBuild\vs-debugtools\qt_import.props” - 吾非无心 - 博客园 类/结构最后一个成员为类(string)时可能会出现“堆损坏”(HEAP CORRUPTION DETECTED)错误 GCC在C语言中内嵌汇编 asm __volatile__ QT删除python中的单行注释 double转int QJson 存储(u)longlong有问题 QT QPixmap QImage内存泄漏 QMetaObject::connectSlotsByName: No matching signal for QT数据库连接管理类 QT多重继承带来的问题及解决办法,记录备查 QT6 源码编译Win32 x86 vc++高精度计时sleep stack smashing detected 莫名其妙的错误 strdump的问题 再加一个realloc的问题 linux下简单封装读写锁 codeblocks下libacl配置 centos8 安装、配置redis6 pyftpdlib中文乱码的解决之道 libevent学习一
CentOS8让uwsgi开机自动启动django(无需登录,无需手动)
吾非无心 · 2020-09-11 · via 博客园 - 吾非无心

baidu了好几天,折腾了好几天,终于让uwsgi能在CentOS8下开机自动启动Django网站了

网上说的:

/etc/init.d/???.sh

chkconfig --add ???.sh

这种↑方法,不行!!

没研究,不知道是不是CentOS8版本原因

今天看了下Systemd的介绍,终于以.service的方式搞定。

解决方案分两步:

  1、新建自己的 xxx.service(位置:/etc/systemd/system)

[Unit]
Description=uwsgi-xxx-support
After=network.target
Before=nginx.service

[Service]
ExecStart=/usr/sbin/xxx.sh
ExecReload=/bin/kill -HUP ( ps -ep | grep uwsgi)
Type=forking


[Install]
WantedBy=multi-user.target
~                              

注意:: Type 要设置为forking,因为xxx.sh执行完之后是要退出的,继续运行的是uwsgi进程,默认的simple是启动不了的,状态会一直是inactive(dead)

建 好 之 后:$  systemctl enable xxx.service

  2、建自己的xxx.sh脚本(我放在/usr/sbin)

#!/bin/sh 
  
venvwrap="virtualenvwrapper.sh"



python38=`/usr/bin/which python3.8`
VIRTUALENVWRAPPER_PYTHON=${python38}

export WORKON_HOME=/root/.virtualenvs

if [ $? -eq 0 ]; then
        venvwrap=`/usr/bin/which $venvwrap`
        source $venvwrap
fi

workon .xxx
source activate
uwsgi --ini /webroot/xxx/uwsgi.ini &
~                                                                                                                                             
~                                                                                                                                             
~                                                                                                                                             
~          

     要设置 VIRTUALENVWRAPPER_PYTHON          ,否则source ...../virtualenvwrapper.sh会报错,报找不到python

     要export WORKON_HOME    ,否则workon找不到虚拟环境

     activate要以source 参数的形式运行,否则报无权限

      uwsgi  最后添&,表示后台执行

 reboot

不登录,不执行任何指令

打开浏览器,浏览网站

SUCCESS!