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

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Troy Hunt's Blog
P
Proofpoint News Feed
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
Cyberwarzone
Cyberwarzone
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
S
Securelist
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
T
Threatpost
H
Heimdal Security Blog
W
WeLiveSecurity
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
GRAHAM CLULEY
IT之家
IT之家
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
TaoSecurity Blog
TaoSecurity Blog
A
About on SuperTechFans
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
Google DeepMind News
Google DeepMind News
量子位
Stack Overflow Blog
Stack Overflow Blog
Know Your Adversary
Know Your Adversary
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
AI
AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
Vercel News
Vercel News
C
Cyber Attacks, Cyber Crime and Cyber Security
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
大猫的无限游戏
大猫的无限游戏
Forbes - Security
Forbes - Security

博客园 - lykyl的自留地

树莓派编译安装opencv3 (2019.1.6更新) centos6 安装EPEL "检索COM类工厂中 CLSID为 {00024500-0000-0000-C000-000000000046}的组件时失败,原因是出现以下错误: 80070005" 问题的解决 centos6.x 安装pylucene (20161027改) - lykyl的自留地 趣味python编程之经典俄罗斯方块 python编码规范 在CentOS 6.5上安装python2.7 "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法 利用SHELL脚本实现文件完整性检测程序(1.2版更新) 获取linux服务器基本信息脚本 DELPHI实现关闭指定进程,自身防杀 基于python编写的天气抓取程序 linux使用心得(持续更新) vim使用心得(持续更新) NFS服务基本配置及使用 利用shell脚本实现计划任务功能 V1.2 利用shell脚本实现计划任务功能 rsync简明手册 linux bash script简明手册(持续更新)
改进uwsgi启动脚本,使其支持多个独立配置文件
lykyl的自留地 · 2016-02-18 · via 博客园 - lykyl的自留地

最近在研究flask,在架设运行环境的时候犯了难。因为我想把每个独立的应用像NGINX处理多个网站那样,每个应用单独一个配置文件。而网上流传的uwsgi启动脚本都只支持单个配置文件。虽然有文章说可以把多个应用的配置写成命令集成到启动脚本里,但那样的话显然不够灵活。官方文档看了头实在是大,找来找去也没个头绪。于是决定自己把启动脚本改进一下。在原来脚本的基础上加入了配置文件遍历获取,再循环处理每个配置文件。改造难度不大效果却很好,完美实现我的需求。现将代码贴出来分享给有需要的人。当然如果您有更简便的方法能达到目的,还请劳烦告之一声。

特别声明:

1、 脚本只支持INI格式配置文件的加载,如需要加载其他格式配置文件请自行修改脚本中对应位置代码。

2、 PID文件名要求与配置文件名一致,扩展名为pid。如果不一样会导致进程不能正常关闭或重新加载。

3、 脚本命名为uwsgi_svr保存到/etc/init.d/目录下,记得配置执行权限。

#!/bin/bash
# chkconfig: 2345 55 25
# Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add uwsgi'

### BEGIN INIT INFO
# Provides:          uwsgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the uwsgi web server
# Description:       starts uwsgi using start-stop-daemon
### END INIT INFO

# Modify by lykyl
# Ver:1.1
# Description: script can loads multiple configs now.
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="uwsgi daemon"
NAME=uwsgi_srv
DAEMON=/usr/local/bin/uwsgi
CONFIGDIR=/etc/uwsgi/
PIDDIR=/var/run/
SCRIPTNAME=/etc/init.d/$NAME
FindCmd="/usr/bin/find"
declare -a iniList
declare -a SiteNameList

 
function Init() {
    iniList=`$FindCmd $CONFIGDIR -name '*.ini'`
    for i in ${iniList[@]}
    do
       SiteNameList=(${SiteNameList[@]} `basename $i|awk -F. '{print $1}'`)
    done
}

function Start() 
{
    local c=0
    for i in ${iniList[@]}
    do
      if $DAEMON $i; then
        echo "${SiteNameList[$c]} started"
      else
        echo "${SiteNameList[$c]} already running"
      fi
      let ++c
    done
}
 
function Stop() 
{
    local c=0
    for i in ${SiteNameList[@]}
    do
      if $DAEMON --stop ${PIDDIR}${i}.pid; then
        echo "${SiteNameList[$c]} stoped"
      else
        echo "${SiteNameList[$c]} not running"
      fi
      rm -f ${PIDDIR}${i}.pid
      let ++c
    done
}
 
function Reload() 
{
    local c=0
    for i in ${SiteNameList[@]}
    do
      if $DAEMON --reload ${PIDDIR}${i}.pid; then
        echo "${SiteNameList[$c]} reloaded"
      else
        echo "${SiteNameList[$c]} can't reload"
      fi
      let ++c
    done
}
 
function Status() 
{
    ps aux|grep $DAEMON
    echo
}

#main
set -e
[ -x "$DAEMON" ] || exit 0
Init
 
case "$1" in
 status)
    echo -en "Status $NAME: \n" 
   Status ;; start) echo -en "Starting $NAME: \n" Start ;; stop) echo -en "Stopping $NAME: \n" Stop ;; reload|graceful) echo -en "Reloading $NAME: \n" Reload ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2 exit 3 ;; esac exit 0