zoukankan      html  css  js  c++  java
  • gunicorn+flask+centos启动flask脚本

    #启动指定端口数量的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	(Detached)','')
        content=content.replace('	','')
        content=content.replace('
    ',',')
        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 $'
    '".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 $'
    '".format(screen_id))
    
    
    def kill_all_screen():
        screen_ls=get_screen_id_list()
        for item in screen_ls:
            os.system("sleep 1")
            os.system("screen -X -S {0} quit".format(item))
        os.system("sleep 1")
        os.system("screen -wipe")
        os.system("sleep 1")
        os.system("killall gunicorn")
    
    
    if __name__ == '__main__':
        kill_all_screen()
        create_screen()
        send_commands()
  • 相关阅读:
    解决Xcode升级7.0后,部分.a静态库在iOS9.0的模拟器上,link失败的问题
    2014年工作总结
    工作还是事业
    海豚社区阶段性开发总结
    Xcode开发和调试总结
    iOS证书深究
    何为分类,UIImageView举例
    UIWebView的探索
    SugarSync网盘之NSDateFormatter
    ASP.NET程序从IIS6移植到IIS7时出现500.22错误(转)
  • 原文地址:https://www.cnblogs.com/anbylau2130/p/13614690.html
Copyright © 2011-2022 走看看