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

Calendar 👁️ 68

As an experienced security CMS website operation person, I know that the stability of website services and data security is the foundation of operation work.When managing the Anqi CMS service, we often encounter situations where we need to stop or restart the process.kill -9The command to forcefully terminate the process, although it seems quick, may still bring potential risks such as data loss and extended service interruption time.Therefore, understanding and adopting milder and safer stop commands is crucial for maintaining the healthy operation of the website.

Say goodbye to roughness and embrace a gentle shutdown

kill -9The command sends to the process isSIGKILLA signal, which means the operating system will immediately force the process to terminate, without giving it any chance to clean up or save the state.This is like pulling the power plug directly, which may lead to data loss in processing, database connections not closed properly, incomplete log information, and other issues.For systems like AnqiCMS that need to handle user requests, read and write databases, and manage file content, this brute force method should be avoided as much as possible.AnQi CMS is an enterprise-level content management system developed in Go language, the applications of Go language can usually respond well to termination signals and perform graceful shutdown operations.

Understand the process and recognition of AnQiCMS

Before performing any stop operation, it is first necessary to accurately identify the running AnQiCMS process. The AnQiCMS application typically runs as a standalone binary file (for example, on Linux asanqicms, Windows under isanqicms.exe). We can find its process ID (PID) using the command line tool.

In Linux system, the commonly used command to combinepsandgrep:

ps -ef | grep anqicms | grep -v grep

This command lists all processes containing the string "anqicms" and excludes them.grepThe process of the command itself, thereby displaying the real process information of AnQiCMS, where the second column is the process ID (PID). For example:

root      7621     1  0 10:30 ?        00:00:10 /www/wwwroot/anqicms.com/anqicms

Here7621It is the PID of the AnQiCMS process.

A gentler stop command.

Once we have determined the PID of the AnQiCMS process, we can use the following safer and gentler method to stop it:

1. Use the AnQiCMS providedstop.shscript

The official AnQiCMS provided the deployment tutorial for Linux environment,start.shandstop.shScripts to manage the startup and shutdown of processes. This is the most recommended and direct method, as it is provided by AnQiCMS developers to ensure compatibility and stability.

stop.shThe sample content of the script is as follows:

#!/bin/bash
### stop anqicms
# author fesion
# the bin name is anqicms
BINNAME=anqicms
BINPATH="$( cd "$( dirname "$0"  )" && pwd  )"

