General steps for deploying a spring boot project on a cloud server and running it continuously in the background. To select a server first, you need a cloud server that supports java, such as Jtti's Singapore cloud Server. The operating system can be Linux, Ubuntu or CentOS. The JavaScript environment needs to be installed on the cloud server. JDK 8 or later is recommended:
sudo apt update
sudo apt install openjdk-11-jdk
After installation, run the java version and javac version commands to check the JavaScript version.
Upload the required spring boot project to the jar package on the server. This can be done with the scp command:
scp your-app.jar username@your-server-ip:/path/to/destination
To run the spring boot project:
java -jar your-app.jar
To ensure the operation of the project, nohup is required:
nohup java -jar your-app.jar > app.log 2>&1 &
The output can be redirected to the app.log file and run continuously in the background without breaking the terminal link. You can choose the system management tool to manage the project, first create the systemdfw file:
[Unit]
Description=Your Spring Boot Application
After=network.target
[Service]
User=your-username
ExecStart=/usr/bin/java -jar /path/to/your-app.jar
SuccessExitStatus=143
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target Reload the systemd configuration startup service:
sudo systemctl daemon-reload
sudo systemctl start your-app
To set self-start:
sudo systemctl enable your-app
Query service status:
sudo systemctl status your-app
Install the supervisor
sudo apt install supervisor
Create supervisor
The configuration file of:
[program:your-app]
command=/usr/bin/java -jar /path/to/your-app.jar
directory=/path/to/your-app
autostart=true
autorestart=true
stderr_logfile=/var/log/your-app.err.log
stdout_logfile=/var/log/your-app.out.log
user=your-username
Update and configure self-start:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start your-app
Configure firewalls and ports, such as applications running on 8080:
sudo ufw allow 8080/tcp