Deploy spring boot application in production environment on RHEL 7/8?
Feb 8, 2021
- Create a directory and copy the springboot web application executable jar to it
# mkdir /var/myapp
# cp /Downloads/Demoapp-0.0.1-SNAPSHOT.jar /var/myapp/
2. Create the user who will own and run the web application
# useradd myapp
# passwd myapp
# chown myapp:myapp /var/myapp/Demoapp-0.0.1-SNAPSHOT.jar
# chmod 500 /var/myapp/Demoapp-0.0.1-SNAPSHOT.jar
3. Make the application immutable
# chattr +i /var/myapp/Demoapp-0.0.1-SNAPSHOT.jar
4. Create a systemd service to autostart application on reboot
# vim /etc/systemd/system/myapp.service
[Unit]
Description=myapp
After=syslog.target
[Service]
user=myapp
ExecStart=/var/myapp/Demoapp-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
5. Enable auto-start of the application.
# systemctl enable myapp.service
# systemctl start myapp.service
# systemctl status myapp.service