Example #1
0
def django_deploy():
    for host in host_config.webserver:
        p = Paramiko()
        key = paramiko.RSAKey.from_private_key_file(
            os.path.join(config.base.Base_dir, 'config', 'id_rsa'))
        p.connect(host=host[0], port=host[1], user=host[2], pwd=host[3])

        #创建虚拟环境
        p.cmd('virtualenv /root/Desktop/python-envl/django1.8')

        #上传项目
        p.upload(
            os.path.join(config.base.Base_dir, 'django_deploy', 'polls.zip'),
            '/project/polls.zip')
        p.cmd('unzip -d  /project -o /project/polls.zip')

        #安装mysql-python依赖包
        p.cmd('yum -y install mysql-devel')

        #安装项目依赖
        p.cmd(
            '/root/Desktop/python-envl/django1.8/bin/pip install -r /project/polls/requirements'
        )

        #supervisor安装启动
        supervisor_install(p)

        nginx_server(p)
Example #2
0
def get_ssh_client(hosts):
    key = paramiko.RSAKey.from_private_key_file(
        os.path.join(config.base.Base_dir, 'config', 'id_rsa'))
    clients = []
    for host in hosts:
        client = Paramiko()
        client.connect(host=host[0], user=host[1], key=key)  #建立连接
        clients.append(client)
    return clients
Example #3
0
def nginx_deploy(hosts):
    for host in hosts:
        p = Paramiko()
        key = paramiko.RSAKey.from_private_key_file(
            os.path.join(config.base.Base_dir, 'config', 'id_rsa'))
        p.connect(host=host[0], port=host[1], user=host[2], pwd=host[3])  #建立连接
        p.upload(
            os.path.join(config.base.Base_dir, 'paramilko_deploy',
                         'Desktop.zip'), '/opt/nginx.zip')
        p.cmd('unzip -o -d /opt/ /opt/nginx.zip  ')
        p.cmd('python /opt/nginx.py')
Example #4
0
def del_all(hosts):
    for host in hosts:
        p = Paramiko()
        key = paramiko.RSAKey.from_private_key_file(
            os.path.join(config.base.Base_dir, 'config', 'id_rsa'))
        p.connect(host=host[0], port=host[1], user=host[2], pwd=host[3])

        p.cmd('pkill nginx')
        p.cmd('supervisorctl stop polls')
        p.cmd('rm -rf /etc/supervisord.d/polls.ini')
        p.cmd('rm -rf /usr/local/nginx1.10.2')
        p.cmd('rm -rf /usr/local/sbin/nginx')
        p.cmd('rm -rf /project/baidu*')
        p.cmd('rm -rf /root/Desktop/python-envl/django1.8')
        p.cmd('yum -y remove supervisor')