SaltyCrane Blog — Notes on JavaScript and web development

Notes on Python deployment using Fabric

I found out about Fabric via Armin Ronacher's article Deploying Python Web Applications. Fabric is a Capistrano inspired deployment tool for the Python community. It is very simple to use. There are 4 main commands: local is almost like os.system because it runs a command on the local machine, run and sudo run a command on a remote machine as either a normal user or as root, and put transfers a file to a remote machine.

Here is a sample setup which displays information about the Apache processes on my remote EC2 instance.

  • Install Easy Install
  • Install Fabric
    $ sudo easy_install Fabric
  • Create a file called located at ~/myproject
    def ec2():
        set(fab_hosts = [''],
            fab_user = 'sofeng',
            fab_password = 'mypassword',)
    def ps_apache():
        run("ps -e -O rss,pcpu | grep apache")
    Note: for security reasons, you can remove the password from the fabfile and Fabric will prompt for it interactively. Per the documentation, Fabric also supports key-based authentication.

  • Run it
    $ cd ~/myproject
    $ fab ec2 ps_apache
       Fabric v. 0.0.9, Copyright (C) 2008 Christian Vest Hansen.
       Fabric comes with ABSOLUTELY NO WARRANTY; for details type `fab warranty'.
       This is free software, and you are welcome to redistribute it
       under certain conditions; type `fab license' for details.
    Running ec2...
    Running ps_apache...
    Logging into the following hosts as sofeng:
    [] run: ps -e -O rss,pcpu | grep apache
    [] out:  2163  5504  0.0 S ?        00:00:00 /usr/sbin/apache2 -k start
    [] out:  2520 15812  0.0 S ?        00:00:00 /usr/sbin/apache2 -k start
    [] out:  2521  3664  0.0 S ?        00:00:00 /usr/sbin/apache2 -k start
    [] out:  2522  3664  0.0 S ?        00:00:00 /usr/sbin/apache2 -k start
    [] out:  2523  3664  0.0 S ?        00:00:00 /usr/sbin/apache2 -k start
    [] out:  2524  3664  0.0 S ?        00:00:00 /usr/sbin/apache2 -k start
    [] out:  2619  3664  0.0 S ?        00:00:00 /usr/sbin/apache2 -k start
    [] out:  2629  1204  0.0 R ?        00:00:00 /bin/bash -l -c ps -e -O rss,pcpu | grep apache


#1 Basil Shubin commented on :

Hmmm... Fabric.. curious.

Nice note ;-)