How to effectively manage the PIDs of multiple AnQiCMS instances?

Calendar 👁️ 66

As a professional who has been deeply engaged in website operations and has extensively applied AnQiCMS (AnQiCMS), I fully understand the importance of efficiently managing multiple content platforms in an increasingly complex network environment.How to effectively manage the process identifier (PID) of each instance when the business develops to the point where it needs to operate multiple independent sites simultaneously, or to deploy multiple AnQiCMS instances for performance, isolation, and other needs, has become a key factor in ensuring the stable operation and maintenance efficiency of the system.

AnQi CMS, with its high concurrency features of Go language and simple architecture, makes deployment and operation relatively lightweight and efficient.However, unlike the PHP applications in the traditional LAMP/LNMP stack that depend on the web server process, AnQiCMS is an independent Go application that listens on a port and handles requests by itself.This means that each independent AnQiCMS instance will run as a separate Go process on the server, with its own unique PID.anqicmsWhen a process is running, it becomes very difficult to identify and operate on a specific instance just by its default process name.

Understanding the scenarios and challenges of multi-instance deployment.

Before delving into PID management, we need to differentiate between two common multi-site operation models.One is to use the built-in "Multi-site Management" feature of AnQiCMS, which allows you to manage multiple domain sites within a single AnQiCMS application (i.e., a Go process).In this mode, all sites share the same AnQiCMS process, the same port, and distinguish content through domain mapping and site root directory configured in the background.For such a scenario, you do not need to worry about managing the PIDs of multiple AnQiCMS processes, as there is only one main process.

Another situation, which is the focus of our discussion in this article, is deploymentMultiple independent AnQiCMS application instancesThis is usually due to the following considerations:

  • Resource isolation:Each instance can be independently configured with resource limits to avoid one site's high load affecting other sites.
  • Data isolation: Each instance has its own database and file storage, ensuring data security and non-interference.
  • Version control: Different instances can run different versions of AnQiCMS, convenient for testing or gradual upgrades.
  • Team collaboration:Different operation teams can independently manage their own AnQiCMS instances without affecting each other.

In this mode, each AnQiCMS instance will be an independent process on the server, and they may be referred to as by defaultanqicms. If not distinguished, when you try to stop, restart, or monitor a specific instance, you may mistakenly operate on other instances, leading to unnecessary downtime or confusion.

Core strategy: Differentiate processes through unique naming

The key to solving this challenge lies in assigning a unique name to each AnQiCMS instance'sAssign a unique name to the executable fileAdjust the start and stop scripts accordingly.

