I'm trying to deploy a Rails 5.1 app. I have deployed the app several times without problems, but now, all of a sudden I get this error message from Capistrano
00:13 deploy:cleanup
SSHKit::Command::Failed: rm exit status: 1
rm stdout: Nothing written
rm stderr: rm: cannot remove '/opt/www/absence-
registrator/releases/20171017091250/node_modules/jquery/dist/jquery.js':
Permission denied
Tasks: TOP => deploy:cleanup
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as
[email protected]: rm exit status: 1 │
rm stdout: Nothing written
rm stderr: rm: cannot remove '/opt/www/absence-
registrator/releases/20171017091250/node_modules/jquery/dist/jquery.js':Permission denied
rm: cannot remove '/opt/www/absence-registrator/releases/20171017091250/node_modules/jquery/dist/jquery.slim.js': Permission denied rm: cannot remove '/opt/www/absence-registrator/releases/20171017091250/node_modules/jquery/dist/jquery.min.js': Permission denied rm: cannot remove '/opt/www/absence-registrator/releases/20171017091250/node_modules/jquery/dist/jquery.min.map': Permission denied
It seems the deploy user that Capistrano is using to remove older versions, doesn't have enough permissions to remove node_modules
I tried to fix the issue by setting node_modules to the linked directories:
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets node_modules}
but that didn't fix it either.
Does someone have an idea how to fix this?
thanks for your help,
Anthony
ps: this is the output of the ls -lt command in the current directory:
-rw-rw-r-- 1 deploy deploy 864 Oct 27 14:04 Capfile
-rw-rw-r-- 1 deploy deploy 2454 Oct 27 14:04 Gemfile
-rw-rw-r-- 1 deploy deploy 8520 Oct 27 14:04 Gemfile.lock
-rw-rw-r-- 1 deploy deploy 148 Oct 27 14:04 README.md
-rw-rw-r-- 1 deploy deploy 227 Oct 27 14:04 Rakefile
drwxrwxr-x 10 deploy deploy 4096 Oct 27 14:04 app
drwxrwxr-x 2 deploy deploy 4096 Oct 27 14:04 bin
drwxrwxr-x 6 deploy deploy 4096 Oct 27 14:04 config
-rw-rw-r-- 1 deploy deploy 130 Oct 27 14:04 config.ru
drwxrwxr-x 3 deploy deploy 4096 Oct 27 14:04 db
drwxrwxr-x 4 deploy deploy 4096 Oct 27 14:04 lib
-rw-rw-r-- 1 deploy deploy 103 Oct 27 14:04 package.json
drwxrwxr-x 8 deploy deploy 4096 Oct 27 14:04 spec
drwxrwxr-x 2 deploy deploy 4096 Oct 27 14:04 vendor
-rw-rw-r-- 1 deploy deploy 228 Oct 27 14:04 yarn.lock
drwxrwxr-x 2 deploy deploy 4096 Oct 27 13:58 assets_manifest_backup
drwxrwxr-x 3 deploy deploy 4096 Oct 27 13:58 public
lrwxrwxrwx 1 deploy deploy 48 Oct 27 13:58 node_modules ->
/opt/www/absence-registrator/shared/node_modules
drwxrwxr-x 2 deploy deploy 4096 Oct 27 13:58 tmp
lrwxrwxrwx 1 deploy deploy 39 Oct 27 13:58 log -> /opt/www/absence-
registrator/shared/log
-rw-rw-r-- 1 deploy deploy 41 Oct 27 13:58 REVISION
Root cause
root
ownerdeploy
user to deploy the app, it doesn't have permission to delete files with owner is root
Solution
Since you turned your node_modules
to be shared directory, you don't need to fix npm issue with sudo. You can simply change owner of releases
folder recursively to deploy:deploy
. The purpose is making old releases can be deleted successfully. The command will be
sudo chown -R deploy:deploy /opt/www/absence-registrator/releases
It seems you have a problem with permissions that npm
sets for node_modules
. You can check the official documentation for troubleshooting the issue
Try to issue permissions on the dir on your server under your deployer user
sudo chown -R $USER /opt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With