无法使用Capistrano删除旧版本



我最近将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

我在shared/tmp/cache/上尝试了chmod -R 777chown $USER

我也尝试过这个解决方案,我得到错误

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

config/deploy.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

很可能两者都不起作用,然后我建议查看此文档:从2.xx升级capistrano更具体地说,它建议从零开始capify项目,并手动移动旧的cap文件。

EDIT:您可以使用sudo手动删除有问题的目录吗?

sudo rm -rf /apps/myapp/releases/20210527195617/tmp/cache/bootsnap/compile-cache/36/9709c0fbdbcd6c

如果这样做有效,那就意味着您需要调整权限,以便您的capistrano用户可以删除该文件夹。如果不能做到这一点,手动清理以前的版本,并从那里开始对新用户进行新的部署应该可以工作。

能够通过运行sudo chown deploy app/myapp/releases来解决此问题。仍然不时弹出,但这修复了它。

您已经找到了一个适合您的解决方案,但在不首先设置正确所有者/权限的情况下强制删除的另一种方法是重新映射;rm";至";sudo rm":

SSHKit.config.command_map[:rm] = 'sudo rm'

所以每一个";rm";调用capistrano将使用";sudo rm";相反当然,您的capistrano用户需要一个无密码的sudo。

如果您不想使用sudo来运行命令,可以尝试通过在服务器上运行groups [your username]来检查您的用户属于哪个组。

当您有了这些信息后,您可以将其添加到您的deploy.rb中:set :group, "[your group]"

这修复了我在不再删除发布的项目中遇到的一些被拒绝权限的问题。

相关内容

  • 没有找到相关文章

最新更新