Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Deploying a Spring Boot Application on Tencent Cloud Lighthouse with Persistent Background Execution

Tech Sep 9 1

Provisioning the Cloud Environment

Begin by registering or logging into your Tencent Cloud account. Complete identity verification as required to activate services.

Required Components

  • Cloud Instance: Tencent Cloud Lighthouse running CentOS 7.8 (64-bit)
  • Local Application: A Spring Boot + MyBatis Plus-based news management system
  • Client Tools:
    • Xshell 6 for SSH access
    • Navicat Premium for database export
    • WinSCP for file transfer

Migrating the Local Database

Export the local database using Navicat Premium: right-click the database, select Dump SQL File, and include both structure and data.

On the server, use phpMyAdmin (installed via BT Panel) to import the dump:

  1. Create a new database with the same name as the original.
  2. Use the Import tab to upload and execute the SQL file.
  3. Verify that tables and data are correctly restored.

Adjusting Application Configuration

Edit application.properties to avoid port conflicts. Since the server already runs a standalone Tomcat on port 8080, configure the embedded Tomcat in Spring Boot to use an alternative port:

server.port=9001

Packaging and Uploading the Application

Use Maven to package the project:

mvn clean package

This generates a JAR file in the target/ directory. Create a dedicated directory on the server (e.g., /usr/newsapp) and upload the JAR ussing WinSCP.

Running the Application

Foreground Execution (Not Recommended for Production)

java -jar news-system-0.0.1-SNAPSHOT.jar

This process terminates when the SSH session ends.

Persistent Background Execution

Create a startup script to ensure the application runs independently of the terminal session:

vim /usr/newsapp/start.sh

Insert the following content (press i to enter insert mode):

#!/bin/bash
nohup java -jar /usr/newsapp/news-system-0.0.1-SNAPSHOT.jar > app.log 2>&1 &

Save and exit (Esc, then :wq). Make the script executable:

chmod +x /usr/newsapp/start.sh

Launch the application:

sh /usr/newsapp/start.sh

Verify the process is runing:

ps aux | grep news-system

The application is now accessible via http://<server-public-IP>:9001.

To stop the service, identify the process ID and terminate it:

ps aux | grep news-system
kill <PID>

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.