// Capistano Deployment Recipe ////////////////////////////// # == Common Settings ======================================================== default_run_options[:pty] = true set :application, "dates_facebook" set :scm, "git" set :repository, "git@github.com:johnantoni/dates.git" set :branch, "facebook" set :deploy_via, :remote_cache set :user, "deploy" set :keep_releases, 3 # == Tasks ================================================================== task :production do set :application, "dates_facebook" set :rails_env, "production" set :domain, "linode.red91.com" ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "linode")] ssh_options[:port] = 22 role :web, domain role :app, domain role :db, domain, :primary => true set :deploy_to, "/web/#{application}" namespace :deploy do desc "Restarting mod_rails with restart.txt" task :restart, :roles => :app, :except => { :no_release => true } do run "touch #{release_path}/tmp/restart.txt" end [ :start, :stop ].each do |t| desc "#{t} task is a no-op with mod_rails" task t, :roles => :app do ; end end end end namespace :deploy do task :symlink_files, :roles => :app, :except => { :no_symlink => true } do run <<-CMD cd #{release_path} && cp config/database-#{rails_env}.yml config/database.yml && cp config/memcached-#{rails_env}.yml config/memcached.yml CMD end end desc "Generate a maintenance.html to disable requests to the application." deploy.web.task :disable, :roles => :web do disable_template = "./app/views/layouts/maintenance.rhtml" remote_path = "#{shared_path}/system/maintenance.html" on_rollback { run "rm #{remote_path}" } template = File.read(disable_template) deadline, reason = ENV["UNTIL"], ENV["REASON"] maintenance = ERB.new(template).result(binding) put maintenance, "#{remote_path}", :mode => 0644 end after "deploy:update_code", "deploy:symlink_files" // Sample Methods ///////////////// def patch_uploads(file) # uploads < 20k are stringio streams if file.kind_of? StringIO file.rewind realFile = Tempfile.new(file.original_filename) while not file.eof? realFile.write file.read end else realFile = file end return realFile end class Hash def paginate_hash(id) return self.flatten_values.simply_paginate_array(id) end def flatten to_a.flatten! end def flatten_values a = Array.new self.each {|k,v| a.push(v) } return a end end