How does the startup script ensure that AnQiCMS automatically restarts after an unexpected stop?

Calendar 👁️ 69

AnQiCMS is a modern content management system developed based on the Go language, and its stability and high availability are the core guarantees of website operation.In the operation of a website, the background service process may unexpectedly stop due to various unpredictable reasons, such as exhaustion of system resources, program errors, external attacks, etc.To ensure the continuity of the website service, AnQiCMS has designed an automated mechanism to monitor and restart its core processes.

The core of this automatic reboot mechanism lies in the system scheduling tasks configured on the Linux server (usually throughcrontabservice implementation) and a specially designed startup scriptstart.shCollaborative work. In this way, AnQiCMS achieves self-monitoring and fault recovery capabilities.

The principle of AnQiCMS automatic restart implementation

When AnQiCMS process stops unexpectedly, its automatic restart feature mainly depends on the following steps and components:

First, on the server'scrontabThe scheduled task is configured to periodically execute a specific script file. According to the AnQiCMS deployment documentation, the script is usually located in the application installation directory.start.shThe most common configuration is to letcrontabExecute this every minutestart.shscript to ensure the system can quickly respond to any process interruption.

secondly,start.shThe script contains the logic to check the running status of the AnQiCMS main program and trigger a restart if necessary. The script usually defines two key variables:BINNAMEandBINPATH.BINNAMEIs the executable file name of AnQiCMS (default asanqicms),whileBINPATHIt is the installation path of AnQiCMS. The introduction of these variables makes the script highly configurable, convenient for users to adjust according to actual deployment situations.

