How to ensure that only the target AnQiCMS process is terminated by the stop script, not other同名 processes?

Calendar 👁️ 53

As an experienced website operator who deeply understands the operation of AnQiCMS, I know the importance of precise control over website services.In routine maintenance, stopping or restarting services is a common operation, but ensuring that only the target process is terminated and not inadvertently harming unrelated or similarly named processes is a challenge that technicians must face.AnQiCMS designed its stop script with full consideration of this requirement, achieving precise identification and termination of specific AnQiCMS processes through the clever use of Linux command-line tools and clear naming conventions.

Stop any running application process, which usually involves finding its process identifier (PID) and then sending a termination signal to the PID.However, in a complex server environment, there may be multiple applications running simultaneously, and some unrelated process names may accidentally contain the string of the target application.In this case, relying solely on fuzzy name matching to find processes may lead to the risk of "killing the wrong process", causing service interruption or data anomalies.

AnQiCMS'stop.shThe script is designed to avoid such risks. The core of the script lies in its combination of usageps/grepandawkUse standard Linux command line tools to accurately locate the target AnQiCMS process. Specifically, the script will execute the following key steps:

Firstly, the script will go throughps -efCommand to list detailed information of all running processes on the system.ps -efProvided a complete list of processes, including process ID (PID), parent process ID (PPID), CPU usage, memory usage, start time, and the complete command path, providing rich data sources for subsequent filtering.

Next, the script willps -efpass the output through a pipeline togrep '\<anqicms\>'command. Here isgrepcommand is the key to accurate recognition. It uses\<and\>These special regular expression metacharacters represent the 'start of a word' and 'end of a word'. This meansgrepIt will strictly match "anqicms" as a standalone word, not as a substring of any process name containing "anqicms". For example, if there is a process namedmyanqicmsapportest_anqicmsThe process of thisgrepcommand will not treat it as a target process, thereby effectively avoiding collateral damage.

To further improve accuracy, the subsequentgrep -v grepoperation is standard practice. Because the previousgrepThe command itself is also a process, and the command line also contains the word 'grep'. If not filtered, it may also include itself in the results.grep -vThe function is to reverse match, that is, to exclude all lines containing 'grep', ensuring that only the actual AnQiCMS process remains in the final result.

Finally, the filtered results are directed toawk '{printf $2}'.ps -efIn the output, the process ID (PID) is usually located in the second column.awkThe tool's function here is to extract this column of data and use it as the unique identifier (PID) for the AnQiCMS process.If the AnQiCMS process is found, its PID will be captured and stored in the script variable.

After obtaining the exact PID, the script performs a simple check: if the PID exists (i.e.exists -ne 0), then it means the AnQiCMS process is running, at this time the script will usekill -9 $PIDSend a forceful termination signal to cleanly shut down the AnQiCMS service.If the PID does not exist, the script will prompt that AnQiCMS is not running, to avoid unnecessary termination attempts.

It is worth mentioning that AnQiCMS also supports deploying multiple independent AnQiCMS instances on the same server (for example, to provide services for different businesses or test environments). In this advanced deployment scenario, in order to ensure that each instance's stop script can accurately control its corresponding process, the official documentation recommends: to replicate a set of code for each independent AnQiCMS instance and its main program file (anqicmsRename the executable file to a unique name (for exampleanqicms_site1/anqicms_devetc.). Accordingly, each instance ofstop.shin the scriptBINNAMEVariables are also modified to point to their specific executable file names. In this way, even if multiple AnQiCMS instances are running on the server, each instance's stop script can also use its uniqueBINNAMEAnd as mentioned beforegrepAn accurate matching mechanism ensures that only the processes it manages are terminated, without affecting the normal operation of other AnQiCMS instances.

In summary, the stop script of AnQiCMS combines the powerful functionality of Linux command line tools, utilizes precise word boundary matching and clear naming conventions to achieve highly accurate identification and termination of target processes, which is crucial for ensuring the stability and security of website services.

Frequently Asked Questions

How does the AnQiCMS shutdown script handle the situation where the AnQiCMS process is not running?

AnQiCMS'stop.shBefore attempting to terminate the process, the script will first try tops -ef | grep ... | awk ...Command to check if the target process PID exists. If the script detects that the PID does not exist (i.e.exists -eq 0It will friendly output a message indicating that the AnQiCMS process is currently not running, without performing any termination operation, which effectively avoids unnecessary errors or empty operations.

How can I ensure that the stop scripts for each instance of AnQiCMS running on my server can accurately terminate their corresponding processes?

