How to modify the `start.sh` script to record more detailed debug information when starting AnQiCMS?

Calendar 👁️ 49

As a website operator deeply familiar with AnQiCMS, I know the importance of system stable operation and efficient problem troubleshooting for content management.When AnQiCMS encounters an exception while running or needs to gain a deeper understanding of its internal workflow, obtaining detailed debugging information is a crucial step.start.shThe script serves as the entry point for AnQiCMS in the Linux environment, which is the key part we modify to obtain more debugging information.

Understandingstart.shThe initial function of the script.

In the deployment of AnQiCMS,start.shThe script is responsible for checking the process status of AnQiCMS and starting its main program. Through the documentation, we learn that its core logic includes checking if AnQiCMS is running, and if not, it will proceed throughnohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &This command is used to start the program. The meaning of this command is that it runs the AnQiCMS executable file in the background (vianohup) and redirects standard output and standard error ($BINPATH/$BINNAME)2>&1redirected torunning.login the file. This means that all information output directly to the console by the AnQiCMS program will be recorded in this log file.

However, for deeper debugging needs, merely capturing standard output and standard error may not be enough. Many Go applications, including content management systems like AnQiCMS, usually support different log levels, such asinfo/warn/errorand what we need most when debuggingdebugortracelevel. To get more detailed debugging information, it often requires indicating the AnQiCMS program itself to run at a higher log level.

Explore methods to enable more detailed debugging information

AnQiCMS as a Go language developed application, its log output level of detail can usually be controlled in the following common ways:

First, many applications will respond to specificenvironment variables. For example, you can setANQICMS_DEBUG=trueOrLOG_LEVEL=debugSuch environment variables are used to inform the program to output more details. These environment variables need to be set before the program starts.

In addition, some programs will acceptcommand-line argumentsTo control the log level. For example, add after the start command.--debugor--verboseSuch a flag.

Moreover,configuration fileIt is also a common way to control the behavior of the application. AnQiCMS'sconfig.jsonThe file is used to configure basic information such as ports, and theoretically it can also include log level settings. But according to the provided document,config.jsonUsed mainly for template-related configurations, it does not explicitly indicate that it supports log level adjustment. Therefore, we need to focus on the first two methods that are directly modified by the script.start.shThe method of modifying directly by the script.

modifystart.shScript to obtain detailed debug logs

To record more detailed debug information when AnQiCMS starts, we need to modifystart.shScript, add the corresponding control parameters when executing the AnQiCMS program.Here we will introduce two methods of modification based on environment variables and command line parameters, you can try according to the parameters supported by AnQiCMS.At the same time, in order to avoid confusion between debug logs and regular runtime logs, it is recommended to output debug information to a separate log file.

The following is the modificationstart.shThe steps of the script are:

First, find the directory of AnQiCMS installation on your serverstart.shfile. Usually, this file is located/www/wwwroot/your_domain/start.shpath (depending on your actual installation path).

Open with a text editorstart.sha file, for examplevi start.shornano start.sh.

Find the line in the script that starts the AnQiCMS core program. It will look something like this:cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &

Now, we will modify this line based on different debugging needs:

Method one: Enable detailed logging by setting the environment variable

If AnQiCMS supports controlling the log level through environment variables (such asANQICMS_LOG_LEVEL=debug),You can set this environment variable before executing the command. The modified startup command may look like this:

#!/bin/bash
### check and start AnqiCMS
# author fesion
# the bin name is anqicms
BINNAME=anqicms
BINPATH=/www/wwwroot/anqicms # 请根据您的实际路径修改

# check the pid if exists
exists=`ps -ef | grep '\<anqicms\>' |grep -v grep |wc -l`
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"
    # --- 添加或修改以下行以启用更详细的调试日志 ---
    export ANQICMS_LOG_LEVEL="debug" # 假设 AnQiCMS 响应 ANQICMS_LOG_LEVEL 环境变量
    # 或者尝试更通用的 LOG_LEVEL 环境变量
    # export LOG_LEVEL="debug"

    # 将详细日志输出到专门的 debug.log 文件,方便区分
    cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/debug_running.log 2>&1 &
