In the daily operation of the website, while we pursue system stability and efficiency, sometimes for maintenance, resource optimization, or to deal with emergencies, we need to "let the system rest" in time.AnQiCMS is a high-performance content management system built on the Go language, serving a wide range of users with its concise and efficient architecture. However, even such an excellent system requires careful management from us as operators.Today, let's discuss how to set up an automated script for AnQiCMS to stop automatically under certain conditions, thereby achieving more intelligent and worry-free operation and maintenance.

Understand the stop mechanism of AnQiCMS

To implement automatic shutdown, you must first understand how AnQiCMS is stopped. According to the deployment method of AnQiCMS, the shutdown mechanism is somewhat different:

  1. Deploy directly (Linux command line or Baota panel Go project):AnQiCMS is usually started in the Linux environment through its built-in startup script (start.shRun as a daemon process, accordingly, there is also a stop scriptstop.sh)。Thisstop.shThe core logic of the script is to find the process ID (PID) of AnQiCMS, then usekill -9 PIDCommand to force termination of the process. When we want to automate the stop, the goal is to trigger and execute thisstop.shscript.

  2. Docker container deployment (such as 1Panel, aaPanel, or Baota Docker):In the Docker environment, AnQiCMS runs in an independent container. At this time, we cannot directly call the internalstop.shA script to stop AnQiCMS, but it should be managed through the Docker host's commands to manage the container's lifecycle, namely usingdocker stop <容器名称或ID>command. Automation scripts need to call this Docker command.

  3. Windows Local Test:The Windows environment is typically used for local development or testing. AnQiCMS as aanqicms.exeThe executable file runs. In an automated scenario, you need to manually terminate the process through Task Manager, or use PowerShell script language to find and terminateanqicms.exeProcess.

Considering that Linux server deployment is mainstream, we will mainly discuss script implementation under Linux environment, and briefly mention the differences in the Docker environment.

The core idea of the automation stop script

“Specific conditions”are the key to stopping automation. These conditions can be diverse, such as:

  • Insufficient disk space, reaching the preset threshold.
  • The server CPU or memory usage is consistently too high.
  • The website needs to be deeply maintained during specific times (such as in the early morning).
  • Anomalous log output detected, such as a large number of errors in a short period of time.
  • Received external instructions (for example, by placing a 'stop marker file' at a specific location).

To demonstrate generality and simplicity, we choose to check a“Stop Marking File”Exists to trigger the automation stop of AnQiCMS. When this marking file appears, our automation script will perform the stop operation.

Next, we will implement this automated shutdown process step by step.

1. Prepare the AnQiCMS shutdown script

In the AnQiCMS installation directory, there is usually astop.shscript. Its content is as follows:

`bash #!/bin/bash

stop anqicms

author fesion

the bin name is anqicms

BINNAME=anqicms # Your AnQiCMS executable name BINPATH=\( ( cd " )( dirname “$0” )” && pwd )” # An