分享 使用 Capsitrano 部署 Sinatra 项目

noob · 2015年07月31日 · 2368 次阅读

第一次发帖,请各位多多指教,新人在此谢过了,格式不太好,以后会多多注意的 1:首先在 Gemfile 中加入

 group :development do
     gem 'capistrano'
     gem 'capistrano-chruby'
     gem 'capistrano-rvm'
     gem 'capistrano-bundler'
end   

2:bundle install 安装 capistrano 3:执行结果:

  dongchaodeMacBook-Pro:happy iclick$ capify .
--------------------------------------------------------------------------------
Capistrano 3.x is incompatible with Capistrano 2.x.

This command has become `cap install` in Capistrano 3.x

For more information see http://www.capistranorb.com/
————————————————————————————————————————

4:执行 cap install 执行结果

dongchaodeMacBook-Pro:happy iclick$ cap install
mkdir -p config/deploy
create config/deploy.rb
create config/deploy/staging.rb
create config/deploy/production.rb
mkdir -p lib/capistrano/tasks
create Capfile
Capified

5:配置发布项目的一些属性 1)在 config/deploy.rb 中加入如下例子:(根据不同的项目更改不同的配置信息)

# config valid only for current version of Capistrano
lock '3.4.0'

set :application, 'redis_move'   #项目的名称

set :repo_url, 'ssh://[email protected]:2727/share/xmo/redis_move'  #得到项目源码地址

set :branch,'flush_code'  # 远程分支

set :deploy_to, '/opt/redis_move'  #发布到服务器的存储地址


set :bundle_flags, '--deployment' 

set :bundle_gemfile, -> { release_path.join('Gemfile') } 
注: bundle_gemfile bundle_flags 发布的时候自动执行bundle,还需要将 根目录下Capfile中得require 'capistrano/bundler'注释解开

set :chruby_ruby, 'ruby-2.1.3'

set :rvm_ruby_version, 'ruby-2.1.3'

set :stages, %w(staging production)

set :default_stage, "production"

注:set:stages 中后面的值和 config/deploy/下面的文件名称相对应 default_stage 默认执行 production 中得配置 (其中配置内容 eg:server '10.21.20.124', user: 'xmo', roles: %w{web})

set :scm, :git #默认使用git

set :linked_files, fetch(:linked_files, []).push("config.ru")
 #添加一些项目中不变更的配置信息这些配置文件会被放在shared中,作用是将shared中得文件链接到repo下来的项目中,
注:首先shared中得文件事先scp上去,否则会报错


set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
# 是将项目的指定目录链接到shared目录中。这个操作会在从repo取下代码之后进行

# Default value for keep_releases is 5
set :keep_releases, 5

#每次发布完成之后使用thin重启服务
namespace :deploy do
    task :start do
        on roles(:web),in: :sequence, wait: 3 do
            within release_path do
                execute "cd /opt/redis_move/current;bundle exec thin -P tmp/rack.pid -e production -p 9191 -l logs/thin.log -d start"
           end
       end
end

task :stop do
    path = File.expand_path("..", __FILE__)
    file_path = File.join(path, "tmp/rack.pid")
    if File.exist?(file_path) then
       File.open(file_path) do |file|
           pid = file.read
          system("kill -9 #{pid}")
       end
     FileUtils.rm file_path
  end
end

task :restart => [:stop, :start]

after :published, :restart


end

上传服务器之后的文件列表图片 更多详细信息:https://ruby-china.org/topics/18616

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号