2015-12-11 69 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