Skip to content

Commit 64b15c5

Browse files
author
Steve Pulec
committed
Add additional task to Fabric example
1 parent 3dbd567 commit 64b15c5

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

docs/scenarios/admin.rst

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,50 @@ Install Fabric:
1414

1515
pip install fabric
1616

17-
The following code will ssh into both of our servers, cd to our project
18-
directory, activate the virtual environment, pull the newest codebase,
19-
and restart the application server.
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.
2022

2123
::
2224

2325
from fabric.api import cd, env, prefix, run, task
2426

2527
env.hosts = ['my_server1', 'my_server2']
2628

29+
@task
30+
def memory_usage():
31+
run('free -m')
32+
2733
@task
2834
def deploy():
2935
with cd('/var/www/project-env/project'):
3036
with prefix('. ../bin/activate'):
3137
run('git pull')
3238
run('touch app.wsgi')
3339

34-
With the previous code saved in a file named fabfile.py, we merely need to run
35-
the following command to deploy our application to both of our servers.
40+
With the previous code saved in a file named fabfile.py, we can check memory
41+
usage with:
42+
43+
::
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:
3661

3762
::
3863

0 commit comments

Comments
 (0)