AnQiCMS, as an efficient content management system built based on the Go language, is renowned for its lightweight and high-performance in command-line deployment environments.The characteristics of the Go language make AnQiCMS typically compiled into a standalone binary file, which simplifies deployment, but it also means that we need to clearly understand how to manage its lifecycle.Especially when we need to stop the service, how to ensure that all related background processes have completely exited, avoiding resource occupation or potential service conflicts, is a critical step to ensure the stable operation of the system and avoid the appearance of 'zombie processes'.
Understanding the essence of AnQiCMS process
In Linux and other operating systems, a Go application usually appears as a single main process.This process carries all the core functions of AnQiCMS, including web services, database connection pool, background task scheduling, and so on.When we start the service according to the AnQiCMS command line deployment tutorial, for example, by executingstart.shScript, the executable file of AnQiCMS (usually namedanqicmsWould benohupThe command is run in the background. This means that even if we close the SSH terminal session, the AnQiCMS service will continue to provide.
Therefore, when we decide to stop the AnQiCMS service, our main goal is to ensure that this main process is terminated safely and completely.Although the Go language's own concurrency model (Goroutine) runs efficiently within a single process and usually does not generate independent subprocesses, in some extreme cases, such as program crashes or configuration issues, unexpected resource usage may occur.
The official way to stop the AnQiCMS service:stop.shscript
The developers of AnQiCMS have prepared a convenient service management script for us,stop.shThis is used to stop the service. The core logic of this script is usually to find the process namedanqicmsand then sendkill -9a signal to force termination.
For example,stop.shThe simplified logic of the script may look like this:
#!/bin/bash
BINNAME=anqicms
exists=`ps -ef | grep '\<anqicms\>' |grep -v grep |awk '{printf $2}'`
if [ $exists -eq 0 ]; then
echo "$BINNAME NOT running"
else
echo "$BINNAME is running"
kill -9 $exists
echo "$BINNAME is stop"
fi
Thiskill -9The method ensures that even if AnQiCMS encounters certain deadlock situations, it can be effectively closed, which is a means of forcibly terminating the process without leaving an opportunity for the process to clean up resources. During the execution./stop.shAfter the command, we would usually think that the service has stopped. But as a meticulous operations expert, it is indispensable to carry out subsequent confirmation work to ensure that everything is in place.
How to confirm that all related processes have exited?
After the service has stopped, we need to go through several steps to verify.anqicmsIs the main process really exited, and has the port resources it occupied also been released?
Firstly, the most direct and most commonly used method is to usepsThe command to check the process list. In the command line, we can combinegrepThe command to filter outanqicms: related processes:
ps -ef | grep anqicms | grep -v grep
The meaning of this command is:ps -efList the details of all running processes on the system (including user, PID, CPU usage, etc.), then pass it through a pipeline|Pass the output togrep anqicmsThis step will filter all lines containing the keyword "anqicms". Finally, we will usegrep -v grepto excludegrep anqicmsThis command itself generates the process, ensuring that we see the process of the AnQiCMS service itself.
If there is no output after the command is executed, then Congratulations to you,anqicmsThe main process has successfully exited. If you still see similar linesroot 12345 1 ... /path/to/anqicmsthen it meansanqicmsthe process is still running, and we need to handle it further.
Secondly, in addition to the main process itself, sometimes AnQiCMS may not release the network port it occupies in time due to abnormal exit.This may hinder the normal startup of the next service because the new AnQiCMS instance will not be able to bind to the port that is already occupied.We can pass throughlsofCommand to check the occupation of a specific port. AnQiCMS uses it by default.8001Port, so we can check it like this:
lsof -i:8001
lsof -i:<port_number>The command lists all files or processes that have opened the specified network port. Ideally, after executing this command, there should be no output. If you see something similaranqicms 12345 user ...This line indicates that the port is still occupied by a process with PID12345ofanqicmsThe process is occupying. This usually meansanqicmsThe process may not be running inps -efIt is displayed in a clear way to show its web service functions, but it is still running in the background in some form and holding the port.At this time, you can record this PID for future processing.
Finally, although it is not a direct process exit confirmation, but check AnQiCMS'srunning.log(Instart.shThe log output is usually specified to this file) or system log file (for example, on Systemd systems usingjournalctl -u <your_anqicms_service>or check `/var