fix: 修复 sudoers 中 systemctl 路径不兼容的问题

问题原因:
- sudoers 只配置了 /bin/systemctl 路径
- 部分系统(如 Ubuntu 22.04+)的 systemctl 位于 /usr/bin/systemctl
- 路径不匹配导致 sudo 仍然需要密码

修复内容:
- 同时支持 /bin/systemctl 和 /usr/bin/systemctl 两个路径
- 兼容 Debian/Ubuntu 和 RHEL/CentOS 等不同发行版
This commit is contained in:
shaw
2025-12-18 19:17:05 +08:00
parent 4eb22d8ee9
commit b51ad0d893
2 changed files with 8 additions and 0 deletions

View File

@@ -530,11 +530,15 @@ setup_sudoers() {
cp "$INSTALL_DIR/sub2api-sudoers" /etc/sudoers.d/sub2api
else
# Create sudoers file
# Support both /bin/systemctl and /usr/bin/systemctl for different distros
cat > /etc/sudoers.d/sub2api << 'EOF'
# Sudoers configuration for Sub2API
sub2api ALL=(ALL) NOPASSWD: /bin/systemctl restart sub2api
sub2api ALL=(ALL) NOPASSWD: /bin/systemctl stop sub2api
sub2api ALL=(ALL) NOPASSWD: /bin/systemctl start sub2api
sub2api ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart sub2api
sub2api ALL=(ALL) NOPASSWD: /usr/bin/systemctl stop sub2api
sub2api ALL=(ALL) NOPASSWD: /usr/bin/systemctl start sub2api
EOF
fi