Spring Boot application as a service in Linux

In this tutorial, How to run Spring Boot Application as a service in Linux. Spring boot preferred deployment method via an executable jar file that contains tomcat inside.

Spring Boot application as a service

Spring Boot and Systemd

Create new file “/etc/systemd/system/myapp.service” as a service to start on reboot.

[Unit]
Description=myapp
After=syslog.target
[Service]
User=myapp
ExecStart=/var/myapp/myapp.jar
SuccessExitStatus=143
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target

Note: You change the Description, User, and ExecStart fields suitable for your application.

Start the service:

$ sudo systemctl start myapp

Check the status is active

$ sudo systemctl status myapp

Spring Boot and System V

Create a specific user to run the service and executable JAR file.

$ cd /opt/myapp
$ sudo useradd huupv
$ sudo passwd huupv
$ sudo chown huupv:huupv myapp.jar
$ sudo chmod 500 myapp.jar

Assuming you have a Spring Boot application installed in the folder /opt/myapp . you need to create a symlink as follows:

$ sudo ln -s /opt/myapp/myapp.jar /etc/init.d/myapp

Start the service

$ sudo service myapp start

You have created the “Spring Boot application as a service in Linux“.Thank you for reading the DevopsRoles page!

, ,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published.

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.