The script is executed throughps -ef | grep '\<anqicms\>' | grep -v grep | wc -lThis command is used to check if the AnQiCMS process is running. The working principle of this command is:ps -efIt will list all the running processes on the system,grep '\<anqicms\>'Filter out process lines containing the word "anqicms"(\<and\>Ensure that the match is a complete word to avoid affecting other processesgrep -v grepThen it will filter outgrepCommand its own process to prevent interference, finallywc -lCount the number of lines matched, i.e., the number of AnQiCMS processes.

If the script detects that the number of AnQiCMS processes is 0, that isexists -eq 0then it indicates that the AnQiCMS program has stopped running. In this case,start.shthe startup command will be executed immediately:cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &. This command is used to:

  1. cd $BINPATH: First, switch to the AnQiCMS installation directory to ensure the program can start in the correct environment.
  2. nohup $BINPATH/$BINNAME: Use.nohupCommand to start the AnQiCMS executable file.nohupThe function is to allow the program to run in the background, and it will not stop even after the user logs out or closes the terminal.
  3. >> $BINPATH/running.log 2>&1Redirects the program's standard output (stdout) and standard error (stderr) torunning.logIn the file. This is very important for subsequent fault diagnosis and running status monitoring.
  4. &Finally, put the entire startup command into the background to run, not occupying the currentcrontabprocess resources.

BycrontabA periodic check every minute, AnQiCMS can achieve nearly real-time process monitoring and automatic repair. Once the main program is unexpectedly terminated, the scheduled task will detect this situation within at most one minute and execute immediatelystart.shThe script restarts the service. This mechanism greatly enhances the reliability and stability of the AnQiCMS website, minimizing service downtime and ensuring the continuous availability of website content.


Frequently Asked Questions (FAQ)

Q1: If the AnQiCMS process stops unexpectedly and the restart script fails to start the program, how should I troubleshoot?A1: If the script restart fails to start AnQiCMS, first you should checkrunning.logThe file records the output and any error information of the AnQiCMS program when it starts, these logs are crucial for diagnosing the cause of startup failure.Common failure reasons may include port occupation, database connection issues, insufficient file permissions, or configuration file errors, etc.You can still manually execute it in the command linecd $BINPATH && $BINPATH/$BINNAMEtry to start it and observe the detailed error information output by the terminal.

Q2: Can I install multiple AnQiCMS instances on a single server and use the automatic restart feature for all of them?A2: Yes, AnQiCMS supports installing multiple instances on a single server and configuring automatic restarts for each instance.Each AnQiCMS instance requires a separate port.When configuring, you need to create a separate installation directory for each instance and modify itsconfig.jsonFiles are specified with different ports and modifiedstart.shin the scriptBINNAMEAnd if the executable file has been renamedBINPATHThe variable should match the actual path of the instance. Finally, add a separate scheduled task entrycrontabfor each instance, pointing to its respectivestart.shscript.

Q3: Can the frequency of the automatic restart check be adjusted? If I want it to check every five minutes instead of every minute, how should I set it?A3: The frequency of automatic restart check is fully configurable. It is determined bycrontabthe time expression in the scheduled task. To adjust the check frequency from every minute to every five minutes, you need to editcrontabConfigure (for example bycrontab -ecommand), find the line corresponding to the AnQiCMS startup script.*/1 * * * *is modified to*/5 * * * *Just do it.*/5Indicates every 5 time units, i.e., every 5 minutes. Please set this frequency reasonably based on your needs for service recovery speed and the use of server resources.

Related articles

Why does the AnQiCMS startup script use `ps -ef | grep | wc -l` to check the PID?

As an experienced CMS website operation personnel of an enterprise, I know that the stable operation of the system is of great importance to content publishing and user experience.AnQi CMS, with its high efficiency, lightweight, and easy deployment features, has won the favor of many small and medium-sized enterprises and content operation teams.However, even the most excellent system needs a reliable startup and maintenance mechanism to ensure its continuous online operation.Among them, the `ps -ef | grep | wc -l` command used in the startup script to check the PID, although it looks a bit complex, it is the key to ensuring the stable operation of the Anqi CMS.

2025-11-06

How to determine if the AnQiCMS process is running on the server?

As an expert who deeply understands the operation of AnQiCMS, I am well aware of the importance of stable system operation for website business.Determine whether the AnQiCMS process is running normally on the server, which is a basic and crucial task in daily operations.It is crucial to accurately grasp the process status, whether it is to investigate website access failures or to confirm whether the scheduled tasks are effective.

2025-11-06

What is the real meaning of checking if the PID exists in the AnQiCMS startup script?

As an experienced security CMS website operations personnel, I know that the logic behind each system component is crucial for the stable operation and efficient management of the website.The startup script serves as the starting point of the application lifecycle, its design often embodies considerations for system robustness and operational convenience.Now, let's delve into the true significance of the "check if PID exists" section in the Anqi CMS startup script.

2025-11-06

Install AnQi via Docker on aaPanel

Anq CMS is an enterprise-level content management system based on the Go language, designed to provide an efficient, customizable and easy-to-expand content management solution.As a website operator familiar with content creation and optimization, I understand how important a stable and efficient system is.This article will give a detailed introduction on how to use the Docker function of the aaPanel to quickly deploy the Aq CMS, helping you build and start your website efficiently.

2025-11-06

What are the potential risks and alternatives for `kill -9 $exists` in the AnQiCMS shutdown script?

As a professional who deeply understands the operation of AnQiCMS, I know that the stability of the content system and data security are the foundation of website operation.In the daily operation and maintenance of AnQiCMS, we often encounter scripts for starting and stopping services.Among them, the command `kill -9 $exists` can quickly terminate the process when stopping the AnQiCMS service, but its potential risks should not be overlooked.Understanding these risks and adopting appropriate alternatives is crucial for ensuring the robust operation of the website.

2025-11-06

What are the key information about PID recorded in AnQiCMS's `check.log` file?

As an experienced CMS website operation personnel of an enterprise, I am well aware of the importance of system log files in maintaining the stable operation of the website.In the daily operation and maintenance of AnQiCMS, the `check.log` file plays an indispensable role. It records detailed information about the core process (PID) of the application, providing valuable clues for us to understand the system status and carry out fault troubleshooting.

2025-11-06

If `start.sh` shows that AnQiCMS is running but the website is inaccessible, how should I troubleshoot?

As an experienced CMS website operation person, I know the anxiety and unease when the system runs on the surface but the website cannot be accessed.This usually means there is a break between backend services and frontend access.In the case where `start.sh` shows that AnQiCMS is running but the website cannot be accessed, we need to investigate systematically.This is not just checking the service itself, but also needs to review the server environment, network configuration, and the core settings of AnQiCMS.

2025-11-06

How to effectively manage the PIDs of multiple AnQiCMS instances?

As a professional who has been deeply involved in website operations and has extensively used AnQiCMS (AnQiCMS), I am well aware of the importance of efficiently managing multiple content platforms in an increasingly complex network environment.How to effectively manage the process identifier (PID) of each instance when the business develops to the point where it needs to operate multiple independent sites simultaneously, or to deploy multiple sets of AnQiCMS instances for performance, isolation, and other requirements, has become a key factor in ensuring system stability and maintenance efficiency.

2025-11-06