In the daily operation of the website, although we strive for system stability and efficiency, sometimes out of considerations for maintenance, resource optimization, or dealing with emergencies, we need to 'let the system take a break' in a timely manner.AnQiCMS is a high-performance content management system built on the Go language, serving a large number of users with its concise and efficient architecture. However, even such an excellent system requires meticulous management on our part as operators.Today, let's discuss how to set up an automated script for AnQiCMS to stop automatically under specific conditions, thus achieving more intelligent and worry-free operation and maintenance.
Understand the stop mechanism of AnQiCMS
To implement automated shutdown, it is first necessary to understand how AnQiCMS is stopped. Depending on the deployment method of AnQiCMS, the shutdown mechanism varies slightly:
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 script forstop.sh)。Thisstop.shscript's core logic is to find the process ID (PID) of AnQiCMS, then usekill -9 PIDForcefully terminate the process. The goal is to trigger and execute this when we want to automate the shutdown.stop.shscript.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 inside of the container.
stop.shscripts should not be used to stop AnQiCMS, but instead, the container's lifecycle should be managed using the commands of the Docker host, that is, usingdocker stop <容器名称或ID>Command. Automation scripts need to call this Docker command.Windows Local Test:The Windows environment is usually used for local development or testing. AnQiCMS as a
anqicms.exeThe executable file runs. In an automated scenario, the process needs to be manually terminated through the Task Manager, or by using PowerShell and other scripting languages to locate and terminate.anqicms.exeProcesses.
Considering that Linux server deployment is mainstream, we will mainly focus on script implementation under Linux environment and will briefly mention the differences in the Docker environment.
The core idea of the automation stop script
“Specific conditions” are the key to automation stop. These conditions can be various, 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 at specific times (such as in the early morning).
- Abnormal log outputs detected, such as a large number of errors in a short period of time.
- Received external instructions (such as, by placing a 'stop marker file' at a specific location).
For the generality and simplicity of demonstration, we choose to check a“Stop Mark File”Does the presence of this mark file trigger the automatic shutdown of AnQiCMS? When this mark file appears, our automated script will execute the shutdown 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 roughly as follows:
`bash #!/bin/bash
stop anqicms
author fesion
the bin name is anqicms
BINNAME=anqicms # Your AnQiCMS executable filename BINPATH="\(( cd "\)'} ]( dirname “$0” ) && pwd ) # An