As a website manager who is well-versed in the operation of AnQiCMS, I know the importance of system stability for content publishing and user experience.In daily operations, even well-designed systems may encounter unexpected situations, leading to core process interruption.start.shScript, effectively solves this problem, ensuring the continuous availability of the service.
start.sh
The implementation of this automatic pull-up mechanism mainly relies on two key links:Periodic inspectionandSmart restart.
Firstly,Periodic inspectionIt is realized through the system-level timing task service (such as the one in the Linux system),cron) during the installation process of AnQiCMS, the documents clearly indicate that it is necessary tostart.sh脚本添加到一个每分钟执行一次的crontab任务中。这意味着,每隔一分钟,操作系统都会自动执行一次start.shScript, perform a "health check" on the AnQiCMS process.
Whenstart.shThe script will first use a set of precise command combinations to detect if the AnQiCMS main program is running. Specifically, the script will callps -efCommand lists all processes currently in the system, then throughgrep '\<anqicms\>'Filter out the process lines that have the executable file name of AnQiCMS exactly matching. To avoidgrepThe command itself is also misjudged as AnQiCMS process, the script will further usegrep -v grepExclude it.grepprocess. Finally,wc -lThe command counts the number of lines in the filtered results, this number represents the number of running AnQiCMS process instances.The script stores this quantity in a variable and records the check time and result for later log audit.
Then isSmart restartphase. After completing the process status detection, the script will according toanqicmsProcess instance count is determined. If the detected process count is zero (i.e.$exists -eq 0),这意味着 AnQiCMS 服务已经终止运行。此时,脚本会立即采取行动。它首先会切换到 AnQiCMS 的安装目录 (cd $BINPATH),to ensure that the program can start correctly and can load its configuration file and dependent resources. Subsequently, it will executenohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &command to start AnQiCMS.
This boot command includes several important elements:nohupEnsure that the AnQiCMS process continues to run in the background without being affected by user logout or terminal closure after startup;$BINPATH/$BINNAME是指向 AnQiCMS 可执行文件的完整路径,确保了程序的正确执行;>> $BINPATH/running.log 2>&1Then, redirect the standard output and standard error of the program torunning.logIn the file, it is convenient to record program execution logs and debugging, and also prevents the output information from interfering with the terminal; the last,&Symbol runs the entire command in the background, allowing the script itself to end immediately without waiting for the AnQiCMS process to start.
Through this mechanism of 'check every minute, start immediately if not running', what is AnQiCMS doing?start.sh脚本提供了一个简单而高效的自愈能力。Whether due to system resource exhaustion, code abnormal crash or other unforeseeable reasons leading to the interruption of AnQiCMS process, this guard script can identify and automatically recover the service in a short time, which minimizes the downtime of the website and ensures the continuity of user access and content operation.
Common Questions (FAQ)
Whystart.shscript needs to be added tocrontab, rather than running it once directly?
start.shThe design purpose of the script is to continuously monitor the AnQiCMS process.If it runs only once, it can only check and start a process once, and cannot restart it again if the process terminates unexpectedly afterwards.crontabEvery minute executes,start.shthe script can realize its guardian process, automatic recovery function, and ensure the stability of the system throughout its operation cycle.
AnQiCMS process isstart.shAfter pulling up, will data be lost?
start.shThe script is only responsible for starting the AnQiCMS process, it will not directly operate or modify the website's data.AnQiCMS as a content management system, its data is usually stored in a database and loaded when the program starts.If the process is unexpectedly terminated and restarted, as long as the database remains intact, it usually will not cause data loss.start.shis irrelevant to the process management function.
Ifstart.shWhat should I do if the script starts multiple AnQiCMS processes?
start.shBefore starting a new process, the script will go throughps -ef | grep '\<anqicms\>' | grep -v grep | wc -lExactly check if there is a process namedanqicms. Only when this count is0When, it will execute the start command only when there is no AnQiCMS process running.Therefore, this script can effectively avoid repeated startup and ensure that multiple AnQiCMS instances will not conflict with each other.