`start.sh` script can be integrated with more advanced process monitoring tools (such as `Monit` or `Supervisor`)?

Calendar 👁️ 62

As a long-term professional responsible for the operation of AnQiCMS website, I am well aware that stable and efficient system operation is crucial for content publishing and user experience.The AnQi CMS has won the favor of users with its high-performance and concise architecture developed in Go language.In deployment and daily operation and maintenance, we often encounter a problem: how to ensure the continuous and stable operation of the AnQiCMS application, especially when facing unexpected crashes or server restarts.

AnQiCMSstart.shThe operation mechanism and limitations of the script

The deployment guide of AnQi CMS provides a script namedstart.shscript, whose core function is to check the AnQi CMS main program (usually}anqicmsIs the binary file running. If the program is not running, the script will proceed throughnohup /path/to/anqicms >> /path/to/running.log 2>&1 &The command starts AnQiCMS in the background and redirects the output to a log file. To achieve the automatic monitoring of the process, we usually configure thestart.shscript tocrontabIn order to execute it once a minute, it is used to detect and restart the AnQiCMS process that may have stopped.

This is based oncrontabandstart.shThe guard mode is simple and easy to use, which is enough to deal with small sites or development environments, but it has obvious limitations in production environments. First,start.shOnly by checking if the process ID exists can we determine if the program is running. It cannot recognize the situation where the program exists but is in a 'zombie' state, unresponsive, or internally crashed. Secondly,crontabThe minimum execution cycle is usually one minute, which means that once AnQiCMS fails, the system needs to wait up to one minute to detect and attempt to restart, during which the service interruption will have a negative impact on user experience and SEO. In addition,start.shLack of log rotation, resource monitoring, dependency service checking, and other advanced features makes fault troubleshooting and system maintenance complex.

The necessity of introducing advanced process monitoring tools

To enhance the availability, stability, and manageability of AnQiCMS in the production environment, simply rely onstart.shThe script is far from enough.We need to introduce a more professional and intelligent process monitoring tool.These tools can monitor the health of applications in real time, not just the existence of the process; they can automatically restart the program immediately when it crashes, significantly shortening the service downtime; at the same time, they also provide rich configuration options, supporting resource limitations, log management, startup sequence of dependent services, web management interface, and other functions, greatly simplifying the operation and maintenance work.

For example,MonitandSupervisorThese are two widely popular process monitoring tools, each with its own features and advantages, but they can all effectively replacecrontabandstart.shThe combination provides AnQiCMS with stronger guardian capabilities.

Integration with Supervisor

SupervisorIt is a client/server system written in Python that allows users to monitor and control a large number of processes on Unix-like operating systems.It is a lightweight, feature-rich process manager, very suitable for managing single-instance applications like AnQiCMS.

To integrate AnQiCMS withSupervisorIntegration, first make sure that the server on which you are installing is installedSupervisor. Then, you can define the service of AnQiCMS by creating a new configuration file.

