991cab265a160829e65dee2b7c2197ad0edf47b9
[python-guide.git] / docs / scenarios / admin.rst
1 Systems Administration
2 ======================
3
4 Fabric
5 ------
6
7 Fabric is a library for simplifying system administration tasks. While Chef
8 and Puppet tend to focus on managing servers and system libraries,
9 fabric is more focused on application level tasks such as deployment.
10
11 Install Fabric:
12
13 .. code-block:: bash
14
15     $ pip install fabric
16
17 The following code will create two tasks that we can use: ``memory_usage`` and
18 ``deploy``. The former will output the memory usage on each machine. The
19 latter will ssh into each server, cd to our project directory, activate the
20 virtual environment, pull the newest codebase, and restart the application
21 server.
22
23 ::
24
25     from fabric.api import cd, env, prefix, run, task
26
27     env.hosts = ['my_server1', 'my_server2']
28
29     @task
30     def memory_usage():
31         run('free -m')
32
33     @task
34     def deploy():
35         with cd('/var/www/project-env/project'):
36             with prefix('. ../bin/activate'):
37                 run('git pull')
38                 run('touch app.wsgi')
39
40 With the previous code saved in a file named fabfile.py, we can check memory
41 usage with:
42
43 .. code-block:: bash
44
45     $ fab memory_usage
46     [my_server1] Executing task 'memory'
47     [my_server1] run: free -m
48     [my_server1] out:              total     used     free   shared  buffers   cached
49     [my_server1] out: Mem:          6964     1897     5067        0      166      222
50     [my_server1] out: -/+ buffers/cache:     1509     5455
51     [my_server1] out: Swap:            0        0        0
52
53     [my_server2] Executing task 'memory'
54     [my_server2] run: free -m
55     [my_server2] out:              total     used     free   shared  buffers   cached
56     [my_server2] out: Mem:          1666      902      764        0      180      572
57     [my_server2] out: -/+ buffers/cache:      148     1517
58     [my_server2] out: Swap:          895        1      894
59
60 and we can deploy with:
61
62 .. code-block:: bash
63
64     $ fab deploy
65
66 Additional features include parallel execution, interaction with remote
67 programs, and host grouping.
68
69 Chef
70 ----
71
72 .. todo:: Write about Chef
73
74 Puppet
75 ------
76
77 .. todo:: Write about Puppet
78
79 Blueprint
80 ---------
81
82 .. todo:: Write about Blueprint
83
84 Buildout
85 --------
86
87 .. todo:: Write about Buildout