Last active
December 17, 2015 06:48
-
-
Save songjiayang/5567955 to your computer and use it in GitHub Desktop.
cap deploy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
desc "重启服务器" | |
task :restart, :roles => :app do | |
run "touch #{current_path}/tmp/restart.txt" | |
end | |
desc "在本地生成配置文件" | |
task :setup_local_configs do | |
system "cat config/database.yml.example > config/database.yml" | |
system "cat config/resque.yml.example > config/resque.yml" | |
system "cat config/mongoid.yml.example > config/mongoid.yml" | |
system "cat config/memcached.yml.example > config/memcached.yml" | |
system "cat config/settings/production.yml.example > config/settings/production.local.yml" | |
puts "请修改如下配置,这些配置将同步到服务器" | |
puts "config/database.yml" | |
puts "config/resque.yml" | |
puts "config/mongoid.yml" | |
puts "config/memcached.yml" | |
puts "config/settings/production.local.yml" | |
end | |
desc "同步本地配置文件到app服务器" | |
task :sync_configs, roles: :app do | |
run "mkdir -p #{shared_path}/config" | |
run "mkdir -p #{shared_path}/config/settings" | |
put File.read("config/database.yml"), "#{shared_path}/config/database.yml" | |
put File.read("config/resque.yml"), "#{shared_path}/config/resque.yml" | |
put File.read("config/mongoid.yml"), "#{shared_path}/config/mongoid.yml" | |
put File.read("config/memcached.yml"), "#{shared_path}/config/memcached.yml" | |
put File.read("config/settings/production.local.yml"), "#{shared_path}/config/settings/production.local.yml" | |
end | |
desc "在服务器创建配置文件" | |
task :setup_configs, roles: :app do | |
run "mkdir -p #{shared_path}/config" | |
run "mkdir -p #{shared_path}/config/settings" | |
put File.read("config/database.yml.example"), "#{shared_path}/config/database.yml" | |
put File.read("config/resque.yml.example"), "#{shared_path}/config/resque.yml" | |
put File.read("config/mongoid.yml.example"), "#{shared_path}/config/mongoid.yml" | |
put File.read("config/memcached.yml.example"), "#{shared_path}/config/memcached.yml" | |
put File.read("config/settings/production.local.yml.example"), "#{shared_path}/config/settings/production.local.yml" | |
puts "请修改如下配置" | |
puts "#{shared_path}/config/database.yml" | |
puts "#{shared_path}/config/resque.yml" | |
puts "#{shared_path}/config/mongoid.yml" | |
puts "#{shared_path}/config/memcached.yml" | |
puts "#{shared_path}/config/settings/production.local.yml" | |
end | |
after "deploy:setup", "deploy:sync_configs" | |
desc '创建配置的软链接' | |
task :symlink_configs, roles: :app do | |
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" | |
run "ln -nfs #{shared_path}/config/resque.yml #{release_path}/config/resque.yml" | |
run "ln -nfs #{shared_path}/config/mongoid.yml #{release_path}/config/mongoid.yml" | |
run "ln -nfs #{shared_path}/config/memcached.yml #{release_path}/config/memcached.yml" | |
run "ln -nfs #{shared_path}/config/settings/production.local.yml #{release_path}/config/settings/production.local.yml" | |
end | |
after "deploy:update_code", "deploy:symlink_configs" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment