Protect AnQi CMS: How to validate elegantlystart.shScript incrontabIs it working normally?
AnQiCMS (AnQiCMS) is an efficient content management system developed based on the Go language, which has won the favor of many small and medium-sized enterprises and content operators due to its easy deployment and fast operation. In order to ensure that your AnQiCMS site can run stably and continuously, even in the face of sudden situations or server restarts, we usually will start and guard the core program responsible for starting and maintaining the program.start.shConfigure the script to the Linux system's scheduled taskcrontab.
However, merely adding the script tocrontabIt does not mean everything is fine.
As an experienced website operation expert, I fully understand the importance of verification work. This article will delve into how to systematically checkstart.shScript incrontabIs the configuration truly effective, ensure that your security CMS is always online.
Understand the "Guardian":start.shwithcrontabCollaborative work
Before we delve into verification, it is necessary to understand first.start.shThe working principle of the script and its interaction withcrontab.
According to the AnQiCMS deployment document,start.shThe script is designed very cleverly, it does not simply start the AnQiCMS program, but will undergo a 'physical examination' before it starts:
# check the pid if exists
exists=`ps -ef | grep '\<anqicms\>' |grep -v grep |wc -l`
...
if [ $exists -eq 0 ]; then
echo "$BINNAME NOT running"
cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &
fi
This core code indicates,start.shIt will first check if the process namedanqicmsis running. If the process does not exist(exists -eq 0), it will truly executenohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &the command to start AnQiCMS and redirect all output torunning.logfile, running in the background.
AndcrontabThe function is to call this at the time interval you set (usually once a minute, for example)*/1 * * * * ...), call this at regular intervals.start.shScript. So, even if the AnQiCMS program crashes unexpectedly,crontabit will detect that it is not running in the next minute and will automatically restart, thus achieving the "guard" effect. At the same time,start.shIt will also record a brief information of each check and startup attempt.check.log.
Understanding this, our verification work has a clear direction.
Verification journey: Step by step to confirm effectiveness.
Next, we will verify in detail through a series of stepsstart.shScript incrontabof the running status
First step: ConfirmcrontabThe existence and correctness of the task itself
Firstly, we need to checkcrontabDid you really addstart.shthe script task and is the path correct.
You can list all scheduled tasks of the current user by enteringcrontab -lcommands in the terminal. If your task is torootThe user configured, it may be necessary to usesudo crontab -l.
Carefully check the output results to ensure that it contains something similar to*/1 * * * * /www/wwwroot/anqicms.com/start.sh(Please adjust the entry according to your actual installation path).If the path is incorrect, AnQiCMS will not be guarded correctly.crontab -eEnter the editing interface to correct
Second step: CheckcrondThe running status of the service
crontabThe execution of the task depends oncrond(orcron) service. If this service is not running, then your scheduled task will not be executed naturally.
You can use the following command to checkcrondthe status of the service:
- For Systemd systems (such as CentOS 7+, Ubuntu 16.04+):
systemctl status cronorsystemctl status crond - For SysVinit systems (such as CentOS 6):
service cron statusorservice crond status
Ensure that the service status is displayed asactive (running)Or similar. If the service is not running, you need to start it, for example:sudo systemctl start cron.
Step 3: Reviewstart.shScript execution log
This is verificationcrontabWhether the call was successfulstart.shthe most direct evidence.start.shThe script will output a brief log of each execution tocheck.logthe file.
Go to the installation directory of your AnQiCMS undercheck.logfile (for example/www/wwwroot/anqicms.com/check.log), usingtail -f check.logCommand to view the content of the file in real time:
tail -f /www/wwwroot/anqicms.com/check.log
You should be able to see a new log entry added every minute, displaying:anqicms PID check:This indicates:crontabIndeed, it is calling at regular intervals:start.shscript. IfexistsThe value shows as0This means that the AnQiCMS program was not running when the check was performed, and the script tried to start it; if it shows as1This indicates that AnQiCMS is running normally.
Step 4: Verify the survival status of the AnQiCMS process
Just knowcrontabThe script has been called, but we still need to confirm whether the AnQiCMS program itself is really running.
You can useps aux | grep anqicmscommand to view all processes related toanqicms: related processes:
ps aux | grep anqicms
In the output results, you should be able to find one or moreanqicmsprocesses, and their status should beRunning. If you only seegrep anqicmsitself, it means that the AnQiCMS program has not started.
Additionally, since AnQiCMS usually listens on a specific port (default as 8001),You can also verify that the program is providing services to the outside world by checking the usage of the port:
lsof -i:8001
If the command returns process information listening to the port, and the process name isanqicmsThis means that AnQiCMS is running and listening for network requests. If the return result is empty, or the process is notanqicmsThere may be a port conflict or the program has not started.
Step 5: Insight into AnQiCMS runtime logs
Ifcheck.logThe script is called,ps auxThe process is running, but the website still cannot be accessed, which may be that AnQiCMS itself encountered a problem when starting up. At this time,running.logit becomes our 'diagnosis'.
start.shThe script will redirect both the standard output and error output of the AnQiCMS program torunning.logfile (for example/www/wwwroot/anqicms.com/running.log)
Usetail -f running.logCommand to view the contents of the file:
tail -f /www/wwwroot/anqicms.com/running.log
This records the detailed information during the startup and operation of AnQiCMS.Any startup failure messages, such as database connection issues, configuration errors, insufficient permissions, etc., will be displayed here.By analyzing these logs, you can locate and solve the problems of the AnQiCMS program itself.
Step 6: Simulate a fault to verify the automatic recovery mechanism (optional but strongly recommended)
This is correctcrontabThe most strict test of the guard function. We will manually terminate the AnQiCMS process and then observecrontabWhether it can restart automatically within one minute
- First, use
ps aux | grep anqicmsFindanqicmsProcess ID (Process ID). - Then, use
kill -9 [PID]command to forcibly terminate the process. - Wait for about a minute and then execute again.
ps aux | grep anqicms. If everything is normal, you will find that the AnQiCMS process has reappeared andcheck.logthere will be an entry displayingexists -eq 0and then there will be an attempt to start the record.
If the program fails to restart automatically, you need to check it carefullystart.shThe logic, execution permissions, andcrontabconfiguration.
Final verification: directly access your AnQiCMS website
After all technical validations are completed, the most direct way to verify is to access your AnQiCMS website domain directly in the browser. If the website can load normally and function smoothly, that meansstart.shscripts andcrontabThey have successfully completed their guardianship mission.
By following these comprehensive verification steps, you will be able to understand AnQiCMS thoroughly and deeply.start.shScript incrontabThe status of the operation, ensure that your website has a stable and reliable automatic operation and fault recovery capability.
Frequently Asked Questions (FAQ)
1. Why mystart.shScript incrontabHas run (check.logThere are records), but the website still hasn't started?
This usually meanscrontabSuccessfully calledstart.shHoweverstart.shFailed to start the command for AnQiCMS internally. Possible reasons include:
- Port conflict: