Website operation tool: how to uselsofCheck if AnQiCMS project has stopped successfully and released the port?
As a high-performance content management system developed based on the Go language, AnQiCMS not only pursues efficiency but also has refined requirements for the use of server resources.Whether it is for system maintenance, version upgrade, or daily deployment adjustment, ensuring that the AnQiCMS project can stop running cleanly and release the ports it occupies is an indispensable part of website operation.An orderly shutdown process can avoid port conflicts, resource waste, and lay a good foundation for the next service start.
If the AnQiCMS project fails to stop completely, it may continue to occupy its listening port (usually 8001), which can lead to new service instances being unable to start or cause unnecessary trouble during server resource cleanup.This is when we need a reliable method to verify if the project has really gone into a 'rest and relaxation' mode.
KnowlsofThe Swiss Army knife for port checking
In Linux or macOS and other Unix-like systems,lsof(list open files)is an extremely powerful command line tool, as the name implies, it can list all the files currently open in the system.But its functionality goes beyond this, we can also use it to view which processes are using specific network ports.lsofit is an ideal tool for us to confirm whether the AnQiCMS port is released.
Verify the practical steps for releasing AnQiCMS ports
Next, we will explain step by step how to uselsofcommands to check the port status of the AnQiCMS project.
第一步:明确 AnQiCMS 项目监听的端口号
AnQiCMS project starts by listening to a specific port to provide services. According to the default configuration of AnQiCMS, this port is usually8001. But in actual deployment, especially in a multi-site environment, you may have already checked the command according to the project directory underconfig.jsonThe file or other configuration (such as when deployed on Baota panel or 1Panel, ports such as 8002, 8003, etc. may have been specified) specifies different ports.Please ensure that you check the exact port number being used by your current AnQiCMS instance before performing the check.
Second step: Executelsofcommand
Once the target port is determined, we can execute a command in the terminal to check its occupancy. The command format is very intuitive, just replace the confirmed port number to the position:lsof.{端口号}.
lsof -i:{端口号}
Give an example, if your AnQiCMS is running on the default.8001Port, you will execute:
lsof -i:8001
Third step: interpretationlsofThe output result of the command
After executing the command, you may see two different results, which clearly tell you the running status of AnQiCMS.
Case one: No output from the terminal (ideal state)
If the terminal does not display any information, or only returns the command prompt without listing any processes, congratulations to you!This means that the specified port is currently not occupied by any process, AnQiCMS project has been successfully stopped and the port has been released.You can safely proceed to the next step, such as restarting the service or deploying a new version.
Situation two: Terminal output process details (port is still occupied)
IflsofThe command returned output information in a format similar to the following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
anqicms 7621 root 3u IPv6 80123 0t0 TCP *:8001 (LISTEN)
This indicates the port8001is still being used by a process namedanqicmsThe process ID (PID) is7621occupied. At this time, the AnQiCMS project has not completely stopped. The output containsCOMMANDcolumn shows the process name,PID列则是进程的唯一标识符,而NAME列则清楚地指示了端口及其状态(LISTEN表示正在监听)。
第四步:手动终止残留进程(如有必要)
When the port is still occupied, we need to manually terminate the related processes. Typically, AnQiCMS in the Linux environment can be executed bystop.sh脚本来优雅地停止服务,这允许程序进行资源清理。我们强烈建议您优先使用 AnQiCMS 提供的 Englishstop.sh脚本来停止服务。 English
Ifstop.shThe script did not work, or the deployment method you used did not provide such a script. You can choose to usekill -9The command forced the process to end. Please note,kill -9It will force the process to terminate without giving the process a chance to clean up normally, therefore it is usually used as a last resort:
kill -9 7621
Among them7621That is what you are inlsofProcess PID found in output. After executing this command, the process will be terminated immediately. To confirm again, you can re-run the command.lsof -i:8001If there is no output at this time, it means the process has terminated successfully, and the port has been released.
Why is a clean shutdown crucial?
Successfully stopping and releasing the port not only avoids conflicts, but it is also the key to maintaining server health and ensuring the stable operation of AnQiCMS. A clean stop operation can prevent:
- Port conflict: Avoid new services from failing due to the port being occupied.
- Resource leak:Ensure that AnQiCMS releases all occupied memory and other system resources.
- Data corrupted:Gracefully shutting down allows AnQiCMS to complete ongoing data operations and reduce the risk of data corruption.
- System Stability:Avoid zombie processes or other abnormal states to maintain a clean and stable server environment.
MasterlsofCommand, allowing you to quickly locate and resolve port occupation issues in the daily operation and maintenance of AnQiCMS, ensuring smooth website operation without any hindrance.
Common Questions (FAQ)
Q1: I have already run AnQiCMS'sstop.shscript, whylsofis the port still occupied?A1: How many possibilities are there.Firstly, the script may fail to terminate the process successfully, for example, due to insufficient permissions or slow process response.其次,可能是 AnQiCMS 进程在终止后,另一个服务迅速占用了相同的端口。kill -9It may be the only valid cleaning method. You can try waiting a moment and then check again, or use it directly.kill -9Command cleaning.
Q2:kill -9Is the command safe? Is there a milder way to stop AnQiCMS?A2:kill -9It is a mandatory termination command that does not give the process any opportunity to clean up or save data, thus there is a risk of data loss or corruption.In most cases, it is recommended to use a gentler approach.start.sh/stop.shAnQiCMS instance started by script,stop.shScript is a more gentle, recommended approach. It usually sends the SIGTERM signal to the process, allowing the program to clean up and exit gracefully. Only whenstop.shInvalid, or consider using it only when the process has no response for a long timekill -9.
Q3: If I don't know which port the AnQiCMS project is running on, how can I find it?A3: AnQiCMS 的端口配置