fi

Here, we go throughexport ANQICMS_LOG_LEVEL="debug"(or similar variable) to try to enable debug mode. At the same time, we will change the log file todebug_running.logIn order to separate debug information from regular runtime logs, which will be very helpful during later analysis.

Method two: Enable detailed logging by passing command line arguments.

If AnQiCMS supports controlling the log level through command-line arguments (for example--debugor--log-level debug),You can pass these parameters to the executable file when executing the command. The modified startup command may look like this:

#!/bin/bash
### check and start AnqiCMS
# author fesion
# the bin name is anqicms
BINNAME=anqicms
BINPATH=/www/wwwroot/anqicms # 请根据您的实际路径修改

# check the pid if exists
exists=`ps -ef | grep '\<anqicms\>' |grep -v grep |wc -l`
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"
    # --- 添加或修改以下行以启用更详细的调试日志 ---
    # 假设 AnQiCMS 响应 --debug 命令行参数
    # cd $BINPATH && nohup $BINPATH/$BINNAME --debug >> $BINPATH/debug_running.log 2>&1 &

    # 或者假设 AnQiCMS 响应 --log-level debug 命令行参数
    cd $BINPATH && nohup $BINPATH/$BINNAME --log-level debug >> $BINPATH/debug_running.log 2>&1 &
fi

Please note that you may need to consult the official AnQiCMS development documentation or source code to confirm the specific supported environment variables or command line parameter names.Because the provided document does not explicitly state how AnQiCMS controls its internal log level.It is very important to maintain an attitude of exploration and verification when trying these general methods as an operations manager.

Save after modificationstart.shFile. To make the changes take effect, you need to stop the currently running AnQiCMS instance (if it exists) and then run it again.start.shScript to start AnQiCMS.

Stop AnQiCMS command example (please adjust according to yourstop.shscript path and content): ./stop.sh

Start AnQiCMS command example: ./start.sh

After starting, you can viewdebug_running.logFile to obtain detailed debugging information generated by AnQiCMS. For example:tail -f $BINPATH/debug_running.log.

Remember that leaving detailed debug logs enabled for a long time in a production environment may affect system performance and may expose some sensitive information. Therefore, it is recommended that you turn offstart.shScript restored to the original configuration, or at least the log level is returned to normal mode.


Frequently Asked Questions (FAQ)

Question: Will enabling detailed debug logs affect the performance of AnQiCMS?

Yes, leaving detailed debug logs enabled for a long time usually affects the performance of AnQiCMS.Because the program needs to spend additional time and resources to generate, format, and write a large amount of log information, this will increase the CPU, memory, and disk I/O overhead.After the problem is resolved, it is recommended to promptly disable the detailed log mode to ensure the system's performance.

Ask: If I modifiedstart.shthe script but AnQiCMS still does not output detailed logs, what should I do?

Answer: If during modificationstart.shAfter running the script and restarting AnQiCMS, you still do not see more detailed output in the log file, which may mean that the AnQiCMS application itself did not respond to the environment variables or command line parameters you tried to set.In this case, you should refer to the latest official development documentation of AnQiCMS, or search for specific instructions on how to enable detailed logging in the AnQiCMS community forum or GitHub repository.Sometimes, the log level control of an application may be through its internal configuration file rather than external startup parameters

Related articles

What is the impact on server performance of setting `*/1 * * * *` to check the AnQiCMS process every minute in `crontab`?

As a website operator who is deeply familiar with the operation of Anqi CMS, I know that the stability and response speed of website services are crucial for attracting and retaining users.The content management system is at the core of the website, and its continuous stable operation is the basis for ensuring efficient content publication and smooth user access.Regarding the setting of `*/1 * * * *` in `crontab` to check the AnQiCMS process every minute, as well as the potential impact on server performance, this is a topic worthy of in-depth discussion.### Ongoing intent and implementation Firstly

