kev
kev

Reputation: 1190

Cannot start systemd service

I have a spring boot executable jar in a digital ocean droplet. I'm able to execute the jar using java -jar myapp.jar Now I want to have i run as a service.

I've created the file /etc/systemd/system/myapp.service with these contents

[Unit]
Description=myapp
After=syslog.target

[Service]
User=kevin
ExecStart=/var/myapp/myapp-backend-1.0-SNAPSHOT.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

Then enabled it to start at system startup

systemctl enable myapp.service

I'm now attempting to start the service

systemctl start myapp.service

But I'm getting this error

Failed to start myapp.service: Unknown unit: myapp.service See system logs and 'systemctl status myapp.service' for details.

running systemctl status myapp.service return this:

Failed to get properties: No such interface ''

Upvotes: 4

Views: 11697

Answers (2)

Alban VIDAL
Alban VIDAL

Reputation: 126

Try this :

[Unit]
Description=myapp
After=syslog.target

[Service]
User=kevin
ExecStart=java -jar /var/myapp/myapp-backend-1.0-SNAPSHOT.jar
SuccessExitStatus=143
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

I have add :

java -jar in youre ExecStart

Restart=always => If java crack, systemd restart the service

RestartSec=5 => After crash the service restart avec 5 seconds

After youre modification, reload the systemd daemon :

systemctl daemon-reload

Enable on startup :

systemctl enable myapp.service

And start now :

systemctl start myapp.service

Upvotes: 3

Shem
Shem

Reputation: 565

You need a wrapper script for the jar mentioned in ExecStart to handle start, stop and restart methods.

Extensive instructions and an example script can be found here

Upvotes: 0

Related Questions