Issue
I recently upgraded my Rails application from Ruby 2.7.3 to 3.0.1. Now I'm unable to delete old releases when deploying with Capistrano. I get the error below
DEBUG [f5dff474] rm: cannot remove '/home/deploy/apps/myapp/releases/20210527195617/tmp/cache/bootsnap/compile-cache/36/9709c0fbdbcd6c': Permission denied
I tried chmod -R 777
and chown $USER
on shared/tmp/cache/
I've also tried this solution, I get the error
OptionParser::AmbiguousOption: ambiguous option: -s
Caused by:
OptionParser::InvalidOption: invalid option: s
Caused by:
ArgumentError: wrong number of arguments (given 1, expected 0)
I've also tried setting 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
Solution
Was able to get this resolved by running sudo chown deploy app/myapp/releases
. Still pops up from time to time, but this fixes it.
Answered By - Antarr Byrd Answer Checked By - David Marino (WPSolving Volunteer)