Skip to content

Instantly share code, notes, and snippets.

@biti
Created September 11, 2011 02:47
Show Gist options
  • Save biti/1209101 to your computer and use it in GitHub Desktop.
Save biti/1209101 to your computer and use it in GitHub Desktop.
自动部署脚本
# auto deploy script
# content: sync update all servers code, control unicorn servers and thin servers
# by liuzihua
default_environment["LC_CTYPE"] = "en_US.UTF-8"
# servers!
set :server1, "124.42.34.226"
set :server2, "124.42.34.238"
set :server3, "119.254.7.196"
set :application, "tuan"
set :repository, "svn://124.42.34.238/fantong_web/fantuan/trunk"
set :scm, :subversion
set :svn_username, 'liuzihua'
set :svn_password, 'zihua'
# rails app path!
set :deploy_to, "/home/www/tuan"
set :current_path, "#{deploy_to}/current"
set :use_sudo, false
set :user, "www"
# unicorn config
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
# thin config
set :thin_config, "#{current_path}/config/thin.yml"
puts "[deploy config]"
puts "---------------------------"
puts "application:\t%s" % application
puts "scm:\t%s" % scm
puts "repository:\t%s" % repository
puts "deploy_to:\t%s" % deploy_to
puts "current_path:\t%s" % current_path
puts "user:\t%s" % user
puts "server1:\t%s" % server1
puts "server2:\t%s" % server2
puts "unicorn_config:\t%s" % unicorn_config
puts "unicorn_pid:\t%s" % unicorn_pid
puts "thin_config:\t%s" % thin_config
puts "---------------------------"
puts
role :web, server1
role :app, server1, server2, server3
role :app1, server1
role :app2, server2
role :app3, server3
namespace :deploy do
task :start, :roles => :app do
puts '===start app servers...'
start_unicorn
start_thin
end
task :stop, :roles => :app do
puts '===stop app servers...'
stop_unicorn
stop_thin
end
task :restart, :roles => :app, :except => { :no_release => true } do
puts '===restart app servers...'
restart_unicorn
restart_thin
end
task :start_unicorn, :roles => [:app1, :app3] do
puts '===start unicorn servers...'
run "cd #{current_path} && unicorn_rails -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop_unicorn, :roles => [:app1, :app3] do
puts '===stop unicorn servers...'
run "kill -s QUIT `cat #{unicorn_pid}`"
end
# 参考https://gist.github.com/393178
task :restart_unicorn, :roles => [:app1, :app3] do
puts '===restart unicorn servers...'
run "kill -s USR2 `cat #{unicorn_pid}`"
end
task :start_thin, :roles => :app2 do
puts '===start thin servers'
run "thin start -C #{thin_config}"
end
task :stop_thin, :roles => :app2 do
puts '===stop thin servers'
run "thin stop -C #{thin_config}"
end
task :restart_thin, :roles => :app2 do
puts '===restart thin servers'
run "thin restart -C #{thin_config}"
end
end
# tail log
namespace :logs do
namespace :rails do
task :app1, :roles => :app1 do
stream "tail -f #{deploy_to}/shared/log/production.log"
end
task :app2, :roles => :app2 do
stream "tail -f #{deploy_to}/shared/log/production.log"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment