码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS8让uwsgi开机自动启动django(无需登录,无需手动)

时间:2020-09-17 22:11:25      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:环境   color   打开   自动   开机   baidu   conf   inactive   不执行   

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!

 

CentOS8让uwsgi开机自动启动django(无需登录,无需手动)

标签:环境   color   打开   自动   开机   baidu   conf   inactive   不执行   

原文地址:https://www.cnblogs.com/xhzxlqt/p/13652829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!