When you run multiple independent AnQiCMS instances on the same server, **the practice is to copy a set of independent AnQiCMS program files for each instance. The key steps are to place the program files in the directory of each instance.anqicmsRename the executable file to a unique name (for example,anqicms_prod/anqicms_test). Then, modify each instance directory accordingly,stop.shand change the internal script,BINNAMEThe variable is set to match the new name of the executable file for this instance. This way, each instance'sstop.shscript will precisely locate and terminate the specific processBINNAMEthat matches the variable, ensuring that they do not interfere with each other.

If other unrelated application process names happen to contain the string "anqicms", will AnQiCMS's shutdown script incorrectly terminate them?

AnQiCMS'stop.shThe script avoids such misoperations bygrepusing in the command\<and\>the word boundary symbols of these regular expressions (grep '\<anqicms\>'This means it will strictly match 'anqicms' as a complete

Related articles

When encountering AnQiCMS process zombie (Zombie Process), can the PID management script solve it?

AnQiCMS is an enterprise-level content management system developed based on the Go language, which has won the favor of many small and medium-sized enterprises and content operation teams with its high efficiency, customizable and scalable features.As an experienced website operator, I am well aware of the importance of stable server operation for content platforms.In daily operation and maintenance, we occasionally encounter some abnormal server process situations, among which a "zombie process" is one of them.

2025-11-06

AnQiCMS is deployed on Baota Panel, what is the difference between PID monitoring of Go projects and manual scripts?

As an experienced security CMS website operator, I know that the stable operation of the website is the foundation for the efficient publication and optimization of content.The choice of deployment and process management methods for systems like AnQiCMS, which are developed based on the Go language, directly affects the reliability and operation and maintenance efficiency of the system.Today, let's delve into the similarities and differences between the PID monitoring mechanism of the AnQiCMS Go project and the manual maintenance script when deployed on Baota panel.

2025-11-06

How to modify the `start.sh` script so that it can still work normally after the AnQiCMS process name changes?

As a senior Anqi CMS website operation personnel, I am well aware of the importance of maintaining the stable operation of the system, especially in a changing application environment.AnQi CMS is favored by our operations team for its efficiency in Go language and ease of deployment.However, in daily operations, especially when it involves multi-site deployment or personalized configuration, one may encounter a situation where it is necessary to adjust the core startup script to adapt to the new process naming rules.### Understand the core function of the `start.sh` script `start.sh`

2025-11-06

If the `BINPATH` setting in the AnQiCMS startup script is incorrect, what PID-related issues may arise?

As an experienced AnQiCMS website operator, I know that every detail of the startup script may affect the stable operation of the system.In the daily operation and maintenance of AnQiCMS, the `BINPATH` variable in the startup script plays a vital role, indicating the storage path of the AnQiCMS executable files.Once this path is set incorrectly, a series of issues related to the Process ID (PID) will arise, directly affecting the startup, monitoring, and management of the AnQiCMS service.

2025-11-06

When the AnQiCMS process starts, which information in the `running.log` file is helpful for PID debugging?

As a website operator who deeply understands the operation of AnQiCMS, I know that every system file hides valuable information, especially when the system is abnormal, the log file is the key to troubleshooting.When the AnQiCMS process starts, the content recorded in the `running.log` file is crucial for debugging PID (process ID) and troubleshooting startup issues.

2025-11-06

Does the AnQiCMS `start.sh` script consider the issue of insufficient permissions in a multi-user environment that prevents PID from being checked?

As a senior CMS website operation personnel, I fully understand that in practice, especially in multi-user or shared server environments, ensuring the stable operation and effective management of the application is crucial.AnQiCMS is an enterprise-level content management system developed in Go language, the simplicity and efficiency of its deployment are one of its advantages, which naturally includes considerations for starting and stopping scripts.

2025-11-06

How to add a more robust PID file management mechanism to the AnQiCMS startup script?

As an experienced Anqi CMS website operation person, I know that the stability and reliability of website services are the foundation for the success of content operation.AnQiCMS with its efficient Go language features and concise architecture provides us with a solid foundation, but ensuring the robustness of its startup and shutdown in actual deployment, especially process management, is the key link that requires refined polishing.

2025-11-06

Why does the AnQiCMS `stop.sh` script use `awk '{printf $2}'` after `grep` to get the PID?

In the operation and maintenance of AnQi CMS, we often encounter situations where we need to start or stop services.For the AnQiCMS project developed based on the Go language, it usually runs as a single binary executable file.To achieve smooth service management, the `stop.sh` script plays a core role.

2025-11-06