How to use the stop script `stop.sh` written by author fesion in AnQiCMS?
AnQiCMS (AnQiCMS) is an efficient and feature-rich Go language content management system, its stable operation is inseparable from fine deployment and management.As a website operator, we not only need to pay attention to content creation and optimization, but also ensure the smooth operation of the system backend.In this case, stop the scriptstop.shPlaying a crucial role, it can help us manage the lifecycle of AnQiCMS services safely and effectively.
Stop the scriptstop.shits core function
stop.shThe main function of the script is to terminate the running process of the AnQiCMS application on the Linux system.In order to carry out system maintenance, version upgrades, or to adjust the configuration, we need a reliable way to stop the running service.This script provides a standardized, command-line friendly way to achieve this goal, avoiding the繁琐 and potential errors of manually searching for the process ID (PID) and forcibly terminating.By executingstop.shEnsure that the AnQiCMS service is shut down orderly, making space for subsequent operations.
Get to know in-depthstop.shThe working principle of the script
stop.shThe script is a simple Bash script whose core logic is to find and terminate the AnQiCMS service process. The script contains several key variables and commands that together complete the stop task:
first, BINNAMEThe variable defines the name of the AnQiCMS executable file, the default beinganqicms. This name is crucial for the script to identify the target process.
secondly,BINPATHthe variable through$( cd "$( dirname "$0" )" && pwd )Command dynamically obtain the directory where the script is located, ensure that the script can be executed correctly at any location, and find the executable files and log files of AnQiCMS.
The script is then used.ps -ef | grep '\<anqicms\>' | grep -v grep | awk '{printf $2}'Combine commands to find the process ID of AnQiCMS.
ps -efList all running processes.grep '\<anqicms\>'Filter out lines containing "anqicms" (note\<and\>Make sure to match the complete word and not a partial match)grep -v grepexcludegrepCommand its own process to avoid killing by mistake.awk '{printf $2}'Extract the second field of the process line, which is the process ID.
If the AnQiCMS running process is found (that isexistsIf the variable is not 0), the script will use it.kill -9 $existscommand to forcibly terminate the process.kill -9is a force kill command, meaning it will immediately terminate the process without giving the process a chance to perform cleanup operations.Although this method is usually effective, in some cases, if AnQiCMS is processing critical data, it may lead to data inconsistency.However, from the documents provided by AnQiCMS,stop.shThe default method adopted is to directly terminate.
In AnQiCMS deployment applicationstop.sh
stop.shThe script plays a role in various AnQiCMS deployment scenarios:
InBaota panelin the environment,stop.shCommonly configured as a scheduled task, for example, to run once a month, as part of maintenance or restart procedures. Operators can add a Shell script task by selecting the Scheduled Task interface on the Baota panel, and thenstop.shPaste the content in and set the appropriate execution cycle. Although the document shows it is executed monthly, in practice, we may do it more often withstart.shCooperation, used to manually restart the service when needed.
For those who passCommand lineDeployed AnQiCMS instance,stop.shThe usage is more direct. Just execute through the terminal in the AnQiCMS installation directory../stop.shCommand to stop the service. This is very useful for scenarios that require manual service management or writing automation deployment scripts.
When a server has been deployed onMultiple AnQiCMS sitesthen,stop.shThe flexibility is particularly important. If each AnQiCMS instance has a different executable file name (for example, to distinguish different sites), we need to modify it accordingly.stop.shwithin the scriptBINNAMEThe variable makes it match the executable filename of a specific instance.This ensures that we can accurately stop the target site without affecting other AnQiCMS instances that are running.
InSystem UpgradeDuring the process, especially when upgrading from AnQiCMS 2.x version to 3.x version, the document also mentioned stopping the project first using the scheduled task (i.e., runningstop.sh), then delete the old scheduled task and deploy with a new Go project. This indicatesstop.shIt is a standardized step in the upgrade process, used to ensure that the old service is completely shut down so that the new version can start smoothly.
Key considerations and operational suggestions
Usestop.shAt this point, as a website operator, we need to pay attention to the following points:
first, BINNAMEThe accuracy of variables is crucial. If the executable file of AnQiCMS is renamed, it must be updated synchronously.stop.shin the scriptBINNAMEOtherwise, the script will not be able to find and stop the correct process.
secondly,stop.shPrimarily designed for Linux environments. ForWindows systemIt is explicitly stated in the AnQiCMS documentation that there is nostop.shscript, the user needs to manually terminate through the Windows Task Manageranqicms.exeprocess. Therefore, when deploying across platforms, it should be understood that there are these differences
Finally, executestop.shafterwards, we should go throughps -ef | grep '\<anqicms\>' | grep -v grepCheck again to make sure the AnQiCMS process has indeed stopped. This is a good operational habit that can avoid service anomalies caused by script execution failure.
In summary,stop.shThe script is an indispensable part of the AnQiCMS service management toolbox.It simplifies the operation of stopping services, improves operational efficiency, and provides the necessary flexibility in multi-site and upgrade scenarios.Mastering its usage and precautions will make the daily management of AnQiCMS smoother and safer.
Frequently Asked Questions (FAQ)
stop.shCan the script be used on Windows system?No. According to the official documentation of AnQiCMS,stop.shThe script is designed for the Linux environment. On Windows systems, you need to manually terminate the process by finding it in the Task Manager.anqicms.exeto stop the service.
If I change the executable file name of AnQiCMS (for example, fromanqicmschanged tomysite)stop.shcan it still work?it will not work directly. You need to editstop.shthe script file, changing its internalBINNAMEThe value of the variable is updated to the new executable filename (for example,BINNAME=mysite), to ensure that the script can correctly identify and stop your AnQiCMS instance.start.shThe script also needs to be modified in the same way.
Executestop.shHow to confirm that the AnQiCMS service has stopped?In the Linux terminal, you can useps -ef | grep '\<anqicms\>' | grep -v grepcommand (please replaceanqicmsReplace your actual executable filename to check if there is still an AnQiCMS process running.If no output is displayed, it means that the AnQiCMS service has been successfully stopped.