暂时无法通过 capistrano 继续部署
Can't continue deploying after for while via capistrano
我的环境如下。
Environment
Version
Rails
7.0.0
Ruby
3.0.0
capistrano
3.16.0
Production environment
Amazon EC2 Linux
部署一段时间后,我得到了这些日志。
然后部署停止,不再工作。
INFO [41bfeeb4] Running /usr/bin/env sudo /bin/systemctl stop puma_〇〇_production as deploy@〇〇
DEBUG [41bfeeb4] Command: ( export RBENV_ROOT="/usr/local/src/rbenv" RBENV_VERSION="3.0.0" ; /usr/bin/env sudo /bin/systemctl stop puma_〇〇_production )
DEBUG [41bfeeb4]
あなたはシステム管理者から通常の講習を受けたはずです。
これは通常、以下の3点に要約されます:
#1) 他人のプライバシーを尊重すること。
#2) タイプする前に考えること。
#3) 大いなる力には大いなる責任が伴うこと。
DEBUG [41bfeeb4] [sudo] deploy password:
我觉得跟授权有关
我不知道如何修复。
我该怎么办?
deploy.rb
set :application, '〇〇'
set :repo_url, '〇〇'
set :deploy_to, '/var/www/〇〇'
set :puma_threads, [4, 16]
set :puma_workers, 0
set :pty, true
set :use_sudo, false
set :stage, :staging
set :deploy_via, :remote_cache
set :deploy_to, "/var/www/#{fetch(:application)}"
set :puma_bind,
"unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.access.log"
set :puma_error_log, "#{release_path}/log/puma.error.log"
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_restart_command, 'bundle exec puma'
set :rbenv_type, :system
set :rbenv_path, '/usr/local/src/rbenv'
set :rbenv_ruby, '3.0.0'
set :linked_dirs,
fetch(:linked_dirs, []).push(
'log',
'tmp/pids',
'tmp/cache',
'tmp/sockets',
'vendor/bundle',
'public/system',
'public/uploads',
)
set :linked_files,
fetch(:linked_files, []).push(
'config/database.yml',
'config/secrets.yml',
'config/puma.rb',
'.env',
)
namespace :puma do
Rake::Task[:restart].clear_actions
desc 'Overwritten puma:restart task'
task :restart do
puts 'Overwriting puma:restart to ensure that puma is running. Effectively, we are just starting Puma.'
puts 'A solution to this should be found.'
invoke 'puma:stop'
invoke 'puma:start'
end
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc 'Make sure local git is in sync with remote.'
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts 'WARNING: HEAD is not the same as origin/master'
puts 'Run `git push` to sync changes.'
exit
end
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
end
after 'deploy', 'sitemap:refresh'
Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
require 'capistrano/rails'
require 'capistrano/rbenv'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/bundler'
require 'capistrano/puma'
require 'capistrano/sitemap_generator'
require 'whenever/capistrano'
require 'dotenv'
Dotenv.load
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Systemd
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
deploy 用户需要是 sudo 用户才能重启 puma systemctl 服务。
您可以通过在 /etc/sudoers.d 目录中创建新文件并添加此行来解决此问题
deploy ALL=(ALL) NOPASSWD:/bin/systemctl
我的环境如下。
Environment | Version |
---|---|
Rails | 7.0.0 |
Ruby | 3.0.0 |
capistrano | 3.16.0 |
Production environment | Amazon EC2 Linux |
部署一段时间后,我得到了这些日志。
然后部署停止,不再工作。
INFO [41bfeeb4] Running /usr/bin/env sudo /bin/systemctl stop puma_〇〇_production as deploy@〇〇
DEBUG [41bfeeb4] Command: ( export RBENV_ROOT="/usr/local/src/rbenv" RBENV_VERSION="3.0.0" ; /usr/bin/env sudo /bin/systemctl stop puma_〇〇_production )
DEBUG [41bfeeb4]
あなたはシステム管理者から通常の講習を受けたはずです。
これは通常、以下の3点に要約されます:
#1) 他人のプライバシーを尊重すること。
#2) タイプする前に考えること。
#3) 大いなる力には大いなる責任が伴うこと。
DEBUG [41bfeeb4] [sudo] deploy password:
我觉得跟授权有关
我不知道如何修复。
我该怎么办?
deploy.rb
set :application, '〇〇'
set :repo_url, '〇〇'
set :deploy_to, '/var/www/〇〇'
set :puma_threads, [4, 16]
set :puma_workers, 0
set :pty, true
set :use_sudo, false
set :stage, :staging
set :deploy_via, :remote_cache
set :deploy_to, "/var/www/#{fetch(:application)}"
set :puma_bind,
"unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.access.log"
set :puma_error_log, "#{release_path}/log/puma.error.log"
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_restart_command, 'bundle exec puma'
set :rbenv_type, :system
set :rbenv_path, '/usr/local/src/rbenv'
set :rbenv_ruby, '3.0.0'
set :linked_dirs,
fetch(:linked_dirs, []).push(
'log',
'tmp/pids',
'tmp/cache',
'tmp/sockets',
'vendor/bundle',
'public/system',
'public/uploads',
)
set :linked_files,
fetch(:linked_files, []).push(
'config/database.yml',
'config/secrets.yml',
'config/puma.rb',
'.env',
)
namespace :puma do
Rake::Task[:restart].clear_actions
desc 'Overwritten puma:restart task'
task :restart do
puts 'Overwriting puma:restart to ensure that puma is running. Effectively, we are just starting Puma.'
puts 'A solution to this should be found.'
invoke 'puma:stop'
invoke 'puma:start'
end
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc 'Make sure local git is in sync with remote.'
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts 'WARNING: HEAD is not the same as origin/master'
puts 'Run `git push` to sync changes.'
exit
end
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
end
after 'deploy', 'sitemap:refresh'
Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
require 'capistrano/rails'
require 'capistrano/rbenv'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/bundler'
require 'capistrano/puma'
require 'capistrano/sitemap_generator'
require 'whenever/capistrano'
require 'dotenv'
Dotenv.load
install_plugin Capistrano::Puma
install_plugin Capistrano::Puma::Systemd
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
deploy 用户需要是 sudo 用户才能重启 puma systemctl 服务。
您可以通过在 /etc/sudoers.d 目录中创建新文件并添加此行来解决此问题
deploy ALL=(ALL) NOPASSWD:/bin/systemctl