How does the `stop.sh` script accurately identify and kill the specified AnQiCMS process?

Calendar 👁️ 65

In the daily operation of the Anqi CMS website, precise management of the system's core processes is a key factor in ensuring service stability and maintenance efficiency. Among these,stop.shThe script plays a crucial role in accurately identifying and terminating the running AnQiCMS main process.As a content operation expert familiar with AnQiCMS, I know that such tools are indispensable for ensuring the smooth operation of core businesses such as content publishing and updating.

stop.shThe design purpose of the script is to provide an automated and reliable way to shut down the AnQiCMS service, which is very necessary for performing system maintenance, upgrades, or troubleshooting tasks.It avoids the麻烦 and potential errors of manually searching for process IDs, ensuring the accuracy of operations.

The core of script work lies in its clever process recognition mechanism. It first utilizesps -efCommand to list detailed information of all running processes on the system.This command will output comprehensive data including process ID (PID), parent process ID (PPID), CPU utilization, startup time, and command line.

Next, in order to accurately filter out the AnQiCMS main process from the庞大的 process list, the script uses two layersgrepof filtering. The first layergrep '\<anqicms\>'is the key to identification. Here,\<and\>It is a word boundary in regular expressions, they ensuregrepOnly match the complete 'anqicms' word, not other process names containing 'anqicms' as a substring (such as, namedmyanqicms_appThe process will not be mistakenly killed). This precise matching avoids the injury of other processes with similar names but unrelated functions on the system, greatly improving the safety of the operation.

Following thatgrep -v grepIt is a standard and necessary filtering step. Due togrepThe command itself is also a process, which appears when it is executed.ps -efThe output contains, and its command line will include the keyword it is searching for (i.e. "anqicms"). To preventgrepthe process from being mistakenly identified and terminated,grep -v grepExclude all lines containing the 'grep' keyword from the results, thereby obtaining a pure list containing only the target AnQiCMS process.

Finally, throughawk '{printf $2}'Command, the script extracts the process ID (PID) from the process information that has been filtered through two layers. Inps -efThe output format, the second field is usually the process ID,awkThe tool can accurately capture this information. If the AnQiCMS process is running,existsthe variable will store its PID; if not found,existsit will be empty.

After obtaining the process ID, the script will make a simple judgment. IfexistsThe variable is empty, indicating that the AnQiCMS process is not running, and the script will output the corresponding prompt information. Otherwise, ifexistsit contains a valid PID, the script will executekill -9 $existscommand.kill -9is to sendSIGKILLA signal, which is an instruction to force the termination of a process, the target process cannot capture or ignore this signal, thus ensuring that the AnQiCMS process stops immediately and unconditionally.This mandatory requirement is especially effective when it is necessary to quickly shut down services to respond to emergencies.

Throughout the execution process, the script will also pass throughechoThe command will record the time of operation, process name, and PID check results tocheck.logThe file is being processed, and status information is displayed on standard output. This log record provides valuable data for subsequent operation and maintenance audits and troubleshooting.

Through this meticulous identification logic and decisive termination mechanism,stop.shThe script provides AnQiCMS system administrators with a powerful and reliable tool, ensuring they can accurately and efficiently manage the core services of AnQiCMS when needed.


Frequently Asked Questions (FAQ)

1. If my AnQiCMS executable is not the default oneanqicms,stop.shCan the script recognize and stop it?

By default,stop.shin the scriptBINNAMEThe variable is hardcoded toanqicmsIf your AnQiCMS executable file is renamed (for example, to distinguish between multiple instances on the same server), you need to manually editstop.shthe script, andBINNAME=anqicmsThis line should be modified to your actual executable file name, for exampleBINNAME=myanqicmsappSimilarly, in the scriptgrep '\<anqicms\>'This section also needs to be modified accordingly to ensure an accurate match

2. Whystop.shThe script needs to usekill -9Forcefully terminate the process instead of a gentler approachkillcommand?

kill -9The one sent isSIGKILLA signal that cannot be captured or ignored by the target process, it will immediately terminate the process without giving the process a chance to clean up or save data. Although this may result in the loss of unsaved data, it is often used in automated scripts, especially when it is necessary to ensure that the process is quickly and unconditionally closed (for example, to avoid zombie processes, to deal with unresponsive processes, etc.),kill -9It is a more reliable choice because it guarantees the termination of the process. For daily graceful shutdowns, it is usually usedkillSendSIGTERM(Default signal),allowing the process to clean up resources on its own before exiting.

