From 64b15c59bec363793530d40b382e7f03dcca4720 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Fri, 30 Dec 2011 16:39:10 -0500 Subject: [PATCH 1/5] Add additional task to Fabric example --- docs/scenarios/admin.rst | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index 84a9189..803db75 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -14,9 +14,11 @@ Install Fabric: pip install fabric -The following code will ssh into both of our servers, cd to our project -directory, activate the virtual environment, pull the newest codebase, -and restart the application server. +The following code will create two tasks that we can use: ``memory_usage`` and +``deploy``. The former will output the memory usage on each machine. The +latter will ssh into each server, cd to our project directory, activate the +virtual environment, pull the newest codebase, and restart the application +server. :: @@ -24,6 +26,10 @@ and restart the application server. env.hosts = ['my_server1', 'my_server2'] + @task + def memory_usage(): + run('free -m') + @task def deploy(): with cd('/var/www/project-env/project'): @@ -31,8 +37,27 @@ and restart the application server. run('git pull') run('touch app.wsgi') -With the previous code saved in a file named fabfile.py, we merely need to run -the following command to deploy our application to both of our servers. +With the previous code saved in a file named fabfile.py, we can check memory +usage with: + +:: + + $ fab memory_usage + [my_server1] Executing task 'memory' + [my_server1] run: free -m + [my_server1] out: total used free shared buffers cached + [my_server1] out: Mem: 6964 1897 5067 0 166 222 + [my_server1] out: -/+ buffers/cache: 1509 5455 + [my_server1] out: Swap: 0 0 0 + + [my_server2] Executing task 'memory' + [my_server2] run: free -m + [my_server2] out: total used free shared buffers cached + [my_server2] out: Mem: 1666 902 764 0 180 572 + [my_server2] out: -/+ buffers/cache: 148 1517 + [my_server2] out: Swap: 895 1 894 + +and we can deploy with: :: From d9439d5a9282003e546223370f69144448f56528 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Fri, 30 Dec 2011 18:05:43 -0500 Subject: [PATCH 2/5] Clean up Fabric example to not have horizontal scroll --- docs/scenarios/admin.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index 803db75..512223e 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -45,17 +45,17 @@ usage with: $ fab memory_usage [my_server1] Executing task 'memory' [my_server1] run: free -m - [my_server1] out: total used free shared buffers cached - [my_server1] out: Mem: 6964 1897 5067 0 166 222 - [my_server1] out: -/+ buffers/cache: 1509 5455 - [my_server1] out: Swap: 0 0 0 + [my_server1] out: total used free shared buffers cached + [my_server1] out: Mem: 6964 1897 5067 0 166 222 + [my_server1] out: -/+ buffers/cache: 1509 5455 + [my_server1] out: Swap: 0 0 0 [my_server2] Executing task 'memory' [my_server2] run: free -m - [my_server2] out: total used free shared buffers cached - [my_server2] out: Mem: 1666 902 764 0 180 572 - [my_server2] out: -/+ buffers/cache: 148 1517 - [my_server2] out: Swap: 895 1 894 + [my_server2] out: total used free shared buffers cached + [my_server2] out: Mem: 1666 902 764 0 180 572 + [my_server2] out: -/+ buffers/cache: 148 1517 + [my_server2] out: Swap: 895 1 894 and we can deploy with: From 73432c73681dc663946db0b3776c55ebe8656aee Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Fri, 30 Dec 2011 19:18:58 -0500 Subject: [PATCH 3/5] Fix missing dollar sign in fabric install --- docs/scenarios/admin.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index 512223e..b570d2b 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -12,7 +12,7 @@ Install Fabric: :: - pip install fabric + $ pip install fabric The following code will create two tasks that we can use: ``memory_usage`` and ``deploy``. The former will output the memory usage on each machine. The From 0b5a0efd92211ef29a189c489fe2c6d85931f132 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Fri, 30 Dec 2011 19:24:28 -0500 Subject: [PATCH 4/5] Switch examples to code-block style --- docs/scenarios/admin.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index b570d2b..6271511 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -10,7 +10,7 @@ fabric is more focused on application level tasks such as deployment. Install Fabric: -:: +.. code-block:: bash $ pip install fabric @@ -20,7 +20,7 @@ latter will ssh into each server, cd to our project directory, activate the virtual environment, pull the newest codebase, and restart the application server. -:: +.. code-block:: python from fabric.api import cd, env, prefix, run, task @@ -40,7 +40,7 @@ server. With the previous code saved in a file named fabfile.py, we can check memory usage with: -:: +.. code-block:: bash $ fab memory_usage [my_server1] Executing task 'memory' @@ -59,7 +59,7 @@ usage with: and we can deploy with: -:: +.. code-block:: bash $ fab deploy From da8e3e89e2871ac8146f91e493890b56d9c0938c Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Fri, 30 Dec 2011 19:42:55 -0500 Subject: [PATCH 5/5] Remove unnecessary python code-block --- docs/scenarios/admin.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index 6271511..991cab2 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -20,7 +20,7 @@ latter will ssh into each server, cd to our project directory, activate the virtual environment, pull the newest codebase, and restart the application server. -.. code-block:: python +:: from fabric.api import cd, env, prefix, run, task