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.