简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM