gpt4 book ai didi

ruby-on-rails - 无法使用 Capistrano 删除旧版本

转载 作者:行者123 更新时间:2023-12-04 18:42:56 25 4
gpt4 key购买 nike

我最近将我的 Rails 应用程序从 Ruby 2.7.3 升级到了 3.0.1。现在,在使用 Capistrano 部署时,我无法删除旧版本。我收到以下错误

 DEBUG [f5dff474]       rm: cannot remove '/home/deploy/apps/myapp/releases/20210527195617/tmp/cache/bootsnap/compile-cache/36/9709c0fbdbcd6c': Permission denied
我试过 chmod -R 777chown $USERshared/tmp/cache/我也试过 this solution ,我得到错误
OptionParser::AmbiguousOption: ambiguous option: -s


Caused by:
OptionParser::InvalidOption: invalid option: s


Caused by:
ArgumentError: wrong number of arguments (given 1, expected 0)
我也试过设置 set :use_sudo, true配置/部署.rb
# frozen_string_literal: true

# config valid only for current version of Capistrano
# lock '3.13.0'


set :application, 'my-app'
set :user, 'deploy'

set :puma_threads, [4, 16]
set :puma_workers, 0

set :appsignal_config, name: 'MyApp'
set :appsignal_env, :production
set :appsignal_revision, `git log --pretty=format:'%h' -n 1`

# Don't change these unless you know what you're doing
set :pty, false # https://github.com/seuros/capistrano-sidekiq#known-issues-with-capistrano-3
set :use_sudo, true
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{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.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord
set :keep_assets, 5

## Defaults:
# set :scm, :git
# set :branch, :master
# set :format, :pretty
# set :log_level, :debug
set :keep_releases, 5

set :rbenv_type, :user
set :rbenv_ruby, '3.0.1'
set :migration_role, :app
# set :bundle_binstubs, -> { shared_path.join('bin') }
# set :rbenv_map_bins, %w{rake gem bundle ruby rails}

## Linked Files & Directories (Default None):
# set :linked_files, %w{config/database.yml}
# set :linked_files, %w{config/master.key}
set :linked_files, ['.env.production']
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system db/backups/production}

namespace :puma do
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

task :restart_sidekiq do
on roles(:worker) do
execute :service, "sidekiq restart"
end
end
after "deploy:published", "restart_sidekiq"

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 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end

desc 'Run rake yarn:install'
task :yarn_install do
on roles(:web) do
within release_path do
execute("cd #{release_path} && yarn install")
end
end
end

before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
before "deploy:assets:precompile", "deploy:yarn_install"
end

# ps aux | grep puma # Get puma pid
# kill -s SIGUSR2 pid # Restart puma
# kill -s SIGTERM pid # Stop puma

最佳答案

感觉您的 capistrano 可能与引用答案中的不一样。
您也许可以跳过 -s 参数并尝试:

cap production deploy:cleanup use_sudo=true
请注意,从 3.x 开始,不再需要像 use_sudo 这样的一些参数。
您还可以尝试使用 sudo 为清理上限添加前缀,看看会发生什么:
sudo cap production deploy:cleanup
很可能两者都不起作用,然后我建议查看此文档: upgrading capistrano from 2.xx更具体地说,它建议从头开始 capify 项目并手动移动旧 cap 文件的第 2 项。
编辑 : 你可以使用 sudo 并手动删除有问题的目录吗?
sudo rm -rf /apps/myapp/releases/20210527195617/tmp/cache/bootsnap/compile-cache/36/9709c0fbdbcd6c
如果可行 - 这意味着您需要调整权限,以便允许您的 capistrano 用户删除该文件夹。如果不能这样做,手动清理以前的版本并从那里使用新用户完成的新部署应该可以工作。

关于ruby-on-rails - 无法使用 Capistrano 删除旧版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67754551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com