使用 Capsitrano 部署 Sinatra 项目

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

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

 2:bundle install 安装capistrano

 3: capify . 执行结果:
 

  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://xmo@10.1.1.172: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" # 默认执行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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值