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