源码:
http://docs.fabfile.org 打开是最新版本
博客:
安装
自动化远程部署工具fabric测试案例
#程序名: test_fabric.py
from fabric.api import *
from fabric.api import run
env.host_string = '192.168.01.100'
#env.password = ''
#if set, it will continue to run when err
env.warn_only=True
def main():
sudo('crontab -l; echo "ok" ', 'jakisou')
if __name__ == '__main__':
main()
pass
#本地执行命令:python test_fabric.py
Fabric试用
2010-01-05 09:52:57
Fabric是一种使用SSH自动化应用部署和系统管理任务的Python库和命令行工具,使用起来非常方便,可以:
- 在远程或本地执行命令,并捕获(或不捕获)输出
- 通过SFTP上传或下传文件,并进行常见的文件操作
从而使远程部署和管理系统成为高度可重复的工作。
比如要在远程的一台Linux系统上创建一个Pylons实例,
可以将如下代码存入本地文件fabfile.py,在本地运行fab deploy即可。
from fabric.api import *
from fabric.contrib import files
env.user = 'zengjie'
env.hosts = ['linuxbox']
def deploy():
sudo('apt-get install python')
sudo('easy_install virtualenv')
if not files.exists('~/hello'):
with cd('~'):
run('virtualenv hello')
with cd('~/hello'):
run('bin/easy_install PasteDeploy')
run('bin/easy_install Pylons')
if not files.exists('HelloWorld'):
run('bin/paster create --template=pylons --no-interactive HelloWorld')
with cd('HelloWorld'):
run('../bin/python setup.py develop')
def start():
run('start-stop-daemon --start -m -b --pidfile ~/hello/test.pid '
'--startas ~/hello/bin/paster serve ~/hello/HelloWorld/test.ini')
def stop():
run('start-stop-daemon --stop --pidfile ~/hello/test.pid')
启停Pylons,在本地分别运行fab start和fab stop即可。
- 在远程或本地执行命令,并捕获(或不捕获)输出
- 通过SFTP上传或下传文件,并进行常见的文件操作
从而使远程部署和管理系统成为高度可重复的工作。
比如要在远程的一台Linux系统上创建一个Pylons实例,
可以将如下代码存入本地文件fabfile.py,在本地运行fab deploy即可。
from fabric.api import *
from fabric.contrib import files
env.user = 'zengjie'
env.hosts = ['linuxbox']
def deploy():
sudo('apt-get install python')
sudo('easy_install virtualenv')
if not files.exists('~/hello'):
with cd('~'):
run('virtualenv hello')
with cd('~/hello'):
run('bin/easy_install PasteDeploy')
run('bin/easy_install Pylons')
if not files.exists('HelloWorld'):
run('bin/paster create --template=pylons --no-interactive HelloWorld')
with cd('HelloWorld'):
run('../bin/python setup.py develop')
def start():
run('start-stop-daemon --start -m -b --pidfile ~/hello/test.pid '
'--startas ~/hello/bin/paster serve ~/hello/HelloWorld/test.ini')
def stop():
run('start-stop-daemon --stop --pidfile ~/hello/test.pid')
启停Pylons,在本地分别运行fab start和fab stop即可。