2015-12-11 68 views
0

我尝试使用Capistrano的部署我的应用程序,在制定Capistrano的所有问题是固定的,除非...rails使用capistrano来部署和重启?

我不能自动重新启动服务器后部署,这里是我的代码:

的Gemfile :

gem 'capistrano-rails', '~> 1.1.3'#, group: :development 
gem 'capistrano', '~> 3.1' 
gem 'capistrano-rbenv', '~> 2.0' 
gem 'capistrano-bundler', '~> 1.1.2' 
gem 'capistrano-passenger', '~> 0.1.1' 
gem 'capistrano3-delayed-job', '~> 1.0' 
gem 'capistrano3-nginx', '~> 2.0' 

capfile:

require 'capistrano/setup' 
require 'capistrano/deploy' 

require 'capistrano/rbenv' 
require 'capistrano/bundler' 
require 'capistrano/rails/assets' 
require 'capistrano/rails/migrations' 
require 'capistrano/passenger' 
require 'capistrano/delayed-job' 
require 'capistrano/nginx' 

Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } 

deploy.rb:

require "whenever/capistrano" 
`ssh-add` # need this to make key-forwarding work 

set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" } 

set :application, 'devops' 
set :repo_url, 'mygit' 

set :rbenv_type, :user 
set :rbenv_ruby, "2.2.2" 
set :rbenv_path, "/home/john/.rbenv" 
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" 
set :rbenv_map_bins, %w(rake gem bundle ruby rails) 
set :rbenv_roles, :all 

set :deploy_to, '/home/john/devops' 
set :log_level, :debug 

set :linked_dirs, fetch(:linked_dirs, []).push("bin", "log", "tmp/pids", "tmp/cache", "tmp/sockets", "vendor/bundle", "public/system") 

deploy.rb

namespace :deploy do 

# I try following code: 
#--- 
after :deploy, cap nginx:restart 
run "sudo /etc/init.d/nginx restart" 
run "touch tmp/restart.txt" 
after :deploy, cap production passenger:restart 
after :deploy, cap production deploy:restart 
#--- 

# invoke 'delayed_job:restart' 

    after :restart, :clear_cache do 
    on roles(:web), in: :groups, limit: 3, wait: 10 do 
     # Here we can do anything such as: 
     within release_path do 
     execute :rake, 'cache:clear' 
     end 
    end 
    end 
end 

附:当我在本地输入“touch tmp/restart.txt”(在cap production部署后),我的页面不会随着我的修改而改变,我总是需要使用“sudo /etc/init.d/nginx restart”,我该如何解决这个问题?

我试试这个,也没有响应(没有错误味精):

after 'deploy:publishing', 'deploy:restart' 

namespace :deploy do 

    desc "Restart application" 

    after :publishing, 'deploy:restart' 

    task :restart do 
    on roles(:app), in: :sequence, wait: 1 do 
     execute :touch, release_path.join("tmp/restart.txt") 
    end 
    end 

end 

回答

0

对于乘客重新启动应用程序,你应该touch/restart.txt在服务器上,而不是本地:

namespace :deploy do 

    desc 'Restart application' 
    task :restart do 
    on roles(:app), in: :sequence, wait: 5 do 
     # Restarts Phusion Passenger 
     execute :touch, release_path.join('tmp/restart.txt') 
    end 
    end 

end 

有没有点重新启动nginx本身,除非你升级乘客例如。

而且重启不即时,请求路由到它已经开始后才新代码

+0

我试过“触摸/ restart.txt”在服务器端,并且它没有任何反应,我也试过您的解决方案,但不工作... – John

+0

在服务器上,我尝试“触摸电流/ tmp/restart.txt”或“触摸/home/john/devops/current/tmp/restart.txt”,所有的工作,但是当我尝试你的解决方案或“执行:touch,current_path.join('tmp/restart.txt')“,没有回应... – John