`

capistrano部署文件设置

 
阅读更多
本地项目部署远程,并在远程进行操作
github:https://github.com/capistrano/capistrano
capistrano一般依存与于一个rails项目项目里面,也可以创建一个文件development然后cd进去 cap install也能初始化
(1)group :development do
  gem 'capistrano'
  gem 'capistrano-bundler'
  gem 'capistrano-rails'
  gem 'capistrano-rbenv'
  # Add this if you're using rvm
  # gem 'capistrano-rvm'
end 可以选择部分
  (2)bundle exec cap install
            ├── Capfile
├── config
│   ├── deploy
│   │   ├── production.rb
│   │   └── staging.rb
│   └── deploy.rb
└── lib
    └── capistrano
            └── tasks
(3)deploy文件里 main可以设置
    set :stage_dir, 'config/deploy'
set :stages, ["iqiyi_bj_production","iqiyi_sh_production","youku_production","tencent_production"]有些可以能直接是%w{development production}看自己需求吧,取其他名字对应在(2)config/deploy修改名字
(4)config/deploy/xxx_production.rb文件配置
        set :application, 'iqiyi'
#server  部署两台,可以自己选一台
server 'remote_ip:30066', user: 'your remote serve name',  password: 'your remote serve password', roles: %w{web app db}
server 'remote_ip:30066', user: 'your remote serve name',  password: 'your remote serve password', roles: %w{web app db}

#代码仓库
set :repo_url, 'ssh://git@xxxxx/home/git/projects/xxxxx'
set :branch, 'master'

#目标目录
set :deploy_to, '/home/bbbb' #远程目录
set :scm, :git
set :rails_env, fetch(:stage)
set :pty, true

set :keep_releases, 5
(5)写task任务,操作命令
       1)第一个任务把代码copy到远程(自动完成)
           可以用的命令,after :finishing, 'deploy:cleanup'
                      after :published, :copy_yml_files
                      after :published, :build_xxx
          还有其他命令 build_xxx这是一个task任务即在部署完成后自动运行的任务
        2)自定义命令
            task :start do
    on roles(:all) do
      (3101..3102).each do |i|
        stage_param="#{fetch(:stage)}"
        astage_param = stage_param.split("_")
        stage_param = astage_param[2]
        platform_param = astage_param[0]
        if stage_param=="production"
          stage_param="prod"
        end
        execute <<-EOBLOCK
          logdir=/app/logs/xxx
          if [ -d $logdir ]
            then echo "$logdir exist!"
            else mkdir $logdir
            echo "$logdir created!"
          fi
        EOBLOCK
execute <<-EOBLOCK
echo "#{fetch(:stage)}"
EOBLOCK
    execute "cd #{current_path}; ./eagle -r #{platform_param} -p #{i} -e #{stage_param} -c false -alsologtostderr=false -log_dir=\"/app/logs/bidder\" > #{current_path}/nohuplog 2>&1 &"#, pty: false
    execute "cat #{current_path}/nohuplog"
      end
    end
  end
    上面定义了一个start任务 也可以其他
均是在namespace :deploy do
     方法体里面
       task :restart do
            on roles(:all) do
            Rake::Task["deploy:stop"].invoke
            Rake::Task["deploy:start"].invoke
          end
       end
end有些可能不是用execute这个方法,直接run的方式


https://ruby-china.org/topics/18616
http://www.361way.com/capistrano-deploy/3563.html
文档很详细
     cap  xxx_production deploy
     cap xxx_production deploy:start
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics