Skip to content

Instantly share code, notes, and snippets.

@nragaz
Created July 12, 2010 03:29
Show Gist options
  • Save nragaz/472103 to your computer and use it in GitHub Desktop.
Save nragaz/472103 to your computer and use it in GitHub Desktop.
CURRENT_RUBY = 'ree-1.8.7-2010.02'
RUBY_PATH = "/home/rails/.rvm/rubies/#{CURRENT_RUBY}"
GEM_HOME = "/home/rails/.rvm/gems/#{CURRENT_RUBY}"
ssh_options[:paranoid] = false
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :stages, %w(staging production)
set :default_stage, "production"
require 'capistrano/ext/multistage'
require 'config/boot'
require 'hoptoad_notifier/capistrano'
set :application, "myapp"
set :domain, "myapp.com"
set :user, "rails"
set :use_sudo, false
set :deploy_to, "/srv/myapp"
set :deploy_via, :remote_cache
set :keep_releases, 2
set :repository, "[email protected]:nragaz/myapp.git"
set :scm, :git
set :branch, 'master'
set :git_enable_submodules, 1
set :rails_env, 'production'
set :default_environment, {
'PATH' => "#{GEM_HOME}/bin:#{GEM_HOME}@global/bin:#{RUBY_PATH}/bin:/home/rails/.rvm/bin:$PATH",
'RUBY_VERSION' => CURRENT_RUBY,
'GEM_HOME' => GEM_HOME,
'GEM_HOME' => "#{GEM_HOME}:#{GEM_HOME}@global",
'BUNDLE_PATH' => GEM_HOME
}
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
god.start
end
task :stop, :roles => :app, :except => { :no_release => true } do
god.terminate
end
task :restart, :roles => :app, :except => { :no_release => true } do
god.reload
god.restart_resque
god.restart_unicorn
end
task :bundle do
run "cd #{release_path} && RAILS_ENV=#{rails_env} bundle install"
end
desc "Symlinks the database.yml"
task :symlink_db, :roles => :app do
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end
desc "Symlinks the downtime site"
task :symlink_downtime, :roles => :app do
run "ln -nfs #{release_path}/config/down #{deploy_to}/shared/down"
end
end
namespace :db do
desc "Copy local database.yml.example to server"
task :database_yml, :roles => :app do
run "mkdir #{deploy_to}/shared/config ; true"
upload("config/database.yml.example", "#{deploy_to}/shared/config/database.yml")
end
end
namespace :god do
task :restart_resque, :roles => :app do
sudo "#{GEM_HOME}/bin/god restart resque"
end
task :restart_unicorn, :roles => :app do
sudo "#{GEM_HOME}/bin/god restart unicorn"
end
desc "Reload config"
task :reload, :roles => :app do
sudo "#{GEM_HOME}/bin/god load #{deploy_to}/current/config/god/all.god"
end
desc "Start god"
task :start, :roles => :app do
sudo "#{GEM_HOME}/bin/god -c #{deploy_to}/current/config/god/all.god"
end
desc "Quit god, but not the processes it's monitoring"
task :quit, :roles => :app do
sudo "#{GEM_HOME}/bin/god quit"
end
desc "Terminate god and all monitored processes"
task :terminate, :roles => :app do
sudo "#{GEM_HOME}/bin/god terminate"
end
desc "Describe the status of the running tasks"
task :status, :roles => :app do
sudo "#{GEM_HOME}/bin/god status"
end
end
namespace :nginx do
desc "Deploy site configs from Github"
task :config do
# delete old configs
sudo "rm /etc/nginx/nginx.conf ; true"
sudo "rm /etc/nginx/sites-available/default ; true"
sudo "rm /etc/nginx/sites-enabled/default ; true"
sudo "rm /etc/nginx/sites-available/down ; true"
sudo "rm /etc/nginx/sites-available/up ; true"
# install new configs
run "cd ~ && rm -rf nginx-config* && git clone [email protected]:gist-with-nginx-files.git nginx-config"
sudo "mv /home/rails/nginx-config/nginx.conf /etc/nginx/nginx.conf"
sudo "mv /home/rails/nginx-config/down /etc/nginx/sites-available/down"
sudo "mv /home/rails/nginx-config/up /etc/nginx/sites-available/up"
sudo "ln -nfs /etc/nginx/sites-available/up /etc/nginx/sites-enabled/up"
run "rm -rf nginx-config"
end
desc "Restart nginx"
task :restart do
sudo "/etc/init.d/nginx restart"
end
desc "Stop nginx"
task :stop do
sudo "/etc/init.d/nginx stop"
end
desc "Start nginx"
task :start do
sudo "/etc/init.d/nginx start"
end
desc "Enable downtime site"
task :down do
sudo "rm /etc/nginx/sites-enabled/up ; true"
sudo "ln -nfs /etc/nginx/sites-available/down /etc/nginx/sites-enabled/down"
nginx.restart
end
desc "Enable uptime site"
task :up do
sudo "rm /etc/nginx/sites-enabled/down ; true"
sudo "ln -nfs /etc/nginx/sites-available/up /etc/nginx/sites-enabled/up"
nginx.restart
end
end
desc "Show memory consumption on the server"
task :free do
run "free -lm"
end
after "deploy:update_code" do
deploy.symlink_db
deploy.symlink_downtime
deploy.bundle
deploy.migrate
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment