Reputation: 111
I wrote a Spring Boot RESTful API backend, compiled it to backend.jar
file and ran it on Ubuntu (EC2 of AWS) by command java -jar backend.jar
. It can serve requests well, but it seems that it runs only for a short while and then disappears, so the following requests fail to be served. I can rerun java -jar backend.jar
but it works only for a short while.
How to make the backend.jar
permanent like a service?
(I am new to server administration)
Upvotes: 0
Views: 276
Reputation: 52556
Create a user for your service
$ sudo useradd thangtran
$ sudo passwd thangtran
$ sudo chown thangtran:thangtran backend.jar
$ sudo chmod 500 backend.jar
Solution 1: Use systemd (recommended). In directory /etc/systemd/system
, create file backend.service
has content
[Unit]
Description=A Spring Boot application
After=syslog.target
[Service]
User=thangtran
ExecStart=/path/to/backend.jar SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
See more at https://viblo.asia/p/su-dung-systemd-de-chinh-sua-service-linux-m68Z0PJNZkG
Solution 2: System V init
sudo ln -s /path/to/backend.jar /etc/init.d/your-app
$ sudo service your-app start
Log at /var/log/backend.log
Application's process id tracked at /var/run/backend/backend.pid
Upvotes: 1