Firstly, prepare a complete AnQiCMS package for each AnQiCMS instance that needs to run independently. You can place it in different directories on the server (such as/www/wwwroot/site1_anqicms/and/www/wwwroot/site2_anqicms/Place these packages.

Next, perform the following critical steps for each instance:

Configure independent runtime ports

Each AnQiCMS instance needs to listen on a dedicated port. Enter the program directory of each instance, findconfig.jsonthe file. Edit this file, and setportField modified to a different port number. For example, the first instance uses8001, the second uses8002This step is the foundation, ensuring that each instance can start independently without port conflicts.

Assign a unique name to the AnQiCMS executable file.

This is the core of PID management. In each independent AnQiCMS package directory, the defaultanqicmsRename the executable file to a name with high recognition. For example, if an instance is used for a blog, you can rename its executable file toanqicms_blogIf another one is used for e-commerce, rename it toanqicms_shop. After renaming, each running instance will have a unique name in the system process list, which is the premise for subsequent precise process management.

Adjust the start and stop scripts

AnQiCMS providedstart.shandstop.shscripts to assist in process management. You need to create a set of corresponding scripts for each renamed AnQiCMS instance and modify theBINNAMEvariables andgrepCommand, to point to the unique executable file name you have just assigned.

Start withstart.shFor example, assume you have renamed the executable file toanqicms_blogand the program path is/www/wwwroot/blog_anqicms:

#!/bin/bash
BINNAME=anqicms_blog # 修改为新的可执行文件名
BINPATH=/www/wwwroot/blog_anqicms # 修改为该实例的实际路径

exists=`ps -ef | grep '\<'$BINNAME'\>' |grep -v grep |wc -l`
echo "$(date +'%Y%m%d %H:%M:%S') $BINNAME PID check: $exists" >> $BINPATH/check.log
echo "PID $BINNAME check: $exists"
if [ $exists -eq 0 ]; then
    echo "$BINNAME NOT running"
    cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &
fi

the correspondingstop.shThe script also needs to be modified similarly:

#!/bin/bash
BINNAME=anqicms_blog # 修改为新的可执行文件名
BINPATH="$( cd "$( dirname "$0"  )" && pwd  )" # 此处可以保持不变,或根据实际情况调整

exists=`ps -ef | grep '\<'$BINNAME'\>' |grep -v grep |awk '{printf $2}'`
echo "$(date +'%Y%m%d %H:%M:%S') $BINNAME PID check: $exists" >> $BINPATH/check.log
echo "PID $BINNAME check: $exists"
if [ $exists -eq 0 ]; then
    echo "$BINNAME NOT running"
else
    echo "$BINNAME is running"
    kill -9 $exists
    echo "$BINNAME is stop"
fi

You also need to configure each instance in the task scheduler (such ascrontab) or service manager (such assystemdConfigure the corresponding start/stop tasks within it, ensuring they can run and manage independently and stably.

Configure reverse proxy to map domain names.

Finally, each independent AnQiCMS instance needs to be reverse proxied through a web server (such as Nginx or Apache) to listen on its private port (such as8001/8002Mapped to a publicly accessible domain (such asblog.example.com/shop.example.com). When users visit the domain, the request will be forwarded to the corresponding AnQiCMS instance by the web server.

Operations practice and process monitoring

After completing the above configuration, you will be able to monitor and manage each AnQiCMS instance more clearly.

Useps -efCommand cooperationgrepYou can easily find the PID of a specific instance:

ps -ef | grep anqicms_blog

This will only display withanqicms_bloginformation related to processes, where the second column is the PID of the process.

You can also uselsof -i:{端口号}Command to verify whether a specific port is occupied by the correct AnQiCMS instance:

lsof -i:8001

This will display the occupancy8001Process information of the port, to confirm whether it is youranqicms_bloginstance.

It is strongly recommended to use for production environmentssystemdProfessional service managers to manage these AnQiCMS instances. By creating an independent.serviceA file, you can define the startup command, environment variables, restart policy, log output, and so on for each instance to realize more robust and automated process management.

Summary

By assigning a unique name to each independent AnQiCMS executable file and coordinating with the corresponding startup script and reverse proxy configuration, we can effectively manage the PIDs of multiple AnQiCMS instances on the same server.This strategy not only brings clear process isolation and convenient independent management, but also lays a solid foundation for the scalability and stability of website operations.As a website operator, mastering these refined management skills will undoubtedly greatly improve our work efficiency and ability to deal with complex scenarios.


Frequently Asked Questions

**An

Related articles

If `start.sh` shows that AnQiCMS is running but the website is inaccessible, how should I troubleshoot?

As an experienced CMS website operation person, I know the anxiety and unease when the system runs on the surface but the website cannot be accessed.This usually means there is a break between backend services and frontend access.In the case where `start.sh` shows that AnQiCMS is running but the website cannot be accessed, we need to investigate systematically.This is not just checking the service itself, but also needs to review the server environment, network configuration, and the core settings of AnQiCMS.

2025-11-06

What are the key information about PID recorded in AnQiCMS's `check.log` file?

As an experienced CMS website operation personnel of an enterprise, I am well aware of the importance of system log files in maintaining the stable operation of the website.In the daily operation and maintenance of AnQiCMS, the `check.log` file plays an indispensable role. It records detailed information about the core process (PID) of the application, providing valuable clues for us to understand the system status and carry out fault troubleshooting.

2025-11-06

What are the potential risks and alternatives for `kill -9 $exists` in the AnQiCMS shutdown script?

As a professional who deeply understands the operation of AnQiCMS, I know that the stability of the content system and data security are the foundation of website operation.In the daily operation and maintenance of AnQiCMS, we often encounter scripts for starting and stopping services.Among them, the command `kill -9 $exists` can quickly terminate the process when stopping the AnQiCMS service, but its potential risks should not be overlooked.Understanding these risks and adopting appropriate alternatives is crucial for ensuring the robust operation of the website.

2025-11-06

How does the startup script ensure that AnQiCMS automatically restarts after an unexpected stop?

AnQiCMS is a modern content management system developed based on the Go language, and its stability and high availability are the core guarantees for website operation.In the operation of a website, the background service process may unexpectedly stop due to various unpredictable reasons, such as exhaustion of system resources, program errors, and external attacks.

2025-11-06

When AnQiCMS process fails to start, where should I begin checking for PID-related errors?

When AnQiCMS process fails to start, where should I begin checking for PID-related errors?When operating the AnQiCMS website, the program cannot start normally, which is a common but annoying problem.After we have ruled out basic server connection, file integrity, or database configuration issues, errors related to process ID (PID) are often the hidden causes of AnQiCMS startup failure.

2025-11-06

What is the role of `nohup` and `&` in the background running of the process in the AnQiCMS startup script?

As a website operator who has been deeply involved in the CMS of security enterprises for many years, I am well aware of the importance of every detail for the stable operation of the website, especially on the server side, process management is of great importance.Today, let's delve into the crucial roles played by the seemingly simple symbols `nohup` and `&` in the startup script of AnQiCMS, and how they ensure our website remains continuously online.###

2025-11-06

How to verify that the `grep '\u003canqicms>'` in the `AnQiCMS` startup script can accurately match the process name?

As an experienced senior person proficient in Anqing CMS operation, I am well aware of the importance of system stability and the rigor of process management for the continuous operation of the website.Each line of command in the startup script carries the responsibility of ensuring the health of the service, especially the critical instructions for process detection.Next, I will elaborate on how to verify the accuracy of the `grep '<anqicms>'` command in the `AnQiCMS` startup script, ensuring that it can accurately match the running process of AnQiCMS.### Understanding the Core Mechanism of Process Detection In the Linux Environment

2025-11-06

When AnQiCMS default port is occupied, how to find and terminate the conflicting process through PID?

HelloAs a senior security CMS website operator, I fully understand the difficulties encountered in the operation when technical problems arise, especially when it affects the normal operation of the website.Port occupancy is one of the common but relatively easy problems to solve.When the default running port of AnQi CMS is occupied by other programs, the system will fail to start normally.Below, I will explain in detail how to locate and terminate these conflicting processes to ensure your safe CMS website goes live.

2025-11-06