部署 用 Capistrano 部署 Rabel

dotnil · 2013年03月17日 · 最后由 daqing 回复于 2013年03月17日 · 2755 次阅读

https://gist.github.com/dotnil/5181417

# encoding: utf-8

# config/deploy.rb
# 
#  - 使用 Unicorn
#  - 链接 rabel 的配置文件和用户上传内容
#  - 使用 RVM

# Add RVM's lib directory to the load path.
require "rvm/capistrano"

set :rvm_ruby_string, '1.9.3-p392'
set :rvm_type, :user

# http://gembundler.com/deploying.html
require 'bundler/capistrano'

# set this to keep from missing any password prompts
default_run_options[:pty] = true
set :ssh_options, { :forward_agent => true }

set :application, 'rabel'
set :scm, 'git'
set :scm_verbose, false

set :deploy_via, :remote_cache
set :deploy_to, "/var/www/wenyi.me"

set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"

set :repository, "git@github.com:daqing/#{application}.git"
set :branch, ENV['BRANCH'] || 'v2.0'

set :use_sudo, false
set :user, 'foo'

set :domain, 'wenyi.me'
set :rails_env, 'production'

role :web, domain
role :app, domain
role :db, domain, :primary => true

namespace :deploy do
  desc "启动服务"
  task :start, :roles => :app do
    run "cd #{current_path}; bundle exec unicorn_rails --port 3800 --env #{rails_env} --daemonize"
  end

  desc "停止服务"
  task :stop, :roles => :app do
    run "kill `cat #{unicorn_pid}`"
  end

  desc "重新加载服务"
  task :reload, :roles => :app do
    run "kill -s USR2 `cat #{unicorn_pid}`"
  end

  desc "重新启动服务"
  task :restart, :roles => :app do
    stop
    start
  end

  desc '收拾房间,链接文件'
  task :housekeeping, :roles => :app do
    run "rm -f #{current_path}/config/initializers/siteconf.rb"
    run "ln -s #{shared_path}/config/siteconf.rb #{current_path}/config/initializers/siteconf.rb"

    run "rm -f #{current_path}/config/database.yml"
    run "ln -s #{shared_path}/config/database.yml #{current_path}/config/database.yml"

    run "rm -rf #{current_path}/config/settings.yml"
    run "ln -s #{shared_path}/config/settings.yml #{current_path}/config/settings.yml"

    run "rm -rf #{current_path}/public/uploads"
    run "ln -s #{shared_path}/uploads #{current_path}/public/uploads"

    run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:clean"
    run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
  end
end

after 'deploy:create_symlink', 'deploy:housekeeping', 'deploy:migrate'
after 'deploy', 'deploy:cleanup'

@daqing

代码里的空行都没了,太过分了……

不错!

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册