As an experienced website operations expert, I fully understand the importance of a stable and efficient content management system for corporate operations.AnQiCMS (AnQiCMS) leverages the efficiency and rich features of the Go language to provide excellent solutions for many small and medium-sized enterprises.However, whether it is for maintenance, upgrading, or simply needing to temporarily shut down, safely and correctly stopping the operation of AnQiCMS is a fundamental and critical task.Especially on operating systems like MacOS that focus on user experience, understanding their operation and taking appropriate measures can ensure smooth operation and data security.

Understand the running way of AnQiCMS on MacOS

AnQiCMS is a system developed based on the Go programming language and typically runs on MacOS as a standalone binary executable file.This is different from the traditional PHP application that requires Apache or Nginx and PHP-FPM.You can imagine AnQiCMS as a standalone application that comes with a 'server' function, which can directly listen to ports and provide services.

You may start AnQiCMS in MacOS by the following methods:

  1. Double-click the executable file directlyThis is the most intuitive way, AnQiCMS usually starts in the terminal window and outputs the runtime log.
  2. Start by terminal commandFor example, use./anqicmscommand, or it may be used to run in the background without being affected by the terminal closurenohup ./anqicms &such a command.
  3. by running through a Docker containerIf you are running AnQiCMS on MacOS using Docker Desktop, it will run as a container service in the background.

Understood the ways of starting, we can take targeted safety stop measures.

Several methods to safely stop AnQiCMS

No matter how you start AnQiCMS, our goal is to gracefully close its process to avoid data corruption or resource usage.

1. Through terminal scripts (recommended and the most common 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 astop.shScript example, this script is also applicable on MacOS because MacOS is also based on the Unix 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 withnohupRuns in a way that can also be stopped effectively.

Below is what you can use and understand.stop.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:

  1. Create or edit the script fileIn the same directory as your AnQiCMS installation or in any convenient location, create a file namedstop.sh.
  2. Paste and save the contentPaste the above script content intostop.shthe file and save.
  3. Grant execution permission: Open your MacOS terminal application (you can search for 'Terminal' using Spotlight), then navigate tostop.shThe directory where the file is located, run the following command to give the script execution permission:
    
    chmod +x stop.sh
    
  4. Run the script: Execute the script in the terminal to stop AnQiCMS:
    
    ./stop.sh
    

The script will checkanqicmsThe process exists, if it exists, then usekill -9command to forcibly terminate the process.kill -9It is a powerful termination command that does not give the process any opportunity to clean up resources.For most web applications written in Go language, the internal design usually takes into account the situation of process termination, but in extreme cases, it is still recommended to ensure that data backup is done before the operation.

2. For processes started directly in the terminal

If you are running directly from the terminal./anqicmsOr double-click the executable file, and if AnQiCMS keeps outputting logs in the terminal, it will be much simpler to stop it.

Press in the terminal window where AnQiCMS is runningCtrl + CA combination key. This will send an interrupt signal (SIGINT) to the process, AnQiCMS usually captures this signal, performs some necessary cleanup work, and exits gracefully.This is the recommended stopping method as it allows the program to handle the exit logic itself.

3. For AnQiCMS running in a Docker container

If your AnQiCMS is deployed in a Docker container, you need to stop it by using the Docker command.

  1. Find the container ID or name.First, you need to know the ID or name of the Docker container running AnQiCMS. You can run the following command in the terminal to view all running containers:
    
    docker ps
    
    Find the container that includesanqicmsNote the container of the image,CONTAINER IDorNAMES.
  2. Stop the container: Use the following command to stop the container. Please replace<CONTAINER_ID_OR_NAME>with the actual ID or name you find:
    
    docker stop <CONTAINER_ID_OR_NAME>
    
    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, it will send a SIGKILL signal to force termination.
  3. (Optional) Remove ContainerIf you are sure 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>
    

Verification after operation

Regardless of which stop method is used, after the operation is completed, you should verify whether AnQiCMS has stopped successfully. The most direct method is to use it again.psCommand check process:

ps -ef | grep 'anqicms' | grep -v grep

If this command produces no output, it meansanqicmsThe process is no longer running. You can also try to access the AnQiCMS service port (default is 8001). If you cannot access it, it usually indicates that the service has stopped.

Summary

Stop AnQiCMS running safely on MacOS, the most commonly used and secure method is through the presetstop.shscripts to terminate background processes, or throughCtrl + CStop the foreground process. If AnQiCMS is running in a Docker container, you should use the commands provided by Docker to manage it.Master these methods to make website maintenance and management easier, ensuring smooth operation and data security.


Frequently Asked 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 yourBINNAME(default is)anqicms), andBINPATHVariable is instop.shThe script name and path of the AnQiCMS executable you are actually running are consistent. In addition,ps -ef | grep '\<anqicms\>'The command may not have found the correct process ID, which could 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 relevant process information output to assist in troubleshooting