In the daily maintenance of operating AnQiCMS website, system upgrade is a key link to enhance functions, optimize performance, and enhance security. However, after the upgrade, we often need to conduct detailed checks and adjustments for some background tasks, especially those that depend oncrontabThe startup task of the guardian process.As an experienced website operations expert, I am well aware of the importance of these details for the stable operation of the website.crontabHow to adjust the startup task and how to properly 'save and exit' these changes.

The background守护 mechanism of AnQiCMS:crontabWith the startup script

AnQiCMS as an enterprise-level content management system developed based on the Go programming language, one of its design philosophies is efficiency and simplicity. In order to ensure that the system can automatically start after the server restarts or automatically recover after an unexpected termination, we usually make use of the Linux system'scrontabEnglish: Combine the startup script provided by AnQiCMS to guard the main program.

AnQiCMS usually providesstart.shandstop.shtwo scripts.

  • start.shThe core logic of the script is to check if the AnQiCMS main program is running, if not, it will start it in the background (usingnohupcommand).
  • stop.shThe script is used to find and terminate the process of the main AnQiCMS program.

We usually willcrontabAdd a scheduled task that runs once every minute.start.shScript, to implement the "heartbeat" monitoring and automatic restart of the AnQiCMS main program. Typical.crontabThe task entry may look like this:

*/1 * * * * /www/wwwroot/anqicms.com/start.sh

Here/www/wwwroot/anqicms.com/start.shYesstart.shthe full path of the script.

Necessary adjustments after the upgrade: Why?crontabDo you need to modify?

The upgrade of AnQiCMS, especially from version 2.x to 3.x (or major version updates in the future), may involve adjustments to the underlying architecture, changes to executable file names, or even changes to deployment paths.crontabThe task cannot find or execute AnQiCMS main program correctly.

For example, if you deploy multiple AnQiCMS instances on the same server, to avoid port conflicts and management confusion, you may want to assign a different port for each instance,anqicmsExecutable file renaming (such astaobaoke) and alsostart.shmodify correspondingly in the scriptBINNAMEVariables. After the upgrade, the new executable file may have restored the default name or its path may have changed, all of which require us to synchronize the updatecrontabor its callsstart.shscript content.

Specific operation steps: adjustcrontabStart task

After AnQiCMS upgrade is completed, we need to check and adjust in an orderly mannercrontabtask.

Step one: visitcrontabEditor

Enter the following command in the terminal to open the current user'scrontabEdit the configuration file:

crontab -e

After executing this command, the system will use the text editor you configured (such asviornano).crontabfile.

第二步:定位与修改现有任务

In the openedcrontab文件中,找到您之前为AnQiCMS设置的启动任务条目,通常形如:*/1 * * * * /path/to/your/anqicms/start.sh

重点检查以下几点:

  1. start.sh脚本路径Confirm:/path/to/your/anqicms/start.shThis path is still correct. The upgrade may have changed the installation directory of AnQiCMS. If the path has changed, you need to update the path here.

  2. start.shScript Content: Evenstart.shThe path of the script itself has not changed, and the variables internally defined may also need to be adjusted. Please openstart.shscript file (for example, usingvi /path/to/your/anqicms/start.shcommands), check and modify the following key variables:

    • BINNAMEThis is the name of the executable file of the AnQiCMS main program, the default name isanqicmsIf you have renamed it for purposes such as multi-site deployment, please make sure that it matches the actual executable file name here.
    • BINPATHThis is the directory path where the AnQiCMS main program is located. Similarly, please ensure that this points to the actual directory where the AnQiCMS main executable file is located.

    For exampleIf your content is:start.shThe content is as follows:

    #!/bin/bash
    BINNAME=anqicms
    BINPATH=/www/wwwroot/anqicms
    # ... 其他代码 ...
    cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &
    

    If your AnQiCMS is installed after the upgrade,/new/path/anqicmsand the executable file name isanqicms_v3then you need to:start.shChange to:

    #!/bin/bash
    BINNAME=anqicms_v3
    BINPATH=/new/path/anqicms
    # ... 其他代码 ...
    cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &
    

    Ifstart.shThe file content has been automatically updated by the AnQiCMS upgrade program. Normally, you do not need to manually modify its internal variables. The key is to ensurecrontabFind the correctstart.sh,andstart.shThe internalBINPATHandBINNAMEThe variable points to the upgraded AnQiCMS main program.

Step 3: Save and exit.crontab

This is a crucial step in the operation, also a place where many beginners are likely to be confused. The operation to save and exit may vary depending on the editor you use:

  • If you are using the Vim/Vi editor:
    1. pressEsckey to ensure you exit insert mode.
    2. Enter:wq(colon, w, q).
    3. pressEnterkey.wmeans write (save),qExit.
  • If you are using the Nano editor:
    1. pressCtrl + XCombination keys.
    2. 系统会提示“Save modified buffer?” (是否保存已修改的缓冲区?),输入Y(Yes)。
    3. The system will prompt “File Name to Write:” (File name to write:), press theEnterkey to confirm the file name.

Successfully saved and exited, the system usually promptscrontab: installing new crontab(or similar information), indicating that your changes have taken effect.

Step 4: Verify if the task has taken effect

Adjust and savecrontabThen, you can manually execute once:start.shScript, to ensure that AnQiCMS can start immediately:

/path/to/your/anqicms/start.sh

Then, check whether the AnQiCMS process is running using the following command:

ps -ef | grep anqicms
# 如果您重命名了可执行文件,请使用新的名称,例如:
# ps -ef | grep anqicms_v3

If you see the process information related to AnQiCMS, it means the adjustment was successful. If not, please check carefully.crontabEntry path,start.shScript content, as well as the permissions and actual location of the executable file.

Special considerations for panel-based deployment (1Panel/Taobao Panel)

It is worth mentioning that if you are deploying and managing AnQiCMS through visualization tools such as 1Panel or Baota Panel, the situation may be different. These panels usually provide 'Go project' or 'Docker' deployment