As an experienced CMS website operation personnel in the information security field, I am well aware of the importance of a stable and reliable deployment plan for the continuous operation of the website. Especially in the command-line environment,start.shandstop.shThis service management script is a key to keep AnQiCMS vibrant and respond to emergencies.They are not only responsible for starting and stopping services, but also quietly ensure the robustness of the system.Therefore, verifying that the configuration of these scripts is correct and effective is an essential step after deploying AnQiCMS.
Ensure the robustness of the service start and stop scripts
start.shandstop.shThe script plays a core role in the command line deployment of AnQiCMS.They are the guardians of the website service lifecycle, responsible for waking up the AnQiCMS process at system startup and smoothly closing it when necessary.An incorrectly configured or failed script can cause the website to fail to go live normally, fail to shut down gracefully, and even fail to automatically recover services after server restart, severely affecting the availability of the website.Therefore, it is the responsibility of website operators to carefully verify these two scripts to ensure the stable operation of the system.
Parse the script content and prepare in advance
Before we proceed with the verification, we need to understand the basic logic of these two scripts. According to the AnQiCMS deployment document,start.shThe main function of the script is to check if the AnQiCMS process exists, if it does not exist, then throughnohupCommand starts AnQiCMS main program in the background and redirects the runtime log torunning.log.stop.sh脚本则负责查找 AnQiCMS 进程的 PID(进程ID),然后通过 Englishkill -9命令强制终止进程。
Before starting the verification, please make sure that the following conditions are met:
- AnQiCMS executable file: Ensure that the binary executable file of AnQiCMS (default as
anqicms)Already exists in the specified path. - The script file exists:
start.shandstop.shThe file already exists in the installation directory of AnQiCMS. - File permissions: Ensure that these two scripts and
anqicmsExecutable files all have execution permissions (chmod +x start.sh stop.sh anqicms). - Path correctnessin the script
BINPATHThe variable should accurately point to the installation root directory of AnQiCMS. - Log files are writable:
running.logandcheck.logThe file (or its directory) should have write permissions to allow the script to record logs.
Verify individuallystart.shScript validity
What needs to be verified.start.shCan the script correctly start the AnQiCMS service? We need to perform a series of steps.
Navigate to the installation directory of AnQiCMS in the terminal first, and then execute manuallystart.shscript.
cd /www/wwwroot/your_anqicms_path # 替换为你的实际路径
./start.sh
After executing, please closely observe the terminal output, althoughnohupThe output will be redirected to the log file for most part, but there may still be some immediate feedback.
Next, check the log file generated by the script. First, look atcheck.logFile, it should record the execution time of the script and the check status of the AnQiCMS process. Then, viewrunning.log文件,这里应该有 AnQiCMS 服务启动过程中的详细日志输出。If the service starts successfully, there will usually be related information such as port listening and database connection.
Confirm the log is correct and then you need to verify if the AnQiCMS process is indeed running. You can usepsto check:
ps -ef | grep anqicms
If you see something similarroot 12345 ... /www/wwwroot/your_anqicms_path/anqicmsThe output indicates that the AnQiCMS process is running, and12345this is its PID.
Finally, verify the availability of the network access service. Open your browser and enter the access address configured by AnQiCMS (for examplehttp://your-domain.com:8001Or by configuring the domain through the reverse proxy), confirm that the website can be displayed normally. If the website can be accessed normally, it meansstart.shThe script has successfully started the AnQiCMS service.
Thorough verificationstop.shScript validity
For confirmationstart.shAfter the service starts normally, the next step is to verifystop.shwhether the script can correctly terminate the AnQiCMS process.
Similarly, navigate to the installation directory of AnQiCMS in the terminal, then manually executestop.shscript.
cd /www/wwwroot/your_anqicms_path # 替换为你的实际路径
./stop.sh
Check again after executingcheck.logThe file. It should recordstop.shScript execution time, as well as AnQiCMS process check and termination information.
Subsequently, usepsCommand to verify whether the AnQiCMS process has been terminated:
ps -ef | grep anqicms
If this timegrepthe command did not return any containinganqicmsresults (except forgrepits own process), then it indicates that the AnQiCMS process has been successfully closed.
To further confirm that the service has stopped, you can uselsofCommand check whether the port listened by AnQiCMS has been released. Assuming the default port of AnQiCMS is8001:
lsof -i:8001
If the command does not return any results, it means the port is no longer in use.
Finally, try to access your AnQiCMS website through the browser. Ifstop.shScript execution was successful, you should see error messages indicating connection failure or inaccessible, which means the AnQiCMS service has been successfully stopped.
Integrated Crontab validation strategy
The deployment of AnQiCMS usually combines Crontab to achieve automatic service monitoring and restart.Verify the effectiveness of Crontab integration, which is crucial for ensuring service resilience.
Firstly, ensure that you have alreadystart.shThe script is added to the Crontab, usually set to run every minute to achieve the functionality of a daemon. You can view the Crontab configuration with the following command:
crontab -l
Confirm it contains similar*/1 * * * * /www/wwwroot/anqicms.com/start.sh.
After adding the Crontab task, wait for one or two minutes, then check againcheck.logThe file timestamp. If the timestamp is the latest and it updates every minute, it indicates that Crontab is executing as expectedstart.shscript.
To simulate the situation where the service crashes unexpectedly, you can manually terminate the AnQiCMS process, but do not executestop.sh. For example, usingkill -9Command terminated before finding AnQiCMS process PID:
kill -9 [AnQiCMS进程的PID]
After manually terminating the process, wait for one minute and then use it againps -ef | grep anqicmsCheck command process list.如果 AnQiCMS 进程再次出现,并且 PID 与之前不同,则说明 Crontab 成功检测到服务停止并在下一周期自动重启了 AnQiCMS,这证实了 Crontab 守护进程的有效性。
Troubleshooting and common questions and answers
During verificationstart.shandstop.shThe process of the script may encounter some issues. The following are some common difficulties and their solutions.
One of the most common problems isPort is already occupiedIf AnQiCMS fails to start orrunning.logauto saw the port binding error, which is very likely because the default port (such as 8001) has been occupied by other programs. You can uselsof -i:{端口号}commands (for examplelsof -i:8001) to find the process occupying the port, then throughkill -9 {PID}Command to terminate the process, or modify the configuration file of AnQiCMSconfig.jsonChange its port to another unused port.
Another common issue isScript path or binary filename does not match.start.shandstop.shScript depends onBINPATHandBINNAMEvariables to locate the AnQiCMS executable file. If these variables are not properly configured, or you have changedanqicmsThe name of the executable file without the synchronization script, the script will not be able to find and manage the AnQiCMS process. Please check it carefully.start.shandstop.shin the fileBINPATHandBINNAMEIs it completely consistent with the actual deployment path and executable filename of your application?
In addition,Insufficient file permissionsIt may also cause the script to fail. Ifstart.shorstop.shScript does not have execution permissions, or the AnQiCMS log directory does not have write permissions. The script will not work properly or record logs. You should usechmod +x start.sh stop.sh anqicmsEnsure the script and binary files are executable, and usechmod -R 755 /path/to/anqicmsEnsure the log directory is writable.
Through the above detailed verification steps and troubleshooting methods, you should be able to comprehensively and effectively confirm AnQiCMS'sstart.shandstop.shThe script has been properly configured and can run reliably, providing stable content services for your website.
Common Questions (FAQ)
1. Why is it necessary to usestart.shandstop.shScript, rather than directly running the AnQiCMS binary file?
Directly running the AnQiCMS binary file can start the service, but the service will also terminate after the terminal closes.start.shScripts are usually usednohupThe command starts the service in the background, redirects its standard output and error output to a log file, ensuring that the service continues to run even after the terminal closes. At the same time, it combines with Crontab,start.shCan act as a daemon, automatically restarts when AnQiCMS stops unexpectedly, greatly improving the availability and stability of the website.stop.shAn English translation of this is: An English translation of this is: A standardized method was provided to smoothly terminate the service.
An English translation of this is: 2. How should I troubleshoot if AnQiCMS does not automatically start after the server restarts?
If AnQiCMS does not start automatically after the server restarts, the most common reason isstart.shThe script was not added correctly to the system startup items or Crontab tasks. First, please check your Crontab configuration (crontab -l),确保start.shThe script path is correct, and the scheduling frequency is sufficient (for example*/1 * * * *). In addition, you also need to confirmstart.shThe script itself has no errors, and the path and name of the AnQiCMS executable file are correctly configured in the script.Sometimes, there may be issues with dependent services (such as databases) not starting in time when the system restarts, which may also affect the normal startup of AnQiCMS.
3. I have changed the name of the AnQiCMS executable file (for example fromanqicmstomycms),need to updatestart.shandstop.shscript?
Yes, it is necessary.start.shandstop.shscript, make sure it points to the correct directory of the AnQiCMS executable file, and that the directory containsBINNAMEvariables andgrepThe command usually hard-codes the executable file name to locate and manage processes. If you change the name of the AnQiCMS executable file, you need to modify these two scripts accordingly.BINNAMEVariable, andgrep '\<anqicms\>'ofanqicmsReplace with a new executable file name (for examplegrep '\<mycms\>'). Otherwise, the script will not be able to correctly identify and control your AnQiCMS process.