簡體   English   中英

Rails使用capistrano進行部署並重新啟動?

[英]rails use capistrano to deploy and restart?

我嘗試使用capistrano部署我的應用程序,設置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'

上限文件:

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

PS,當我在本地上鍵入“ touch tmp / restart.txt”( 部署帽子生產后)時,我的頁面沒有隨我的修改而更改,我始終需要使用“ 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

為了讓乘客重新啟動應用,您應該在服務器(而非本地)上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本身沒有任何意義,除非您要升級乘客。

而且重啟不是立即進行的,請求只有在啟動后才被路由到新代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM