Commit e9ec2280 authored by shaw's avatar shaw
Browse files

fix: 修复 sudo 在非交互模式下无法执行的问题

问题原因:
- sudo 命令没有 -n 选项
- 在后台服务中,sudo 会尝试从终端读取密码
- 由于没有终端,命令静默失败

修复内容:
- 添加 sudo -n 选项强制非交互模式
- 如果需要密码会立即失败并返回错误,而不是挂起
parent bb7bfb69
......@@ -32,7 +32,8 @@ func RestartService() error {
// The sub2api user has NOPASSWD sudo access for systemctl commands
// (configured by install.sh in /etc/sudoers.d/sub2api).
cmd := exec.Command("sudo", "systemctl", "restart", serviceName)
// Use -n (non-interactive) to prevent sudo from waiting for password input
cmd := exec.Command("sudo", "-n", "systemctl", "restart", serviceName)
if err := cmd.Start(); err != nil {
return fmt.Errorf("failed to initiate service restart: %w", err)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment