Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 11-15 of 15 total

SVN revision from shell

I use this to set the subject of an email that notifies my team of a Capistrano deploy. The part of interest is how it gets the subversion revision number with a few piped shell commands.

echo "Subject: [rake deploy] Deployed revision `cd /home/www/current ; svn info | grep Revision | sed "s/Revision: //"` on `hostname` at `date`" > ~/sendmail_tmp

Run script/console Remotely with Capistrano

From http://errtheblog.com/post/21.
Allows you to execute script/console remotely through Capistrano. Not for use on multi-machine :roles.

desc "remotely console" 
task :console, :roles => :app do
  input = ''
  run "cd #{current_path} && ./script/console #{ENV['RAILS_ENV']}" do |channel, stream, data|
    next if data.chomp == input.chomp || data.chomp == ''
    print data
    channel.send_data(input = $stdin.gets) if data =~ /^(>|\?)>/
  end
end

Tail Multiple Log Files At Once With Capistrano

From http://errtheblog.com/post/21
Allows you to aggregate the tailing of multiple production log files with one Capistrano task

Stick it in deploy.rb:
desc "tail production log files" 
task :tail_logs, :roles => :app do
  run "tail -f #{shared_path}/log/production.log" do |channel, stream, data|
    puts  # for an extra line break before the host name
    puts "#{channel[:host]}: #{data}" 
    break if stream == :err    
  end
end

List files that would be changed in a Capistrano deploy

// description of your code here
Sometimes you want to know before hand which files have been added or changed since your last deploy. Maybe you have to run a migration. Assuming you're using subversion for you source control, this task will list the pending changes.


desc "List the files that would be updated or changed in a deploy."
task :svn_st_up, :roles => :app do
  run "cd #{current_path} && " + "svn st -u"
end


from my blog

Mongrel Spinner and Restart tasks for Capistrano

These tasks should work with the default deploy.rb file. I assume you've at least read the Capistrano manual at rubyonrails.com, also, you should get your app running on mongrel first with manual booting and restarting before you try to automate.

h2. Spinner

desc <<-DESC
Spinner is run by the default cold_deploy task. Instead of using script/spinner, we're just gonna rely on Mongrel to keep itself up.
DESC
task :spinner, :roles => :app do
  application_port = xxxx #get this from your friendly sysadmin
  run "mongrel_rails start -e production -p #{application_port} -d -c #{current_path}"
end


h2. Restart

desc "Restart the web server"
task :restart, :roles => :app do
  begin
    run "cd #{current_path} && mongrel_rails restart"
  rescue RuntimeError => e
    puts e
    puts "Probably not a big deal, so I'll just keep trucking..."
  end
end


There's a more complete article on my blog.
« Newer Snippets
Older Snippets »
Showing 11-15 of 15 total