#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : fabfile.py # @Author: becivells #@Contact : becivells@gmail.com # @Date : 2017/12/6 #@Software : PyCharm # @Desc : from fabric.api import settings from fabric.api import cd,run,env,put from install_config import * env.hosts = ['192.168.233.136'] env.user='root' env.password = 'password' def pip_mirror(): run(("mkdir -p ~/.pip/ ")) with cd('~/.pip/'): put(LOCAL_PIP_CONF_PATH,'~/.pip/') run('pip install -r %s' % (REMOTE_PIP_REQUIREMENT_PATH)) def supervisor_install(): run('yum install supervisor -y') run('mkdir -p /etc/supervisord.d/') put(LOCAL_SUPERVISORD_CONF_PATH,'/etc/') run('systemctl enable supervisord') run('systemctl start supervisord') def init(): run('yum update -y && yum install epel-release && yum update -y') run('yum install -y python-pip') run('yum install -y git') def create_user(): with settings(warn_only=True): run('useradd -s /usr/sbin/nologin -d {APP_USER_PATH} {APP_USER}'.format( APP_USER=APP_USER, APP_USER_PATH=APP_USER_PATH) ) def upload_web(): run('mkdir -p %s'%(APP_PATH)) with cd(APP_PATH): put('%s/*'%(LOCAL_BASE_DIR),APP_PATH,mode=777) run('chown {APP_USER}:{APP_USER} -R {APP_PATH}'.format( APP_PATH=APP_PATH, APP_USER=APP_USER) ) def web_install(): init() supervisor_install() create_user() upload_web() pip_mirror() # get_config() put(LOCAL_GUNICORN_CONF_PATH, '/etc/supervisord.d/') run('systemctl daemon-reload') run('systemctl restart supervisord') run('supervisorctl reload') run('supervisorctl status')