As an experienced website operations expert, I am well aware of the importance of a stable and efficient content management system for enterprise operations.AnQiCMS (AnQiCMS) provides an excellent solution for a large number of small and medium-sized enterprises with its efficiency in Go language and rich features.However, whether it is for maintenance, upgrade, or simply the need to temporarily shut down, safely and correctly stopping the operation of AnQiCMS is a fundamental and critical operation.Especially on MacOS, an operating system that focuses on user experience, understanding its operation mechanism and taking corresponding measures can ensure smooth operation and data security.
Understanding the running mode of AnQiCMS on MacOS
AnQiCMS as a system developed in Go language, usually runs on MacOS as an independent executable binary file.This is different from the traditional PHP application that requires Apache or Nginx and PHP-FPM.You can imagine AnQiCMS as an independent application that comes with its own 'server' function, which can directly listen to ports and provide services.
Under MacOS environment, you may start AnQiCMS in the following ways:
- Double-click the executable file directlyThis is the most intuitive way, AnQiCMS usually starts in the terminal window and outputs the running log.
- Start through terminal commandsFor example, using
./anqicmsCommand, or it may be used so that it can run in the background without being affected by the closing of the terminal.nohup ./anqicms &Such commands. - Run through Docker containersIf you are running AnQiCMS on MacOS using Docker Desktop, it will run as a container service in the background.
Understood these startup methods, we can take targeted safety shutdown measures.
Several methods of safely stopping AnQiCMS
Whether you start AnQiCMS through any method, our goal is to gracefully close its process, avoiding data corruption or resource occupation.
1. Through terminal script (recommended and most universal method)
For most AnQiCMS deployments, especially those running in the background, using a simple terminal script is the safest way to stop it. The official documentation of AnQiCMS provides a terminal script for Linux environments,stop.shScript example, this script is also applicable on MacOS as MacOS is also a Unix-based operating system.
This script works by: it will find all running processesanqicmsand force them to terminate. This ensures that even if AnQiCMS is running in the background withnohupWay to run, can also be effectively stopped.
The following is what you can use and understandstop.shScript content:
#!/bin/bash
### stop anqicms
# author fesion
# the bin name is anqicms
BINNAME=anqicms
BINPATH="$( cd "$( dirname "$0" )" && pwd )"
# check the pid if exists
exists=`ps -ef | grep '\<anqicms\>' |grep -v grep |awk '{printf $2}'`
echo "$(date +'%Y%m%d %H:%M:%S') $BINNAME PID check: $exists" >> $BINPATH/check.log
echo "PID $BINNAME check: $exists"
if [ $exists -eq 0 ]; then
echo "$BINNAME NOT running"
else
echo "$BINNAME is running"
kill -9 $exists
echo "$BINNAME is stop"
fi
How to use this script to stop AnQiCMS:
- Create or edit a script file:In the same level as your AnQiCMS installation directory or any convenient location, create a file named
stop.sh[en] of the file. - Paste and save the content:Paste the above script content into
stop.shfile and save. - Grant execution permission: Open your MacOS Terminal application (you can search for “Terminal” using Spotlight), then navigate to
stop.shThe directory where the file is located, execute the following command to grant execution permissions to the script:chmod +x stop.sh - Run the script: Execute the script in the terminal to stop AnQiCMS:
./stop.sh
The script will checkanqicmsProcess exists, if it exists, use itkill -9command to force terminate the process.kill -9is a powerful termination command that does not give the process any opportunity to clean up resources.For most web applications written in Go language, their internal design usually already considers the situation where the process suddenly terminates, but in extreme cases, it is still recommended to ensure that data backup has been done before the operation.
2. For processes started directly in the terminal
If you are running directly in the terminal./anqicmsOr double-click the executable file, and it will be much simpler to stop AnQiCMS as it continues to output logs in the terminal.
只需在正在运行AnQiCMS的那个终端窗口中,按下 EnglishCtrl + CCombination key.This will send an interrupt signal (SIGINT) to the process, AnQiCMS will usually catch this signal, perform some necessary cleanup work, and exit gracefully.This is the most recommended stopping method, as it allows the program to handle the exit logic by itself.
3. 针对在Docker容器中运行的AnQiCMS English
If your AnQiCMS is deployed in a Docker container, you need to stop it through the Docker command.
- Find the container ID or name:Firstly, you need to know the ID or name of the Docker container running AnQiCMS. You can view all running containers by running the following command in the terminal:
找到包含docker psanqicms镜像的容器,记下其CONTAINER IDorNAMES. - 停止容器:使用以下命令停止容器。请将
<CONTAINER_ID_OR_NAME>替换为您查到的实际ID或名称:
This command will attempt to send a SIGTERM signal to the container, waiting for a period of time to allow the process to exit gracefully. If it does not exit within the timeout, a SIGKILL signal will be sent to force termination.docker stop <CONTAINER_ID_OR_NAME> - (Optional) Remove containerIf you are sure that you no longer need this container, you can use the following command to completely delete it (this will delete all data in the container, but will not delete the volume data mounted on the host):
docker rm <CONTAINER_ID_OR_NAME>
Operation verification after action
No matter which stop method you use, after the operation is completed, you should verify whether AnQiCMS has stopped successfully. The most direct method is to use it againpsCommand check process:
ps -ef | grep 'anqicms' | grep -v grep
If this command produces no output,anqicmsProcess is no longer running. You can also try to access the AnQiCMS service port (default is 8001), if you cannot access it, it usually also indicates that the service has stopped.
Summary
Stop AnQiCMS running safely on MacOS, the most common and reliable way is to use the presetstop.shscripts to terminate background processes, or throughCtrl + CStop the foreground process.If AnQiCMS is running in a Docker container, it should be managed using the commands provided by Docker.Master these methods, and it will allow you to maintain and manage your website more skillfully, ensuring the smooth operation of the website and data security.
Common Questions (FAQ)
1. I triedstop.shScript, but AnQiCMS seems not to have stopped, why is that?There may be several reasons for this situation. First, please make sure that yourBINNAME(default)anqicms) andBINPATHvariable instop.shThe executable file name and path of AnQiCMS run by you in the script are consistent. Secondly,ps -ef | grep '\<anqicms\>'The command may not have found the correct process ID, which may be because the AnQiCMS process name is not just “anqicms”, or you do not have sufficient permissions to view all users' processes. You can try running it directlyps -ef | grep 'anqicms'Check if there is any related process information output to assist in troubleshooting