Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

systemd error "failed to start service: unit service is not loaded properly: exec format error"

Tags:

ubuntu

systemd

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?

error:

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 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.

sudo journalctl -u previewapi says:

Aug 15 10:00:28 ubuntu-bionic systemd[1]: /etc/systemd/system/previewapi.service:18: Executable path is not absolute:
like image 363
Micah Avatar asked Aug 15 '18 11:08

Micah


1 Answers

The problem wasn't the ExecStart, it was the ExecStop and ExecReload sections-- they need to be absolute as well.

Final version:

[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
like image 72
Micah Avatar answered Oct 31 '22 22:10

Micah