3. How to confirmstop.shThe script has successfully stopped the AnQiCMS process?

Runstop.shAfter the script, you can verify by executing it againps -ef | grep '\<anqicms\>' | grep -v grepcommand. If the command does not return any results, it means the AnQiCMS process has been successfully terminated. In addition,stop.shThe script will also record the process check results in its execution log (default ascheck.log), you can view the file to confirm the process status.

Related articles

What are some more gentle and safe commands to stop the AnQiCMS process besides `kill -9`?

As an experienced CMS website operation personnel of an enterprise, I know that the stability of website services and data security are the foundation of operation work.When managing AnQi CMS service, we often encounter situations where we need to stop or restart processes.However, commands like `kill -9` that forcibly terminate processes, although seemingly quick, may bring potential risks such as data loss and extended service interruption time.Therefore, understanding and adopting gentler and safer stop commands is crucial for maintaining the healthy operation of the website.

2025-11-06

The `kill -9 {PID}` command in an emergency stops the AnQiCMS process, what are its advantages and disadvantages?

As a senior Anqi CMS website operations manager, I know that in daily management, the stable operation of the program is the foundation, and how to deal with emergencies quickly and effectively tests the responsiveness of the operator.When AnQiCMS process encounters an abnormal condition, such as complete unresponsiveness, soaring resource usage, or getting stuck in an infinite loop, the `kill -9 {PID}` command often becomes our 'emergency tourniquet'.However, the sharpness of this 'hemostat' also carries potential risks.### Stop the AnQiCMS process in an emergency situation: `kill -9`

2025-11-06

What is the exact step to find port conflict of AnQiCMS process using the `lsof -i:{port number}` command?

As an experienced CMS website operation person in the security industry, I know that the stable operation of the website is of great importance.Port conflict is a common issue encountered during the initial deployment or multi-site management, which can cause the AnQiCMS service to fail to start or be inaccessible.Understand how to accurately diagnose and resolve such issues, which is crucial for ensuring the normal operation of your website. ### Common scenarios of port conflicts AnQiCMS uses the default port `8001`. When there are other services on the server (such as other web applications, database services

2025-11-06

When the default port of AnQiCMS is occupied, can the `start.sh` script automatically switch ports or provide a prompt?

As a long-term operator of the AnQiCMS website, I am well aware of the importance of system stability and efficient deployment for website operations.In daily work, server port occupation is a common but often overlooked problem.Today, we will delve into how the core startup script `start.sh` of AnQiCMS responds when its default port is occupied, as well as how we, as operations personnel, should understand and handle such situations.

2025-11-06

Under a multi-site deployment scenario, how can the `stop.sh` script ensure that only the AnQiCMS instance expected by the user is stopped?

AnQiCMS is an enterprise-level content management system designed for small and medium-sized enterprises, self-media, and multi-site management, and its multi-site management capability is one of its core advantages.In operational maintenance, especially when deploying multiple AnQiCMS instances on the same server to support more independent sites, how to ensure precise operations on specific instances, such as stopping only the services that users expect, has become a key challenge.`stop.sh` script effectively solves this problem in this scenario through clever design.###

2025-11-06

Why does AnQiCMS recommend using `cron` job scheduling as a process guardian mechanism?

As an experienced CMS website operation personnel of a security company, I fully understand the importance of website stable operation for content publication and user experience.AnQiCMS is an efficient enterprise-level content management system that takes into account the ease of deployment and reliability of operation from the beginning of its design.In the selection of process guard mechanism, AnQiCMS recommends using `cron` scheduled tasks, which are based on deep technical and operational considerations.

2025-11-06

What is the specific function of the `grep -v grep` command in the `start.sh` script?

In the daily operation and maintenance of AnQiCMS, the `start.sh` script plays a crucial role, it is responsible for checking whether the AnQiCMS service is running normally, and starting the service when necessary.Inside this script, we see a wonderful code snippet: `ps -ef | grep '\u003canqicms>' | grep -v grep | wc -l`.The purpose of this command is to accurately determine if the AnQiCMS process exists, among which the role of `grep -v grep` is particularly crucial

2025-11-06

wc -l` command plays a critical role in the PID existence detection in `start.sh`.

In the daily operation and maintenance of AnQi CMS, ensuring the continuous and stable operation of core services is a crucial link.In the `start.sh` script, the detection mechanism for the existence of the AnQiCMS process ID (PID) is the key to achieving this goal.Among them, the `wc -l` command plays an indispensable role in this detection process.

2025-11-06