# check the pid if exists
exists=`ps -ef | grep '\<anqicms\>' |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

Description:Although thisstop.shThe script internally useskill -9But it is designed as part of the entire AnQiCMS maintenance process.The purpose is to ensure that the process can be forcibly terminated regardless of its state, which is particularly important in automated scripts or handling exceptional situations.For everyday operations, we should trust the overall design of the official script../stop.shAt this time, it will check and terminate the AnQiCMS process, usually used for cleaning before service restart.

2. PassedkillCommand to send termination signal (SIGTERM)

Thankill -9More gentle is not carrying-9The parameter'skillThe command sendsSIGTERM(Signal 15).SIGTERMThe signal notifies the process that it should terminate, but allows the process to perform cleanup work before termination, such as closing files, saving data, and gracefully disconnecting from network connections.This is the key for the application to implement "graceful shutdown".

Execution method:

kill [PID]

For example:

kill 7621

When sendingSIGTERMAfter that, it will usually wait for a few seconds, giving enough time for the AnQiCMS process to complete the cleanup work. If the process does not exit automatically within this time, then it may be necessary to consider usingkill -9As a last resort. AnQiCMS, as an enterprise-level application, its Go language backend usually capturesSIGTERMa signal to achieve an elegant shutdown.

3. Use the system service management tool (Systemd / Init)

If AnQiCMS is configured as a system service (such as on Linux through Systemd or traditional SysVinit), then the shutdown method is through the service management tool. These tools usually sendSIGTERMSignal and wait for the service to shut down gracefully.

For services managed by Systemd:

sudo systemctl stop anqicms.service

For traditional SysVinit or Upstart services:

sudo service anqicms stop

Using service management tools can not only gracefully stop processes but also handle dependencies and record service status, which is the recommended standard operation in production environments.

4. Graceful exit in containerized environment (Docker)

If AnQiCMS is deployed in a Docker container (a Docker deployment tutorial is also provided in the documentation), then the command to stop the container will be sent by defaultSIGTERMSignal, and give the main process inside the container a grace period (default 10 seconds) to complete the cleanup.

Execution method:

docker stop [容器名或容器ID]

For example:

docker stop anqicms_container_name

If the container does not stop within the grace period, Docker will send the force stop signal.SIGKILL.

Why choose a gentle shutdown?

  1. Data integrityAllow AnQiCMS to complete all pending database transactions and data writes before closing to prevent data corruption or loss.
  2. Smooth user experienceThe user requests being processed are able to receive normal responses rather than sudden interruptions, reducing the negative user experience.
  3. Log recordingThe process has the opportunity to write shutdown information to the log, which is convenient for subsequent troubleshooting and auditing.
  4. Resource cleanup: AnQiCMS can release occupied file locks, network ports, and other system resources.
  5. Faster restartThe system status is clean, no need for complex recovery or checks upon next startup, and can recover services faster.

Operation process suggestion

In the operation, I usually follow the following steps to stop the AnQiCMS process:

  1. Check the status of the AnQiCMS process:
    
    ps -ef | grep anqicms | grep -v grep
    
    Get PID.
  2. Try to stop gently:
    • Preferred: Using the AnQiCMS providedstop.shScript:./stop.sh(If it exists and is configured correctly).
    • Secondary optionIf AnQiCMS is running as a system service, use the service management command:sudo systemctl stop anqicms.serviceorsudo service anqicms stop.
    • General method: SendSIGTERMsignal:kill [PID].
  3. Wait and verify: Wait for a few seconds (for example, 5-10 seconds), and then use it againps -efCommand to check if the process has exited.
  4. If it has not exited yet, consider forcing termination.: Only use it when the gentle stop failskill -9 [PID].

Through these gentle and safe commands, we can ensure the stable operation of AnQiCMS service and the security of data.


Frequently Asked Questions (FAQ)

Q1: Why mystop.shscript also useskill -9command, is it safe?

A1:provided by AnQiCMSstop.shThe script although usedkill -9is part of the official maintenance process, intended to ensure that the process can be terminated in all cases. In most cases, it is executed by the official script.kill -9Is acceptable, especially when performing forced cleanup before service restart. However, in general principles,SIGTERM(Bykill [PID]Send) Allows the program to perform internal cleanup, if AnQiCMS is designed to respondSIGTERMPerform a graceful shutdown, then manually sendSIGTERMIs a more ideal 'gentle' way. You can try to send manually first.SIGTERMIf the process does not stop in time, consider executing.stop.shScript orkill -9.

Q2: How do I stop AnQiCMS that is running in Docker?

A2:The safest and mildest way to stop the AnQiCMS container in the Docker environment is to usedocker stop [容器名或容器ID]command. Docker by default will send to the main process of AnQiCMS inside the containerSIGTERMA signal is given, and a default grace period (usually 10 seconds) is provided for the program to shut down automatically. Only when AnQiCMS fails to stop within this grace period, Docker will force the transmissionSIGKILLThus,docker stopThe command is already an elegant way to stop the service in the Docker environment.

Q3: After stopping the AnQiCMS process, I found that the website is still inaccessible or shows error messages. How should I investigate?

A3:The website may not be accessible or display errors for various reasons. First, confirm that the AnQiCMS process has started successfully, you can check byps -ef | grep anqicms | grep -v grepCheck again. If the process has started but the website is still inaccessible, it may be a port conflict (check)install.mdmentionedlsof -i:{端口号}), or reverse proxy configuration (such as Nginx/Apache) failed to correctly point to AnQiCMS service. In addition, check the AnQiCMS'srunning.logorcheck.logThe file, which usually contains detailed information about startup failures or runtime exceptions, is helpful for further troubleshooting.

Related articles

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

How to manually check if the PID of AnQiCMS process exists on a Linux server?

As an experienced AnQi CMS operation personnel, I am well aware of the importance of ensuring the stable operation of the core service of the website - the AnQiCMS application itself.In a Linux server environment, it is often necessary to manually check the process ID (PID) to verify that the AnQiCMS process is working normally.This operation is not only a key link in daily maintenance, but also an effective means for preliminary investigation when we encounter website access exceptions.

2025-11-06

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

In the daily operation of the AnQi CMS website, precise management of the system core processes is the key to ensuring service stability and maintenance efficiency.This script, `stop.sh`, 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 publication and updates.

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