2025-11-06

What are the values that can be set for the `BINNAME` variable in the `start.sh` script, besides `anqicms`?

As the website operator of AnQi CMS, we are fully aware that the flexibility of system deployment is crucial for efficient website management.During the deployment of AnQi CMS, the `start.sh` script is a key component for managing the start and stop of core programs.One of the core variables is `BINNAME`, which defines the name of the executable program for AnQi CMS.

2025-11-06

How does the automatic startup function of the AnQiCMS process ensure the continuous stable operation of the system if the server restarts unexpectedly?

AnQi CMS, as an enterprise-level content management system built with Go language, has always put system stability and continuous operation capabilities at the core from the very beginning.For any online service, unexpected server restarts or sporadic process termination are inevitable operational challenges.Therefore, AnQiCMS is built with multiple automatic restart mechanisms, aimed at ensuring that the system can quickly and reliably restore services in the face of such sudden situations, to ensure the continuous stable operation of the website.Understanding the importance of automatic pull-up It is crucial to maintain continuous service availability in website operations

2025-11-06

What is the working principle of the `awk '{printf $2}'` command to get the PID in the `stop.sh` script?

As an experienced CMS website operation personnel in the security industry, I am well aware of the importance of stable system operation and efficient maintenance.In daily management, understanding the working principles of various automation scripts is the key to ensuring system health.Today, let's delve deep into how the `awk '{printf $2}'` command in the `stop.sh` script accurately locates and retrieves the PID (Process ID) of the AnQiCMS process.In the operation and maintenance practice of AnQiCMS, the `stop.sh` script is responsible for gracefully shutting down the application

2025-11-06

Does the `start.sh` script support running the AnQiCMS process with different user identities, how is permission management implemented?

As a senior security CMS website operator, I am well aware of the importance of system stability and permission management for website security and operational efficiency.About the user identity and permission management of the AnQiCMS process running the `start.sh` script, I can elaborate for you.AnQiCMS is a system developed based on the Go language, and its operation and permission settings are different from traditional PHP applications, but the core security concept is the same: the principle of least privilege. `start

2025-11-06

After upgrading from AnQiCMS 2.x version to 3.x version, is the PID detection in the old `start.sh` scheduled task still applicable?

As an experienced CMS website operation personnel of an enterprise, I fully understand the importance of system stability and management efficiency for content operation.About the issue you raised regarding whether the PID detection in the old `start.sh` scheduled task still applies after upgrading from AnQiCMS 2.x to 3.x version, I can provide you with a detailed answer.In the AnQiCMS 2.x version, to ensure the AnQiCMS application written in Go language can run stably and continuously, especially after server restarts or unexpected program exits, it can recover automatically

2025-11-06

How to verify that the `start.sh` and `stop.sh` scripts are configured correctly and valid when deploying AnQiCMS via the command line?

As a senior security CMS website operation personnel, I fully understand the importance of a stable and reliable deployment plan for the continuous operation of the website.Especially in the command-line environment, scripts like `start.sh` and `stop.sh` are crucial for AnQiCMS to maintain vitality and cope with emergencies.They are not only responsible for starting and stopping services, but also quietly ensure the robustness of the system in the background.Therefore, verifying the configuration of these scripts for correctness and validity is an indispensable step after deploying AnQiCMS.###

2025-11-06

How does the Go language high concurrency architecture of AnQiCMS协同with process guardian scripts to ensure the high performance and stability of the system?

AnQiCMS is an enterprise-level content management system developed based on the Go language, which has always put high performance and high availability as its core competitiveness since its inception.In actual operation, website performance and stability are the key to attracting and retaining users.AnQiCMS through its unique Go language high concurrency architecture design, combined with mature process guardian scripts, jointly builds a robust system that can withstand huge traffic pressure and ensure continuous online services.

2025-11-06