How to modify the `start.sh` script to record more detailed debug information when starting AnQiCMS?
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