本文介绍了systemd错误“无法启动服务:单元服务未正确加载:exec格式错误"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以从 shell 执行确切的 ExecStart
命令并且它可以工作,但是由于某种原因在这个服务文件中这不起作用 - 有什么想法吗?
I can execute the exact ExecStart
command from the shell and it works, but for some reason in this service file this doesnt work-- any ideas?
错误:
Failed to start previewapi.service: Unit previewapi.service is not loaded properly: Exec format error.
See system logs and 'systemctl status previewapi.service' for details.
systemd .service 文件:
systemd .service file:
[Unit]
Description = preview-api
After = network.target
[Service]
WorkingDirectory=/srv/previewapi
ExecStart = /usr/bin/java -jar /srv/previewapi/gn-preview-api-0.1.0-SNAPSHOT-standalone.jar
ExecStop = kill -INT $MAINPID
ExecReload = kill -TERM $MAINPID
# In case if it gets stopped, restart it immediately
Restart = always
Type = simple
[Install]
# multi-user.target corresponds to run level 3
# roughtly meaning wanted by system start
WantedBy = multi-user.target
Ubuntu 18.04.
Ubuntu 18.04.
sudo journalctl -u previewapi
说:
Aug 15 10:00:28 ubuntu-bionic systemd[1]: /etc/systemd/system/previewapi.service:18: Executable path is not absolute:
推荐答案
问题不在于 ExecStart
,而在于 ExecStop
和 ExecReload部分——它们也需要是绝对的.
The problem wasn't the
ExecStart
, it was the ExecStop
and ExecReload
sections-- they need to be absolute as well.
最终版本:
[Unit]
Description = preview-api
After = network.target
[Service]
WorkingDirectory=/srv/previewapi
ExecStart=/usr/bin/java -jar /srv/previewapi/gn-preview-api-0.1.0-SNAPSHOT-standalone.jar
ExecStop=/bin/kill -INT $MAINPID
ExecReload=/bin/kill -TERM $MAINPID
# In case if it gets stopped, restart it immediately
Restart = always
Type = simple
[Install]
# multi-user.target corresponds to run level 3
# roughtly meaning wanted by system start
WantedBy = multi-user.target
这篇关于systemd错误“无法启动服务:单元服务未正确加载:exec格式错误"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!