首页 > 其他 > 详细

gunicorn+flask+centos启动flask脚本

时间:2020-09-04 17:00:56      阅读:100      评论:0      收藏:0      [点我收藏+]
#启动指定端口数量的screen,并运行flask程序
import commands
import os


ip="10.1.1.96"
gunicorn_port_list=[5000,5001,5002]


def get_screen_id_list():
    result,content=commands.getstatusoutput(‘screen -ls|grep gunicorn‘)
    content=content.replace(‘.gunicorn\t(Detached)‘,‘‘)
    content=content.replace(‘\t‘,‘‘)
    content=content.replace(‘\n‘,‘,‘)
    ls=content.split(‘,‘)
    return ls


def create_screen():
    for i in range(len(gunicorn_port_list)):
        #创建n个screen程序
        os.system("screen -dmS gunicorn")

def send_commands():
    current_screen_list=get_screen_id_list()
    for port,screen_id in zip(gunicorn_port_list,current_screen_list):
        os.system("screen -x -S {0} -p 0 -X stuff $‘cd /var/wsdd‘".format(screen_id))
        os.system("sleep 1")
        os.system("screen -x -S {0} -p 0 -X stuff $‘\n‘".format(screen_id))
        os.system("sleep 1")
        os.system("screen -x -S {0} -p 0 -X stuff $‘gunicorn -w 4 -b {1}:{2} manage:app –preload‘".format(screen_id,ip,port))
        os.system("sleep 1")
        os.system("screen -x -S {0} -p 0 -X stuff $‘\n‘".format(screen_id))


def kill_all_screen():
    screen_ls=get_screen_id_list()
    for item in screen_ls:
        os.system("kill {0}".format(item))


if __name__ == ‘__main__‘:
    kill_all_screen()
    create_screen()
    send_commands()

  

gunicorn+flask+centos启动flask脚本

原文:https://www.cnblogs.com/anbylau2130/p/13614690.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!