Write a script to run this application. (This script will run continuously as long as application is running)
sudo vi my-webapp.sh
#!/bin/bash
java -jar spring-petclinic.jar
To avoid this long running script, make spring-petclinic a linux daemon(service).
sudo vi /etc/systemd/system/springpetclinic.service
[Unit]
Description=My Webapp
[Service]
User=ubuntu
#change this to your workspace
WorkingDirectory=/home/ubuntu
#path to executable.
#executable is a bash script which calls jar file
ExecStart=/bin/bash /home/ubuntu/my-webapp.sh
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
To reload the deamon
“`sudo systemctl daemon-reload“
enable the service for every boot
“`sudo systemctl enable springpetclinic.service“
start the service
sudo systemctl start springpetclinic
check the application is running or not
sudo systemctl status springpetclinic
For centos the create a file /etc/systemd/system/springpetclinic.service
[Unit]
Description=My Webapp
[Service]
User=centos
#The configuration file application.properties should be here:
#change this to your workspace
WorkingDirectory=/home/centos
#path to executable
#executable is a bash script which calls jar file
ExecStart=/bin/bash /home/centos/my-webapp.sh
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target