As an experienced AnQi CMS operation personnel, I know the importance of ensuring the stable operation of the core service of the website - the AnQiCMS application itself.In the Linux server environment, it often requires manual checking to verify whether the AnQiCMS process is working normally, by checking its process ID (PID).This operation is not only a key link in daily maintenance, but also an effective means for preliminary investigation when we encounter abnormal website access.


Understanding AnQiCMS process and its importance

AnQiCMS is an enterprise-level content management system developed based on the Go language, which usually runs in the background of the server as a separate executable binary file after deployment. In typical installations, this executable file is namedanqicmsThis single process is responsible for handling all requests of the website, including content display, background management, and the operation of various functional modules. Therefore, it is essential thatanqicmsThe existence and health of the process are the cornerstone for the normal operation of the entire website.

When the website shows slow response, inability to access, or abnormal background functions, the first thing we should do is confirm whether the core process of AnQiCMS is still active.If the process terminates unexpectedly, the website naturally cannot provide services; even if the process exists, we may still need to obtain its PID for further monitoring or management operations, such as safely restarting the service or analyzing its resource usage.


Method one: throughpsCheck if the process exists and get the PID

On Linux systems,psThe command is a powerful tool to view the current running process status. Combined withgrepfiltering, we can accurately find the process of AnQiCMS.

We usually useps -efThe command to list detailed information about all running processes on the system. The-eparameter displays all processes,-fThe parameter displays the complete formatted list, including user, PID, CPU usage and other key data.

In order to filter out the AnQiCMS process from a long list of processes, we canps -efpipe the output of|togrepa command.grep 'anqicms'It will search for lines containing the string “anqicms”. However, the command itself is also included in the results becausegrep 'anqicms'It willgrepthe command itself is also included in the results, becausegrepThe command line of the process will also appear "anqicms". To avoid this situation, we can use it againgrep -v grepto exclude.grepthe process itself.

Furtherly, to ensure that we match the exact binary filenameanqicmsThe content rather than a part of the path or any string containing 'anqicms', we can use the word boundary of regular expressions.\<and\>The final command will be like this:.

ps -ef | grep '\<anqicms\>' | grep -v grep

After executing this command, 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 of output,12345It is the PID of the AnQiCMS process. If no output is returned, it means that the AnQiCMS process is currently not running.

If you need to extract PID directly instead of displaying the entire process information, you can useawkcommand to select the second column (usually the PID column):

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 checks the port occupancy situation

AnQiCMS as a web application will listen on a specific port (usually the default one) to provide services.8001) to provide services.lsof(list open files) is a tool used to view the system's open files and network connections.We can use it to check which process occupies 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 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 can clearly indicate that the AnQiCMS process is running and listening on its expected port.anqicms, this 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

The installation directory of AnQiCMS usually providesstart.shandstop.shSuch auxiliary scripts to manage processes.These scripts internally contain logic to check if processes are running, although it is not a direct manual check command, but by reading them, we can learn the check method recommended by AnQiCMS.

For example, instart.shIn the script, it usually includes the following fragment 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 attempting to start AnQiCMS, the script will first useps -ef | grep '\<anqicms\>' |grep -v grep |wc -lto judge the name ofanqicmsThe process exists. Ifwc -lresult (i.e.,$existsthe value of the variable) is0, then it means the process has not run, and then the startup 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 similar to the manual execution mentioned abovepsThe method of the command is highly consistent.They are the automated practices of system administrators managing AnQiCMS processes in daily operations, and also provide a reliable reference for our manual checks.


Summary


Common Questions and Answers (FAQ)

1. I have found the PID of 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 that AnQiCMS is listening on (for example, 8001).Ensure that the firewall rules of the server are checked, and the ports that AnQiCMS listens to and the 80/443 ports that the web server listens to are open.running.logOr specify a log file in other specified log files) to obtain more detailed error information.

2. How do I stop or restart the AnQiCMS process?

The most recommended way is to use AnQiCMS providedstop.shandstart.shscript. These scripts are usually located in the installation directory of AnQiCMS, and they can manage processes in a safer and more elegant way. Executestop.shCan stop the currently running AnQiCMS process, executestart.shIt will start it (if not running). If you need to restart, you can execute in orderstop.shThen executestart.sh. Avoid using it directlykill -9 PIDEnglish translation: Unless the process cannot respond, it may cause data loss or inconsistent state.

English translation: My AnQiCMS executable file name is notanqicmsEnglish translation: How can I check the process?

In some custom deployment or multi-site configuration scenarios, the executable filename of AnQiCMS may be modified. If your executable filename is notanqicmsYou need to adjust the actual filename.psandgrepThe search keywords in the command. For example, if your executable file name ismyanqicms, then the command will becomeps -ef | grep '\<myanqicms\>' | grep -v grep。You can check the installation directory of AnQiCMS, orstart.shandstop.shthe variables defined in the scriptBINNAMEto confirm the correct binary filename.