我尝试使用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'
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
P.S。当我在本地键入“touch tmp / restart.txt”时(在 cap production deploy 之后),我的页面不会随着我的修改而改变,我总是需要使用“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 :(得分:1)
对于重新启动应用的乘客,您应该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本身没有意义,除非你以升级乘客为例。
同样重启不是即时的,只有在启动后才会将请求路由到新代码