シェルから正確なExecStart
コマンドを実行できますが、それは機能しますが、このサービスファイルでは何らかの理由で機能しません。
エラー:
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ファイル:
[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。
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
セクションでした。これらも絶対的なものである必要があります。
最終版:
[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