centos npm错误代码EACCES 243.是什么原因导致npm缓存中得某些目录在创建时没有设置执行标志?

b91juud3  于 2022-11-07  发布在  其他
关注(0)|答案(1)|浏览(119)

在TeamCity代理(centos 7)上运行构建时,任何与teamcity用户一起运行的npm命令(7.24.2版)都会生成以下错误:

[Step 2/25] npm cache clear --force
[npm cache clear --force] npm WARN using --force Recommended protections disabled.
[npm cache clear --force] npm ERR! code EACCES
[npm cache clear --force] npm ERR! syscall unlink
[npm cache clear --force] npm ERR! path /data/teamcity-agent/npm-cache/_cacache/index-v5/34/70188cc2e95f746adf32e21191fb2cad2a56f8c7c78dcf4a0d1587143321
[npm cache clear --force] npm ERR! errno -13
[npm cache clear --force] npm ERR!
[npm cache clear --force] npm ERR! Your cache folder contains root-owned files, due to a bug in
[npm cache clear --force] npm ERR! previous versions of npm which has since been addressed.
[npm cache clear --force] npm ERR!
[npm cache clear --force] npm ERR! To permanently fix this problem, please run:
[npm cache clear --force] npm ERR!   sudo chown -R 2158:993 "/data/teamcity-agent/npm-cache"
[npm cache clear --force]
[npm cache clear --force] npm ERR! A complete log of this run can be found in:
[npm cache clear --force] npm ERR!     /data/teamcity-agent/npm-cache/_logs/2022-05-03T10_51_17_066Z-debug.log
[Step 2/25] Process exited with code 243
[Step 2/25] Process exited with code 243
[Step 2/25] Step npm cache clear (Node.js NPM) failed

但是当我们深入研究这个错误时,并不是说用户teamcity没有拥有npm缓存中的所有文件,而是所有文件都由正确的用户拥有,而是有些目录没有设置execute位。例如:

> cd /data/teamcity-agent/npm-cache
> ls -alR | grep drw-
drw-------.   2 teamcity teamcity  138 Apr 29 01:52 34
drw-------.   2 teamcity teamcity  138 Apr 29 09:54 cc

您可以看到,该高速缓存中的数百个其他目录中,有两个目录只设置了所有者的读写位,其他所有目录都是这样的:

> cd /data/teamcity-agent/npm-cache/_cacache/content-v2/sha512
> ls -al
drwxr-xr-x. 257 teamcity teamcity 8192 Apr 28 12:10 .
drwxr-xr-x.   4 teamcity teamcity   32 Apr 28 12:10 ..
drwxr-xr-x.   7 teamcity teamcity   56 Apr 29 01:52 00
drwxr-xr-x.  11 teamcity teamcity   96 Apr 28 12:10 01
.....

如果没有在目录上设置所有者执行标志,那么teamcity代理就不能修改目录的内容,因此所有的npm命令都会失败。

> chmod -R +755 /data/teamcity-agent/npm-cache

但是过了一段时间,问题又回到了npm缓存的不同区域。这就引出了下面的实际问题:
是什么原因导致npm缓存中的某些目录在创建时没有设置执行标志?
我已经检查过代理上只安装了一个版本的npm。顺便说一句,TeamCity代理运行在Centos 7(CentOS Linux版本7. 9. 2009(核心))上

yiytaume

yiytaume1#

我们从来没有弄清楚是什么导致了这个问题,但我们已经实施了修复,阻止了它的发生。
最后,我们通过/usr/etc/npmrc中的文件将npm缓存从/data/teamcity-agent/npm-cache移动到/tmp/teamcity-agent/npm-cache,该文件现在被设置为:

$ cat /usr/etc/npmrc
registry=https://npm-private-registry.aaa.bbb/
always-auth=true
_auth="................"
email=aaa@bbb.ccc
cache=/tmp/teamcity-agent/npm-cache

当你列出npm配置时,它看起来像这样:

$ npm config list
; "global" config from /usr/etc/npmrc

_auth = (protected)
always-auth = true
cache = "/tmp/teamcity-agent/npm-cache"
; email = "aaa@bbb.ccc" ; overridden by user
registry = "https://npm-private-registry.aaa.bbb/"

; "user" config from /home/centos/.npmrc
...
...

这两个位置之间的唯一区别是/data/teamcity-agent归teamcity用户所有,而/tmp/teamcity-agent归root用户所有。

相关问题