我试图通过systemd启动一个.jar文件(SpringBoot1.4.0),它返回错误退出代码126
系统文件夹中的代码
/etc/systemd/system/Painel.service
[Unit] Description=Iniciar painel After=syslog.target
[Service] User=lrv ExecStart=/bin/bash sudo java -jar /home/lrv/painelWeb-20.0.1-SNAPSHOT.jar $
SuccessExitStatus=143 TimeoutStopSec=10 Restart=on-failure RestartSec=5
[Install] WantedBy=multi-user.target在显示error exite代码127之前,我对命令做了一些更改,现在它出现了错误126,我所做的主要修改是在$PATH中,我添加了Java。
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/bin/java:/usr/bin/javac:/home/lrv/bin:/usr/lib/jvm/jdk1.8.0/bin根据我所看到的错误126,它识别命令,但它的执行与127个甚至不识别它的命令没有区别,这就是为什么在ExecStart中我添加了sudo
我还使用sudo chmod +x和文件(jar文件)给了脚本权限,我想从Ubuntu开始
日志日志-u Painel.service -l -n 50
Painel.service: Failed with result 'exit-code'.
Painel.service: Service hold-off time over, scheduling restart.
Painel.service: Scheduled restart job, restart counter is at 17.
Stopped Iniciar painel.
Started Iniciar painel.
/usr/bin/sudo: /usr/bin/sudo: unable to run the binary file
Painel.service: Main process exited, code=exited, status=126/n/a
Painel.service: Failed with result 'exit-code'.
Painel.service: Service hold-off time over, scheduling restart.
Painel.service: Scheduled restart job, restart counter is at 18.
Stopped Iniciar painel.
Started Iniciar painel.
/usr/bin/sudo: /usr/bin/sudo: unable to run the binary file
Painel.service: Main process exited, code=exited, status=126/n/a
Painel.service: Failed with result 'exit-code'.
Painel.service: Service hold-off time over, scheduling restart.
Painel.service: Scheduled restart job, restart counter is at 19.
Stopped Iniciar painel.
Started Iniciar painel.
/usr/bin/sudo: /usr/bin/sudo: unable to run the binary file
Painel.service: Main process exited, code=exited, status=126/n/a
Painel.service: Failed with result 'exit-code'.
Painel.service: Service hold-off time over, scheduling restart.
Painel.service: Scheduled restart job, restart counter is at 20.
Stopped Iniciar painel.
Started Iniciar painel.
/usr/bin/sudo: /usr/bin/sudo: unable to run the binary file
Painel.service: Main process exited, code=exited, status=126/n/a
Painel.service: Failed with result 'exit-code'.
Painel.service: Service hold-off time over, scheduling restart.
Painel.service: Scheduled restart job, restart counter is at 21.
Stopped Iniciar painel.
Started Iniciar painel.
/usr/bin/sudo: /usr/bin/sudo: unable to run the binary file
Painel.service: Main process exited, code=exited, status=126/n/a
Painel.service: Failed with result 'exit-code'.发布于 2022-06-04 18:56:47
您无法在sudo单元中安全地使用SystemD。这是在日志中出现“无法运行二进制文件”错误的原因之一。
与在服务文件定义中使用sudo不同,您需要定义要运行服务的User和Group,以便使其与超级用户特权一起执行。
将User=root和Group=root添加到您的服务部分。从sudo行中删除ExecStart。保存文件,然后运行sudo systemctl daemon-reload以刷新SystemD所知道的服务文件数据。
那就开始你的服务。
https://askubuntu.com/questions/1412198
复制相似问题