我正在尝试部署Rails 5.1应用。我已经多次部署应用程序没有问题,但现在,我突然从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
user@myapp.com: 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
Capistrano用于删除旧版本的部署用户似乎没有足够的权限来删除node_modules
我尝试通过将node_modules设置为链接目录来解决此问题:
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets node_modules}
但这也没有解决它。
有人知道如何解决这个问题吗?
感谢您的帮助,
安东尼
ps:这是当前目录中ls -lt命令的输出:
-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
答案 0 :(得分:4)
根本原因
root
所有者deploy
用户来部署应用,因此它无权删除所有者为root
<强>解决方案强>
由于您将node_modules
变为共享目录,因此无需使用sudo修复npm问题。您只需将releases
文件夹的所有者递归更改为deploy:deploy
即可。目的是使旧版本可以成功删除。命令将是
sudo chown -R deploy:deploy /opt/www/absence-registrator/releases
答案 1 :(得分:1)
npm
为node_modules
设置的权限似乎存在问题。您可以查看official documentation以解决问题
答案 2 :(得分:1)
尝试在部署者用户
下发布服务器上目录的权限sudo chown -R $USER /opt