Skip to content

Commit 4f7d551

Browse files
author
Kenneth Reitz
committed
Merge pull request realpython#62 from spulec/master
Add Additional Fabric Example
2 parents 2df650c + da8e3e8 commit 4f7d551

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

docs/scenarios/admin.rst

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,56 @@ fabric is more focused on application level tasks such as deployment.
1010

1111
Install Fabric:
1212

13-
::
13+
.. code-block:: bash
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:
3642

37-
::
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
3863
3964
$ fab deploy
4065

0 commit comments

Comments
 (0)