The following is the typical configuration steps for integrating AnQiCMS toSupervisor:

  1. Stop and remove the existingcrontabtask:This is the critical first step. You need to editcrontab(crontab -eDelete all related withstart.shandstop.shscheduling tasks to avoid conflicts.

  2. Create a Supervisor configuration file:In/etc/supervisor/conf.d/in the directory (or youSupervisorConfigure a new location (specified) to create.confa file, for exampleanqicms.conf. The content of the file is roughly as follows:

    [program:anqicms]
    command=/path/to/anqicms          ; AnQiCMS二进制文件的完整路径
    directory=/path/to/anqicms_root   ; AnQiCMS项目的根目录,包含config.json
    autostart=true                    ; Supervisor启动时自动启动AnQiCMS
    autorestart=true                  ; AnQiCMS异常退出时自动重启
    startretries=3                    ; 启动失败后尝试重启的次数
    user=www                          ; 运行AnQiCMS的用户,建议使用非root用户
    stopsignal=QUIT                   ; 发送QUIT信号给Go程序进行优雅关停
    stdout_logfile=/var/log/anqicms/anqicms_stdout.log ; 标准输出日志路径
    stderr_logfile=/var/log/anqicms/anqicms_stderr.log ; 错误输出日志路径
    stdout_logfile_maxbytes=10MB      ; 日志文件最大大小
    stdout_logfile_backups=5          ; 日志文件备份数量
    ; environment=ANQICMS_PORT="8001" ; 如果需要通过环境变量配置端口,可在此处添加
    

    Be sure to set/path/to/anqicmsand/path/to/anqicms_rootReplace with the actual installation path of AnQiCMS. For multi-site deployment, if each site runs on an independent AnQiCMS binary instance, you need to create an independent instance for each site.[program:...]Configure blocks and ensure they use different ports and log files.

  3. Update Supervisor configuration:Notify after saving the configuration file.SupervisorReload the configuration and start AnQiCMS:

    sudo supervisorctl reread
    sudo supervisorctl update
    sudo supervisorctl start anqicms
    

BySupervisorAnQiCMS will receive continuous process protection, detailed logging, and an easy-to-use management interface.

Integration with Monit

MonitIt is a small but powerful tool that can not only monitor processes, but also monitor files, directories, file systems, network connections, system resources (CPU, memory), and more.MonitCheck the status of the monitored item by polling and execute predefined actions (such as restarting the service, sending an alert) when an anomaly is detected.

The following is the typical configuration steps for integrating AnQiCMS toMonit:

  1. Stop and remove the existingcrontabtask:withSupervisorSimilarly, first you need to delete all related tostart.shandstop.shthe relatedcrontabTask.

  2. Create a Monit configuration file:In/etc/monit/conf.d/in the directory (or youMonitCreate a new configuration file at the specified location, for exampleanqicms.conf. The content of the file is roughly as follows:

    check process anqicms with pidfile /var/run/anqicms.pid
        start program = "/bin/bash -c 'cd /path/to/anqicms_root && nohup /path/to/anqicms > /var/log/anqicms/anqicms.log 2>&1 & echo $! > /var/run/anqicms.pid'" as uid www gid www
        stop program  = "/bin/kill `cat /var/run/anqicms.pid`"
        if failed host 127.0.0.1 port 8001 protocol http request "/" then restart
        if 5 restarts within 5 cycles then timeout
        if cpu > 80% for 5 cycles then restart
        if mem > 200 MB for 5 cycles then alert
        group anqicms_apps
        depends on mysql_db ; 假设AnQiCMS依赖MySQL,这里可以添加对数据库的依赖检查
    

    Please note:

    • /path/to/anqicmsand/path/to/anqicms_rootReplace it with the actual path.
    • pidfileThe path needs to ensure that the AnQiCMS startup script can write the PID to this file. Since the Go program does not generate PID files by default, you may need tostart programManually modify the startup command, for exampleecho $! > /var/run/anqicms.pidTo record the PID.
    • stop programYou can usekillCommand, or write a more elegantstop.shScript to sendSIGTERMSignal, give the program a chance to clean up resources before exiting.
    • if failed host ...: This is a health check,Monitwill attempt to access the AnQiCMS HTTP port, and if it fails, it will restart. Port8001Should be consistent with AnQiCMSconfig.jsonThe port configured in
    • depends on mysql_db: This is an example of a dependency, indicating that AnQiCMS can only start normally when the MySQL database service is available.
  3. Update Monit configuration:Check after saving the configuration file,Monitreload the syntax of the configuration:

    sudo monit -t       ; 检查语法
    sudo systemctl reload monit ; 重新加载Monit配置
    

    MonitThe monitoring of the AnQiCMS process will begin, and appropriate actions will be taken when the configured conditions are triggered.

Advantages brought by integration

AnQiCMS will be integrated withSupervisororMonitIntegrate advanced process monitoring tools, which can bring significant advantages in many aspects of your website operation:

  • High availability:The application can automatically restart quickly when it crashes, minimizing downtime to ensure the continuous online operation of AnQiCMS.
  • Resource management:Can monitor the CPU, memory and other resource usage, and execute preset actions (such as restart) when resources are abnormal, to prevent resource exhaustion from causing system crashes.
  • Health check:Supports in-depth health checks for applications, such as checking if the service responds to HTTP requests, not just whether the process is alive.
  • Log management:Provide automated log file rotation and management to prevent log files from growing indefinitely and consuming disk space, and to facilitate log analysis.
  • Centralized management:Provide a unified command-line or Web interface to manage all monitored AnQiCMS instances and other services, improving O&M efficiency.
  • Alarm notification:When AnQiCMS encounters problems, it can be configured to send email, SMS, or other notification methods in a timely manner to alert, allowing operations personnel to know and intervene in the first time.

By this integration, we can free ourselves from the tedious manual checks and restarts, focusing on content creation and website optimization, allowing AnQiCMS to run continuously in a more robust and reliable environment.


Frequently Asked Questions (FAQ)

**1. Why not

Related articles

What is the special meaning of the `\<` and `\>` symbols in the `grep` command when matching process names in the `start.sh` script?

As an experienced soldier who deeply understands the operation of AnQiCMS, I know that stable system operation is the foundation of content creation and distribution.When maintaining the AnQiCMS server, we often encounter situations where we need to check or manage processes, and the `start.sh` script is a key component to ensure that the AnQiCMS service remains online.In the `start.sh` script, there is a line used to check if the AnQiCMS process is running, which includes the `grep` command and the unique `<` and `>` symbols, which seem to be simple characters

2025-11-06

How should the `start.sh` script-generated `check.log` and `running.log` log files be managed and cleaned on a regular basis?

As a website operator who has been dealing with Anqi CMS for a long time, I know that the stable operation of the system cannot be separated from meticulous maintenance work.The log file, as a faithful recorder of the system's status, is of great importance.However, if not properly managed, they may also become potential sources of problems, such as occupying a large amount of disk space, reducing troubleshooting efficiency, and so on.

2025-11-06

Why does the AnQiCMS `stop.sh` script use the `pwd` command to determine BINPATH?

As an experienced secure CMS website operator, I am well aware of the importance of the stable operation of the content management system for the business of the website.In routine maintenance, we frequently deal with the startup and shutdown scripts of the system.For Anqi CMS, its `stop.sh` script uses the `pwd` command to dynamically determine the `BINPATH` variable, which reflects the designer's careful consideration of system robustness and user convenience.The Anqi CMS is a system developed based on the Go language, dedicated to providing an efficient and customizable content management solution

2025-11-06

Is the traditional `start.sh` process guardian method still necessary when deploying AnQiCMS in Docker containers?

As a website manager who is deeply familiar with AnQiCMS (AnQiCMS) operation, I deeply understand that efficiency, stability, and scalability are core considerations when deploying and maintaining a website.With the popularity of containerization technology, many teams choose Docker to deploy AnQiCMS.This naturally leads to a key question: Is the traditional `start.sh` process guardian method still necessary when deploying AnQiCMS in Docker containerization?

2025-11-06

How can the security of the AnQiCMS process be ensured if the `start.sh` script itself fails or is tampered with?

As an experienced AnQiCMS website operations manager, I am well aware that system stability and security are crucial for content management.AnQiCMS provides a solid foundation for users with its high performance and security brought by the Go language development, but even so, any system cannot do without the guarantee of its operating environment.Regarding the security of the `start.sh` script, it is a fundamental issue involving system startup and process management, and its importance should not be overlooked.### `start

2025-11-06

What are the advantages and disadvantages of AnQiCMS using the `start.sh` + `crontab` process guard scheme compared to `systemd` in enterprise-level applications?

As a senior CMS website operation personnel of a well-known security company, I know that the stable and efficient operation of the system is the core of enterprise content management.How to choose the appropriate process protection scheme when deploying AnQiCMS, ensuring that the system can continuously and stably provide services in various situations is a crucial issue.Currently, the AnQiCMS documentation recommends a guard method based on the `start.sh` script combined with `crontab` scheduled tasks.

2025-11-06

What operating systems does AnQiCMS support for deployment and use?

As an experienced AnQi CMS website operations personnel, I am very clear about the deployment and usage of AnQi CMS in different operating system environments.AnQiCMS is an enterprise-level content management system developed based on the Go language, which was designed with cross-platform compatibility in mind, aiming to provide users with flexible and diverse deployment options.

2025-11-06

How to install AnQiCMS's Go project on a Linux server?

As a website operator familiar with AnQiCMS, I fully understand the importance of an efficient, stable, and easy-to-manage content system for website operation.AnQiCMS is a modern enterprise-level content management system developed based on the Go language, with its high concurrency, high security, easy deployment, and excellent SEO-friendly features, it has become an ideal choice for many small and medium-sized enterprises and content operation teams.This article will detail how to install and deploy AnQiCMS's Go project on a Linux server, aiming to help you smoothly set up your own website.###

2025-11-06