Deploy a Spring boot application
- Spring boot application can be deployed in two ways
- as an application
- as a service
- Download Jar file Refer Here
- As an applicaton
- Install openjdk 17
sudo apt install openjdk-17-jdk - run the application
java -jar spring-petclinic-3.3.0-SNAPSHOT.jar - This application will be hosted on port 8080
- Install openjdk 17
-
As a service:
- Refer Here for an article to run spring boot as a service
- Lets create a user
spcwith homedirectory as/var/lib/spc=>sudo useradd -d '/var/lib/spc' -m -s '/bin/sh' spc - Download the jar file into
/var/lib/spc=>sudo wget -P /var/lib/spc/ https://referenceappslt.s3.ap-south-1.amazonaws.com/spring-petclinic-3.3.0-SNAPSHOT.jar - change ownership
sudo chown spc:spc spring-petclinic-3.3.0-SNAPSHOT.jar - Now create a service file in the following location
/usr/lib/systemd/system/spc.service
“`
[Unit]
Description=A Spring Boot application
After=syslog.target
[Service]
User=spc
ExecStart=/usr/bin/java -jar /var/lib/spc/spring-petclinic-3.3.0-SNAPSHOT.jar SuccessExitStatus=143[Install]
WantedBy=multi-user.target
``sudo systemctl daemon-reload`
* Relaod the daemon
* Enable and start the spc service
Ansible Playbook for deploying spring petclinic
- Ubuntu: Initially lets focus on running this playbook on ubuntu
- Refer Here for the playbook written in the class to automate the deployment of spring petclinic
