Systemctl 服务看不到 sudo 文件

Systemctl 服务看不到 sudo 文件

我的问题 - 我需要 systemctl 服务使用 sudo,但我不知道为什么,它没有看到 sudo 文件 我做错了什么?

Description=Just_Work_Pls
After=network.target

[Service]
EnvironmentFile=/etc/environment
ExecStart=/home/Butter_Manager/sudo /home/Butter_Manager/env/bin/python3.8 manager.py
ExecReload=/home/Butter_Manager/sudo /home/Butter_Manager/env/bin/python3.8 manager.py
WorkingDirectory=/home/Butter_Manager/
KillMode=process
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

在状态中我看到这个:

  Loaded: loaded (/lib/systemd/system/Butter_Manager.service; enabled; vendor preset: enabled)
  Active: activating (auto-restart) (Result: exit-code) since Sat 2021-08-28 18:30:51 UTC; 149ms ago
 Process: 6518 ExecStart=/home/Butter_Manager/sudo /home/Butter_Manager/env/bin/python3.8 manager.py (code=exited, status=203/EXEC)
Main PID: 6518 (code=exited, status=203/EXEC)

Aug 28 18:30:51 Butter-Manager systemd[1]: Stopped Just_Work_Pls.
Aug 28 18:30:51 Butter-Manager systemd[1]: Started Just_Work_Pls.
Aug 28 18:30:51 Butter-Manager systemd[1]: Butter_Manager.service: Main process exited, code=exited, status=203/EXEC
Aug 28 18:30:51 Butter-Manager systemd[1]: Butter_Manager.service: Failed with result 'exit-code'.

在日志中我看到这个:

Aug 28 18:31:22 Butter-Manager systemd[6623]: Butter_Manager.service: Failed at step EXEC spawning /home/Butter_Manager/sudo: No such file or directory
Aug 28 18:31:22 Butter-Manager systemd[1]: Butter_Manager.service: Main process exited, code=exited, status=203/EXEC
Aug 28 18:31:22 Butter-Manager systemd[1]: Butter_Manager.service: Failed with result 'exit-code'.
Aug 28 18:31:28 Butter-Manager systemd[1]: Butter_Manager.service: Service hold-off time over, scheduling restart.
Aug 28 18:31:28 Butter-Manager systemd[1]: Butter_Manager.service: Scheduled restart job, restart counter is at 575.
Aug 28 18:31:28 Butter-Manager systemd[1]: Stopped Just_Work_Pls.
Aug 28 18:31:28 Butter-Manager systemd[1]: Started Just_Work_Pls.
Aug 28 18:31:28 Butter-Manager systemd[6644]: Butter_Manager.service: Failed to execute command: No such file or directory
Aug 28 18:31:28 Butter-Manager systemd[6644]: Butter_Manager.service: Failed at step EXEC spawning /home/Butter_Manager/sudo: No such file or directory
Aug 28 18:31:28 Butter-Manager systemd[1]: Butter_Manager.service: Main process exited, code=exited, status=203/EXEC
Aug 28 18:31:28 Butter-Manager systemd[1]: Butter_Manager.service: Failed with result 'exit-code'.
Aug 28 18:31:33 Butter-Manager systemd[1]: Butter_Manager.service: Service hold-off time over, scheduling restart.
Aug 28 18:31:33 Butter-Manager systemd[1]: Butter_Manager.service: Scheduled restart job, restart counter is at 576.
Aug 28 18:31:33 Butter-Manager systemd[1]: Stopped Just_Work_Pls.
Aug 28 18:31:33 Butter-Manager systemd[1]: Started Just_Work_Pls.
Aug 28 18:31:33 Butter-Manager systemd[6657]: Butter_Manager.service: Failed to execute command: No such file or directory
Aug 28 18:31:33 Butter-Manager systemd[6657]: Butter_Manager.service: Failed at step EXEC spawning /home/Butter_Manager/sudo: No such file or directory
Aug 28 18:31:33 Butter-Manager systemd[1]: Butter_Manager.service: Main process exited, code=exited, status=203/EXEC
Aug 28 18:31:33 Butter-Manager systemd[1]: Butter_Manager.service: Failed with result 'exit-code'.
Aug 28 18:31:33 Butter-Manager systemd[1]: Stopped Just_Work_Pls.

两天了毫无进展,我不知道该怎么办...

答案1

在这种情况下,您实际上根本不需要 sudo,因为您的服务是系统范围的服务(位于 /lib/systemd/system 中),因此默认情况下它将以 root 身份运行。您只需/home/Butter_Manager/sudo从服务文件中删除零件即可。

以下是您的服务失败的原因:

/home/Butter_Manager/sudo: No such file or directory

这个意思/home/Butter_Manager/sudo是不存在的。最有可能的sudo/usr/bin/sudo/bin/sudo。您可以通过运行找到它的路径which sudo。运行realpath sudo将简单地返回您当前的工作目录 + sudo(请参阅man realpath)。我思考你的命令的第二部分也有这个问题。我思考你的意思是/bin/env /bin/python3.8而不是/home/Butter_Manager/env/bin/python3.8

相关内容