3

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 ''
kev
  • 1,148
  • 2
  • 14
  • 29

2 Answers2

3

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
Alban VIDAL
  • 126
  • 5
  • Still getiing this error: Failed to start myapp.service: Unknown unit: myapp.service See system logs and 'systemctl status myapp.service' for details. – kev Dec 06 '16 at 19:42
  • 1
    Can you join the output of "systemctl -xn" after systemctl restart myapp.service ? – Alban VIDAL Dec 07 '16 at 17:49
0

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

Community
  • 1
  • 1
Shem
  • 565
  • 2
  • 10