As an experienced website operations expert, I fully understand the importance of an efficient and stable content management system (CMS) for an enterprise's online business.AnQiCMS (AnQiCMS) is an ideal choice for many small and medium-sized enterprises and content operation teams due to its high performance and concise and efficient architecture based on the Go language.However, even the most excellent system cannot do without refined operation and maintenance management, which includes how to safely and effectively stop its running process.Today, let's delve into the shutdown script of AnQiCMS in the Baota panel environmentstop.shHow should it be configured and executed.
Graceful shutdown: Why do we needstop.sh?
You might think, why not just stop a website service by clicking the stop button directly in the Baota panel? Or simply粗暴lykillProcess dropped? For an application like AnQiCMS, which is developed based on the Go language, its operating mechanism is different from traditional PHP, Java applications.It usually runs as a separate binary file, and its process management requires clearer instructions.stop.shThe script is born to achieve this, it is not just a forced termination, but also carries the responsibility of locating the correct process and safely closing, which is crucial to avoiding data damage and ensuring smooth startup next time.
stop.shThe core task is to find the currently running AnQiCMS main process and send it a termination signal.This process involves several key steps and clever combinations of Unix/Linux commands.
Revelationstop.shScript content
According to the official AnQiCMS documentation, a typicalstop.shscript would look something like this:
#!/bin/bash
### stop anqicms
# author fesion
# the bin name is anqicms
BINNAME=anqicms
BINPATH="$( cd "$( dirname "$0" )" && pwd )"
# check the pid if exists
exists=`ps -ef | grep '\<anqicms\>' |grep -v grep |awk '{printf $2}'`
echo "$(date +'%Y%m%d %H:%M:%S') $BINNAME PID check: $exists" >> $BINPATH/check.log
echo "PID $BINNAME check: $exists"
if [ $exists -eq 0 ]; then
echo "$BINNAME NOT running"
else
echo "$BINNAME is running"
kill -9 $exists
echo "$BINNAME is stop"
fi
Let's break down the essence of this script:
BINNAME=anqicmsThis line defines the name of the AnQiCMS executable file. By default, the AnQiCMS executable is usually namedanqicmsIf your filename has been changed, be sure to update it here.BINPATH="$( cd "$( dirname "$0" )" && pwd )"This line of code is very clever, it automatically gets the currentstop.shabsolute path of the script and assigns it toBINPATHThis means that, no matter where you place the script, as long as it is in the same directory as the AnQiCMS executable file, it can automatically identify its runtime environment.exists=ps -ef | grep 'anqicms' |grep -v grep |awk '{printf $2}'This is the core command of the script, used to find the process ID (PID) of AnQiCMS.ps -efList the details of all processes currently running on the system.grep '\<anqicms\>'From the process list, filter out lines containing the keyword "anqicms".\<and\>Is a word boundary, to ensure that only the complete word "anqicms" is matched, not partial matches like "anqicms_test".grep -v grepThis step is to exclude.grepThe process of the command itself, becausegrepThe command itself will also contain the 'grep' keyword to avoid killing incorrectly.awk '{printf $2}'Extract the second column of the filtered process information, which is usually the process ID (PID).
if [ $exists -eq 0 ]; then ... else ... fiThis is a conditional judgment.- If
existsThe PID found is 0, indicating that the AnQiCMS process is not running, the script will output "NOT running". - If
existsNot 0, it means that the AnQiCMS process is running, the script will output "is running" and then executekill -9 $existscommand.
- If
kill -9 $existsThis is the command to forcibly terminate a specified PID process.-9It is a强制终止信号,meaning the process will immediately stop without performing any cleanup work. Although it is somewhat rough, it is very effective in ensuring that the process stops.
Configure in the Baota panelstop.sh
With an understanding of the script, it becomes effortless to configure in the Baota panel.
Log in to the Baota panel and go to the "Scheduled Tasks" section.Click the 'Task Schedule' option in the left menu bar.
Add task scheduleClick the 'Add Task Schedule' button at the top of the page.
Configure task parameters:
- Task type: Select "Shell Script".
- Task Name: Suggest naming it "Stop AnQiCMS" or a similar clear name.
- Execution Schedule: In the official documentation,
stop.shThe example is to be executed monthly, which is usually for regular cleaning or to coincide with scheduled maintenance.But considering that stopping operations is often temporary and proactive, you can also choose to execute manually, or set it according to actual maintenance needs (for example, automatically stop before maintenance at a fixed time each month).If you are just to stop manually, you can choose an uncommon cycle, such as 'month', and then trigger it by clicking the execute button. - Script content: Paste the provided above
stop.shscript content into this text box.
【Key Customization Point】Be sure to check and modify the script in the
BINNAMEandBINPATHVariable.BINPATHThis should be the root directory of your AnQiCMS program, for example:/www/wwwroot/yourdomain.comYou can find the deployment path of your AnQiCMS in the "Files" management of the Baota panel.BINNAMEThis is the executable filename of AnQiCMS, usuallyanqicms. If you have renamed it during installation (for example, to distinguish multiple sites and namedanqicms_site1), please make sure to modify it synchronously.grep '\<anqicms\>'ofanqicmsalso withBINNAMEremain consistent.
For example, if your AnQiCMS is deployed in
/www/wwwroot/myanqicmsdirectory, the executable file name isanqicms_mainThen the corresponding part of the script should be modified to:#!/bin/bash ### stop anqicms # author fesion # the bin name is anqicms BINNAME=anqicms_main # <--- 修改为您的可执行文件名 BINPATH="/www/wwwroot/myanqicms" # <--- 修改为您的程序根目录 # check the pid if exists exists=`ps -ef | grep '\<anqicms_main\>' |grep -v grep |awk '{printf $2}'` # <--- 修改 grep 的匹配名 echo "$(date +'%Y%m%d %H:%M:%S') $BINNAME PID check: $exists" >> $BINPATH/check.log echo "PID $BINNAME check: $exists" if [ $exists -eq 0 ]; then echo "$BINNAME NOT running" else echo "$BINNAME is running" kill -9 $exists echo "$BINNAME is stop" fi- Click “Add Task”After completing the above configuration, click the button to save the task.
Executestop.shscript
When you need to stop the AnQiCMS service, just find the one you just created in the "Scheduled Tasks" list of the Baota panel, the