首页 > 解决方案 > CENTOS 8 / SELinux 的 Pm2 启动问题

问题描述

请问,你知道如何解决这个问题吗?我到处寻找,没有找到。

06:45 SELinux is preventing systemd from open access on the file /root/.pm2/pm2.pid. For complete SELinux messages run: sealert -l d84a5a0b-cfcf-4cb9-918a-c0952bf70600 setroubleshoot

06:45 pm2-root.service: Can't convert PID files /root/.pm2/pm2.pid O_PATH file descriptor to proper file descriptor: Permission denied systemd 2 

06:45 Failed to start PM2 process manager.

我已经执行了这个命令: sealert -l d84a5a0b-cfcf-4cb9-918a-c0952bf70600 setroubleshoot

Messages d'audit bruts 
type=AVC msg=audit(1591498085.184:7731): avc:  denied  { open } for  pid=1 comm="systemd" path="/root/.pm2/pm2.pid" dev="dm-0" ino=51695937 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:admin_home_t:s0 tclass=file permissive=0

PM2 版本:4.4.0 NODE 版本:12.18.0 CentOS 版本:8

我的系统服务:

[Unit]
Description=PM2 process manager
Documentation=https://pm2.keymetrics.io/
After=network.target

[Service]
Type=forking
User=root
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/sbin:/bin:/usr/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/root/.pm2
PIDFile=/root/.pm2/pm2.pid
Restart=on-failure

ExecStart=/usr/lib/node_modules/pm2/bin/pm2 resurrect
ExecReload=/usr/lib/node_modules/pm2/bin/pm2 reload all
ExecStop=/usr/lib/node_modules/pm2/bin/pm2 kill

[Install]
WantedBy=multi-user.target

谢谢

标签: pm2selinuxcentos8

解决方案


正如评论中所说,我遇到了完全相同的问题

要解决此问题,只需在尝试启动 PM2 服务后以 root 身份运行以下命令(在您的情况下,此启动尝试将是systemctl start pm2-root

ausearch -c 'systemd' --raw | audit2allow -M my-systemd
semodule -i my-systemd.pp

这看起来很通用,但它确实有效。这些行是 SELinux 本身提出的。为了得到它们,我必须journalctl -xe在尝试启动服务后运行命令


推荐阅读