How to manually check if the PID of AnQiCMS process exists on a Linux server?
As a senior AnQiCMS operations manager, I fully understand the importance of ensuring the stable operation of the core service - 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 properly.This operation is not only a key link in daily maintenance, but also an effective means of preliminary investigation when we encounter website access anomalies.
Understand the AnQiCMS process and its importance
AnQiCMS is an enterprise-level content management system developed based on the Go programming language. After deployment, it usually runs as a standalone executable binary file in the server background. In a typical installation, this executable file is namedanqicmsThis single process is responsible for handling all requests of the website, including content display, backend management, and the operation of various functional modules. Therefore, ensureanqicmsThe existence and health of the process is the cornerstone of ensuring the normal operation of the entire website.
When the website is slow to respond, inaccessible, or the background functions are abnormal, the first thing we need to do is confirm that the AnQiCMS core process is still active.If the process terminates unexpectedly, the website naturally cannot provide services;Even if the process exists, we may need to obtain its PID for further monitoring or management operations, such as safely restarting the service or analyzing its resource usage.
Method one: throughpsCommand to check if the process exists and get the PID
On the Linux system,psThe command is a powerful tool to view the status of the currently running processes. CombinedgrepWith filtering, we can accurately find the process of AnQiCMS.
We usually useps -efThe command to list the details of all running processes on the system. Wherein-eThe parameter to display all processes,-fThe parameter will display a complete formatted list, including user, PID, CPU usage, and other key data.
To filter out the AnQiCMS process from a long list of processes, we can pass theps -efoutput through a pipeline (|) togrepcommand.grep 'anqicms'It will search for lines containing the string “anqicms”. However, just usinggrep 'anqicms'Willgrepthe command itself is also included in the results becausegrepThe command line of the process will also appear "anqicms". To avoid this, we can use it againgrep -v grepto excludegrepthe process itself.
Further, to ensure that we match the exact binary filenameanqicmsThis is not a part of the path or any string containing 'anqicms', we can use word boundaries in regular expressions.\<and\>The final command will be like this:
ps -ef | grep '\<anqicms\>' | grep -v grep
Execute this command and if the AnQiCMS process is running, you will see output similar to the following:
root 12345 1 0 09:30 ? 00:00:15 /www/wwwroot/anqicms.com/anqicms
In this line output,12345It is the PID of the AnQiCMS process. If no output is produced, it means that the AnQiCMS process is currently not running.
If you need to extract the PID directly rather than displaying the entire process information, you can useawkcommand to select the second column (usually the column where PID is located):
ps -ef | grep '\<anqicms\>' | grep -v grep | awk '{print $2}'
This command will directly output the PID of the AnQiCMS process, for example:
12345
Method two: throughlsofCommand to check port occupancy status
AnQiCMS as a web application, will listen on a specific port (usually the default one),8001) to provide services.lsof(list open files) is a tool used to view open system files and network connections.We can use it to check which process is occupying the port configured by AnQiCMS, thereby indirectly confirming the existence of the AnQiCMS process and its PID.
Assuming AnQiCMS is running on the default8001On the port, we can execute the following commands:
lsof -i:8001
If AnQiCMS is listening on this port, you will see an output similar to the following:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
anqicms 12345 root 3u IPv6 67890 0t0 TCP *:8001 (LISTEN)
In the output,anqicmsis the command name,12345It is its PID. This also clearly indicates that the AnQiCMS process is running and listening on its expected port.If the command does not produce any output, or the COMMAND displayed in the output is notanqicmsThis may mean that the AnQiCMS process is not running, or another program is using the port.
Method three: Use the start and stop scripts provided by AnQiCMS for indirect checking
In the installation directory of AnQiCMS, it usually providesstart.shandstop.shSuch helper scripts are used to manage processes. These scripts internally contain the logic to check if a process is running, although it is not a direct manual check command, but by reading them, we can learn the check method recommended by the AnQiCMS official.
For example, instart.shIn the script, it usually includes the following snippet to check if the process exists:
BINNAME=anqicms
# ...
exists=`ps -ef | grep '\<anqicms\>' |grep -v grep |wc -l`
# ...
if [ $exists -eq 0 ]; then
echo "$BINNAME NOT running"
# ... 启动 AnQiCMS
fi
Thisstart.shBefore trying to start AnQiCMS, the script will first useps -ef | grep '\<anqicms\>' |grep -v grep |wc -lto determine the name ofanqicmsThe process exists. Ifwc -lresult (that is$existsthe value of the variable) is0, it means the process has not run, and then the start operation will be executed.}
Similarly,stop.shThe script will get the PID of the running AnQiCMS process and terminate it:
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
From these scripts, we can learn and adopt the internal process check logic, which is the same as the manual execution mentioned abovepsThe command methods are highly consistent. They are the automation practices of system administrators in managing AnQiCMS processes in daily operations, and also provide reliable references for our manual checks.
Summary
By using the above methods, as an AnQiCMS operator, we can skillfully check whether the PID of the AnQiCMS process exists on the Linux server.No matter whether it is to troubleshoot faults, carry out daily maintenance, or deploy a new version, these skills will be a strong guarantee for our efficient work.Proficiently using these commands will help us better monitor and manage the AnQiCMS service, ensuring its stable and reliable operation.
Frequently Asked Questions (FAQ)
1. I have found the PID of the AnQiCMS process, and the process is running, but the website is still inaccessible, why is that?
Even if the AnQiCMS process exists, the website may not be accessible due to various reasons.You need to check the configuration of Nginx or Apache and other reverse proxy servers to ensure that they forward requests correctly to the port AnQiCMS is listening on (for example, 8001).At the same time, check the firewall rules of the server to ensure that the ports listened to by AnQiCMS and the 80/443 ports listened to by the web server are open.In addition, AnQiCMS's internal errors may also cause the service to be unavailable, at this time you should check the AnQiCMS runtime logs (usually in the installation directory below)running.logIn the specified log file) for more detailed error information.
2. How should I stop or restart the AnQiCMS process?
The most recommended way is to use the AnQiCMS providedstop.shandstart.shscripts. These scripts are usually located in the AnQiCMS installation directory, and they can manage processes in a safer and more elegant way. Executestop.shStop the currently running AnQiCMS process and executestart.shIt will start it (if not running). To restart, execute in orderstop.shThen executestart.shAvoid using it directly.kill -9 PIDUnless the process does not respond, as it may cause data loss or inconsistent status.
3. The executable file name of my AnQiCMS is notanqicmsHow can I check the process?
In some custom deployment or multi-site configuration scenarios, the executable file name of AnQiCMS may be modified. If your executable file name is notanqicmsYou need to adjust according to the actual filenamepsandgrepThe search keyword in the command. For example, if your executable file name ismyanqicmsthen the command will beps -ef | grep '\<myanqicms\>' | grep -v grep. You can check the AnQiCMS installation directory orstart.shandstop.shThe defined in the scriptBINNAMEvariable to confirm the correct binary filename.