Browse files

Adding task to push code to server

  • Loading branch information...
1 parent f0ec313 commit b7f08699150e0c45e5fa3b20328bdae20d91e999 @swaroopch committed Jul 31, 2011
Showing with 46 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +39 −0 fabfile.py
  3. +6 −0 lib/tasks/cache.rake
View
1 .gitignore
@@ -6,3 +6,4 @@ tmp/**/*
Gemfile.lock
.*.swp
public/*.html
+*.pyc
View
39 fabfile.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+'''\
+Run 'fab --list' to see what commands you can run.
+
+Requires Fabric from www.fabfile.org
+'''
+
+import os
+from getpass import getuser
+
+from fabric.api import env, hosts, local, run, sudo
+from fabric.context_managers import cd
+from fabric.utils import puts
+from fabric.colors import magenta
+
+def _transfer_files(src, dst, port=22):
+ '''Sync from local directory to remote directory'''
+ assert os.getenv('SSH_AUTH_SOCK') is not None # Ensure ssh-agent is running
+ if not src.endswith('/'):
+ src = src + '/'
+ if dst.endswith('/'):
+ dst = dst[:-1]
+ local('rsync -avh --delete-before --copy-unsafe-links --exclude "log/*" -e "ssh -p {0}" {1} {2}'.format(port, src, dst), capture=False)
+
+@hosts('isbn.net.in:30247')
+def push():
+ local_dir = os.getcwd()
+ remote_dir = '/home/' + getuser() + '/web/isbn.net.in/private/isbn.net.in'
+
+ _transfer_files(local_dir, env.host + ':' + remote_dir, env.port) # transfer the code
+
+ with cd(remote_dir):
+ run("rm -vf public/index.html public/about.html") # remove page caches on disk
+ #run("env RAILS_ENV=production rake cache:clear") # clear memcache
+ run("touch tmp/restart.txt") # restart passenger
+ sudo("restart isbn.net.in") # delayed_job worker
+
+ puts(magenta('Success! The {0} server has been updated.'.format(env.host_string)))
View
6 lib/tasks/cache.rake
@@ -0,0 +1,6 @@
+desc "Clear cache"
+namespace :cache do
+ task :clear => :environment do
+ Rails.cache.clear
+ end
+end

0 comments on commit b7f0869

Please sign in to comment.