How to verify that the `start.sh` and `stop.sh` scripts are configured correctly and valid when deploying AnQiCMS via the command line?
As a senior security CMS website operations personnel, I fully understand 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 the key to keeping AnQiCMS vital and responding to emergencies.They are not only responsible for starting and stopping services, but also quietly ensure the robustness of the system in the background.Therefore, verifying that the configuration of these scripts is correct and valid is an indispensable 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 lifecycle of the website service, responsible for waking up the AnQiCMS process at system startup and smoothly shutting it down when needed.A misconfigured or failed script can cause the website to fail to go online normally, fail to shut down gracefully, and even fail to automatically restore services after server restart, seriously affecting the availability of the website.Therefore, it is the responsibility of website operators to carefully verify these two scripts to ensure stable system operation.
Script content parsing and preperation
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 script's main function is to check if the AnQiCMS process exists, and if it does not exist, then pass throughnohupThe command starts AnQiCMS main program in the background and redirects the runtime log torunning.log.stop.shThe script is responsible for finding the PID (Process ID) of the AnQiCMS process and then throughkill -9the command to force terminate the process.
Before starting the verification, please ensure 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. - Script file exists:
start.shandstop.shThe file already exists in the installation directory of AnQiCMS. - File permissions: Ensure that these two scripts and
anqicmsAll executable files have execute permission (chmod +x start.sh stop.sh anqicms) - Path accuracy: In the script
BINPATHThe variable should accurately point to the root directory of AnQiCMS installation. - Log file is writable:
running.logandcheck.logThe file (or its directory) should have write permission so that the script can record logs.
Verify one by onestart.shScript validity
To verifystart.shCan the script correctly start the AnQiCMS service, we need to perform a series of steps.
First, navigate to the installation directory of AnQiCMS in the terminal and then manually executestart.shscript.
cd /www/wwwroot/your_anqicms_path # 替换为你的实际路径
./start.sh
After execution, please closely observe the terminal output, althoughnohupRedirect most of the output to the log file, but there may still be some immediate feedback.
Next, check the log file generated by the script. First, look atcheck.logThe file should record the execution time of the script as well as the check status of the AnQiCMS process. Then, viewrunning.logFile, there should be detailed log output during the startup process of the AnQiCMS service.If the service starts successfully, there will usually be port listening, database connection and other related information.
After confirming that the log is correct, you need to verify whether the AnQiCMS process is indeed running. You can usepscommand to 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 and12345its PID is.
Finally, verify the availability of the service via network access. Open your browser and enter the access address configured for AnQiCMS (for examplehttp://your-domain.com:8001Or through the reverse proxy configuration domain), confirm that the website can be displayed normally. If the website can be accessed normally, it indicatesstart.shThe script has successfully started the AnQiCMS service.
Thorough verificationstop.shScript validity
After confirmationstart.shAfter the service starts normally, the next step is to verifystop.shCan the script correctly terminate the AnQiCMS process.
Similarly, navigate to the installation directory of AnQiCMS in the terminal and manually executestop.shscript.
cd /www/wwwroot/your_anqicms_path # 替换为你的实际路径
./stop.sh
Check again after executioncheck.logfile. It should recordstop.shThe execution time of the script, as well as the check and termination information of the AnQiCMS process.
Then, usepsCommand to verify if the AnQiCMS process has been terminated:
ps -ef | grep anqicms
If thisgrepcommand did not return any containinganqicmsresults (exceptgrepits own process), it means the AnQiCMS process has been successfully closed.
To further confirm that the service has stopped, you can uselsofCommand check if the listening port of 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 occupied.
Finally, try to access your AnQiCMS website via the browser. Ifstop.shThe script executed successfully, you should see error messages indicating a connection failure or inability to access, which means the AnQiCMS service has been successfully stopped.
Integrating Crontab and verification strategy afterwards
The deployment of AnQiCMS usually combines Crontab to achieve automatic monitoring and restart of services.Verify whether the Crontab integration is effective, which is crucial for ensuring service resilience.
First, make sure you have alreadystart.shScript 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 that it contains similar*/1 * * * * /www/wwwroot/anqicms.com/start.sh.
After adding the Crontab task, wait a minute or two, and then check againcheck.logThe file timestamp. If the timestamp is the latest and updates every minute, it indicates that the Crontab is running as expectedstart.shscript.
To simulate the situation of a service crash, you can manually terminate the AnQiCMS process but do not executestop.shFor example, usekill -9The process PID of AnQiCMS found before the command is terminated:
kill -9 [AnQiCMS进程的PID]
After manually terminating the process, wait for one minute and use it againps -ef | grep anqicmsCheck the process list command. If the AnQiCMS process appears again and the PID is different from the previous one, it indicates that Crontab successfully detected the service stop and automatically restarted AnQiCMS in the next cycle, which confirms the effectiveness of the Crontab daemon process.
Troubleshooting and common issues solutions
During verificationstart.shandstop.shDuring the script process, some problems may occur. The following are some common difficulties and their solutions.
One of the most common problems isThe port is already occupiedIf AnQiCMS fails to start or atrunning.logError binding port, it is likely because the default port (such as 8001) is already occupied by another program. You can uselsof -i:{端口号}commands (for examplelsof -i:8001) to find the process occupying the port, and thenkill -9 {PID}Command to terminate the process or modify the AnQiCMS configuration fileconfig.jsonChange its port to another unoccupied port.
Another common issue isThe path or binary filename in the script does not match.start.shandstop.shThe script depends onBINPATHandBINNAMEvariables to locate the AnQiCMS executable file. If these variables are not configured correctly, or if you have changedanqicmsThe name of the executable file without the sync update script, the script will not be able to find and manage the AnQiCMS process. Please check it.start.shandstop.shin the fileBINPATHandBINNAMEIs it consistent with the actual deployment path and executable file name of your project.
Furthermore,Insufficient file permissionsMay also cause the script to fail. Ifstart.shorstop.shThe script does not have execution permissions, or the AnQiCMS log directory does not have write permissions, the script will not work normally or record logs. You should usechmod +x start.sh stop.sh anqicmsEnsure the command makes the script and binary files executable, and useschmod -R 755 /path/to/anqicmsEnsure the log directory is writable.
By following the above detailed verification steps and troubleshooting methods, you should be able to comprehensively and effectively confirm AnQiCMS'sstart.shandstop.shThe script is correctly configured and can run reliably, providing stable content services for your website.
Frequently Asked Questions (FAQ)
1. Why do we need to usestart.shandstop.shScript, rather than directly running the AnQiCMS binary file?
Run the AnQiCMS binary file directly can start the service, but after the terminal is closed, the service will also be terminated.start.shScripts usually usenohupThe command starts the service in the background and redirects its standard output and error output to a log file, ensuring that the service continues to run even after the terminal is closed. Additionally, combined with Crontab,start.shCan act as a daemon, automatically restarting AnQiCMS when it stops unexpectedly, greatly improving the availability and stability of the website.stop.shIt provided a standardized way to terminate the service smoothly.
2. How should I troubleshoot if AnQiCMS does not automatically start after the server restarts?
If AnQiCMS does not automatically start after the server restart, the most common reason isstart.shThe script was not added correctly to the system's startup item or Crontab task. First, please check your Crontab configuration (crontab -l) to ensurestart.shThe script path is correct and the scheduling frequency is sufficient (for example*/1 * * * *). Additionally, 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, when the system restarts, there may be issues with dependent services (such as databases) not starting in time, which may also affect the normal startup of AnQiCMS.
3. I changed the name of the AnQiCMS executable file (for example fromanqicmschanged tomycmsNeed to updatestart.shandstop.shIs this script?
Yes, it is necessary.start.shandstop.shin the scriptBINNAMEvariables andgrepCommands are usually hard-coded to find and manage executable file names. If you change the name of the AnQiCMS executable, you need to modify these two scripts accordingly.BINNAMEVariable, andgrep '\<anqicms\>'ofanqicmsReplace with a new executable filename (for examplegrep '\<mycms\>'). Otherwise, the script will not be able to correctly identify and control your AnQiCMS process.