Here's how to deploy a spring boot application and install it as a service:
Preparation
- Package your application as a jar file, name it myapp.jar
- Install the JDK that suits your needs on the server
- Upload the jar file to your server, put it in /var/myapp directory
- Set it as executable by running this command: chmod +x myapp.jar
-
Create a script named myapp.service and place it in
/etc/systemd/system directory, the script contains something like
this
[Unit]
Description=myapp
After=syslog.target network.target
[Service]
ExecStart=/path/to/java/home/bin/java -jar /var/myapp/myapp.jar
ExecStop=/bin/kill -15 $MAINPID
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
- Flag the application to start automatically on system boot, run the following command: systemctl enable myapp.service
If your application fails to start, check the log file written to /var/log/<appname>.log for errors.