123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # @File : config.py
- # @Author: becivells
- #@Contact : becivells@gmail.com
- # @Date : 2017/12/7
- #@Software : PyCharm
- # @Desc :
- import os
- APP_NAME = 'webhooks'
- APP_INDEX = 'webhooks.py'
- APP_PATH_NAME = 'webhooks'
- APP_PORT = 21332
- APP_WORK = 1
- APP_USER = 'flask'
- RUN_USER = 'root'
- APP_USER_PATH = '/home/flask'
- #定义的flask app=FLAKSK()
- APP_DEFINE='app'
- APP_PATH = APP_USER_PATH + '/' + APP_PATH_NAME
- APP_LOG = APP_PATH + '/' +'log'
- #PROJECT DIR
- LOCAL_BASE_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
- #CONF PATH
- LOCAL_CONF_PATH = LOCAL_BASE_DIR + os.sep + 'install' + os.sep + 'config'
- LOCAL_SUPERVISORD_CONF_PATH = LOCAL_CONF_PATH + os.sep + 'supervisord.conf'
- LOCAL_GUNICORN_CONF_PATH = LOCAL_CONF_PATH + os.sep + 'supervisor_%s.conf'%(APP_NAME)
- LOCAL_PIP_CONF_PATH = LOCAL_CONF_PATH + os.sep + 'pip.conf'
- REMOTE_PIP_REQUIREMENT_PATH = APP_USER_PATH + '/' + APP_PATH_NAME + '/' + 'requirements.txt'
- gunicorn_conf = '''[program:{APP_NAME}]
- command=gunicorn -w{APP_WORK} -b0.0.0.0:{APP_PORT} --error-logfile {APP_LOG}/error.log --access-logfile {APP_LOG}/access.log {APP_INDEX}:{APP_DEFINE} ;应用入口
- user={RUN_USER}
- directory={APP_PATH} ;web目录
- startsecs=5 ;启动时间
- stopwaitsecs=0 ;终止等待时间
- startretries = 3
- autostart=true ;是否自动启动
- autorestart=true ;是否自动重启
- redirect_stderr=true ;错误日志输出到标准日志
- stdout_logfile=/dev/null ;标准日志不输出
- stdout_logfile_maxbytes=10MB ;标准日志大小
- environment=PYTHONPATH=$PYTHONPATH:{APP_PATH}
- '''
- def check():
- flask_index_name = '.'.join(APP_INDEX.split('.')[:-1])
- with open(LOCAL_GUNICORN_CONF_PATH,'w') as f:
- f.write(gunicorn_conf.format(
- APP_PATH = APP_PATH,
- APP_PORT = APP_PORT,
- APP_NAME = APP_NAME,
- APP_USER = APP_USER,
- APP_WORK = APP_WORK,
- APP_LOG = APP_LOG,
- RUN_USER = RUN_USER,
- APP_DEFINE = APP_DEFINE,
- APP_INDEX = flask_index_name))
- if not os.path.exists(REMOTE_PIP_REQUIREMENT_PATH):
- print(u'please create file requirements.txt in %s dir '%(LOCAL_BASE_DIR))
- if not os.path.exists(LOCAL_CONF_PATH):
- print('please install dir error ')
- if not os.path.exists(LOCAL_PIP_CONF_PATH):
- print ('pip.conf file not find')
- check()
|