AnQiCMS, as an efficient content management system built with Go language, is known for its lightweight and high performance in command line deployment environments.The characteristics of the Go language make AnQiCMS typically compiled into an independent binary file, which simplifies deployment but 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 to avoid resource occupation or potential service conflicts, is a critical step to ensure the stable operation of the system and prevent the occurrence of 'zombie processes'.
Understanding the essence of the AnQiCMS process
In Linux and other operating systems, a Go application typically 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.start.shScript, the executable file of AnQiCMS (usually namedanqicms) will benohupCommand runs 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 thoroughly.Although Go language's own concurrency model (Goroutine) runs efficiently within a single process and usually does not produce 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 typically to find the process namedanqicmsand then send itkill -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 way ensures that even if AnQiCMS encounters some deadlock situations, it can be effectively closed, which is a means of forcibly terminating the process without giving the process a chance to clean up resources. During the execution./stop.shAfter the command, we usually believe that the service has stopped. However, as an meticulous operation and maintenance expert, it is indispensable to carry out subsequent confirmation work to ensure everything is perfect.
How can we confirm that all related processes have exited?
After the service stops, we need to go through several steps to verifyanqicmsDoes the main process indeed exit, and has the port resources it occupied also been released?
Firstly, the most direct and commonly used method is to utilizepsCommand to check the process list. In the command line, we can combinegrepcommand to filter outanqicmsthe relevant processes:
ps -ef | grep anqicms | grep -v grep
The meaning of this command is:ps -efList detailed information of all running processes on the system (including user, PID, CPU usage, etc.), then pass the output to|grep anqicmsThis step will filter out all lines containing the keyword "anqicms". Finally, we will usegrep -v grepto exclude.grep anqicmsThis command itself generates a 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 exited successfully. If you still see similar lines,root 12345 1 ... /path/to/anqicmsit meansanqicmsthe process is still running, and we need to further handle it.
Secondly, in addition to the main process itself, AnQiCMS may sometimes not release the network port it occupies in time due to abnormal exit.This may hinder the normal startup of the next service, as the new AnQiCMS instance will not be able to bind to the occupied port.lsofCheck the occupation status of a specific port. AnQiCMS uses by default8001port, so we can check it like this:
lsof -i:8001
lsof -i:<port_number>The command will list all files or processes that have opened the specified network port. Ideally, there should be no output after executing this command. If you see something similar toanqicms 12345 user ...The line indicates that the port is still being used by a process with PID of12345ofanqicmsThis usually means that the process is occupyinganqicmsAlthough the process may not be actively running inps -ef
Finally, although not a direct process exit confirmation, but check the AnQiCMS'srunning.log(Instart.shThe configuration usually specifies the log output to this file) or system log file (for example, on Systemd systems)journalctl -u <your_anqicms_service>, or check `/var