ruby Capistrano 2为乘客提供Nginx的部署脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Capistrano 2为乘客提供Nginx的部署脚本相关的知识,希望对你有一定的参考价值。

require 'rvm/capistrano'
require 'bundler/capistrano'


set :server_name, "example.com"
set :application, "application_name"
set :repository,  "git@github.com:username/#{application}.git"

# Uses local instead of remote server keys
ssh_options[:forward_agent] = true
set :deploy_via, :remote_cache
set :rvm_ruby_string, 'default'
set :rvm_type, :user
set :use_sudo, false
set :user, "deploy"
set :deploy_to, "/home/deploy/apps/#{application}"
set :rails_env, "production"
set :branch, "master"
set :keep_releases, 5
default_run_options[:pty] = true
ssh_options[:port] = 56
set :scm, :git
after "deploy:restart", "deploy:cleanup"

role :web, "#{server_name}"                          # Your HTTP server, Apache/etc
role :app, "#{server_name}"                          # This may be the same as your `Web` server
role :db,  "#{server_name}", :primary => true        # This is where Rails migrations will run


namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "touch #{File.join(current_path,'tmp','restart.txt')}"
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /opt/nginx/sites-enabled/#{application}"
    sudo "service nginx restart"
  end
end

before "deploy:setup", "db:configure"
after  "deploy:update_code", "db:symlink"

namespace :db do
  desc "Create database yaml in shared path"
  task :configure do
    set :database_username do
      "rails"
    end

    set :database_password do
      Capistrano::CLI.password_prompt "Database Password: "
    end

    db_config = <<-EOF
          base: &base
            adapter: mysql2
            encoding: utf8
            reconnect: false
            pool: 5
            username: #{database_username}
            password: #{database_password}

          development:
            database: #{application}_development
            <<: *base

          test:
            database: #{application}_test
            <<: *base

          production:
            database: #{application}_production
            <<: *base
            EOF

            run "mkdir -p #{shared_path}/config"
            put db_config, "#{shared_path}/config/database.yml"
  end

  desc "Make symlink for database yaml"
  task :symlink do
    run "ln -nfs #{shared_path}/config/database.yml #{latest_release}/config/database.yml"
  end

end

以上是关于ruby Capistrano 2为乘客提供Nginx的部署脚本的主要内容,如果未能解决你的问题,请参考以下文章

ruby 周五为Capistrano部署脚本

ruby 简单的Capistrano部署为Docker管理的应用程序

Capistrano在升级ruby版本和puma时重启错误版本的puma

Capistrano:我可以为整个 cap 会话设置一个环境变量吗?

Capistrano自动化部署工具安装详细过程

/usr/bin/env ruby​​ 没有这样的文件或目录:使用 capistrano 3、capistrano/rbenv、capistrano/bundler 和 capistrano/rail