首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ubuntu从systemd启动服务

使用ubuntu从systemd启动服务
EN

Ask Ubuntu用户
提问于 2022-06-04 00:28:19
回答 1查看 633关注 0票数 0

我试图通过systemd启动一个.jar文件(SpringBoot1.4.0),它返回错误退出代码126

系统文件夹中的代码

代码语言:javascript
复制
/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。

代码语言:javascript
复制
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

代码语言:javascript
复制
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'.
EN

回答 1

Ask Ubuntu用户

发布于 2022-06-04 18:56:47

您无法在sudo单元中安全地使用SystemD。这是在日志中出现“无法运行二进制文件”错误的原因之一。

与在服务文件定义中使用sudo不同,您需要定义要运行服务的UserGroup,以便使其与超级用户特权一起执行。

User=rootGroup=root添加到您的服务部分。从sudo行中删除ExecStart。保存文件,然后运行sudo systemctl daemon-reload以刷新SystemD所知道的服务文件数据。

那就开始你的服务。

票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1412198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档