After AnQiCMS upgrade, how should the original `crontab` startup task be adjusted and 'save and exit'?
In the daily operation and maintenance of the AnQiCMS website, system upgrades are a key link to enhance functions, optimize performance, and enhance security. However, after the upgrade, we often need to carry out detailed checks and adjustments for some background tasks, especially those relying oncrontabThe 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.Today, let's delve into the original features of AnQiCMS after the upgradecrontabHow to adjust the task startup and how to correctly 'save and exit' these changes.
The background guardian mechanism of AnQiCMS:crontabWith the startup script
AnQiCMS as an enterprise-level content management system developed based on the Go programming language has one of its design philosophies as efficiency and simplicity. To ensure that the system can automatically start after the server is restarted or can recover automatically after the program terminates unexpectedly, we usually make use of the Linux system'scrontab(Scheduled task) 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 (usingnohupcommands).stop.shThe script is used to find and terminate the main process of the AnQiCMS program.
We usually add a scheduled task incrontabto execute once every minute.start.shScript to monitor the "heartbeat" and automatically restart the AnQiCMS main program. Typical.crontabTask entries may look like this:
*/1 * * * * /www/wwwroot/anqicms.com/start.sh
Here/www/wwwroot/anqicms.com/start.shIsstart.shthe full path of the script.
Why necessary adjustments after the upgrade:crontabDo you need to modify?
The upgrade of AnQiCMS, especially from version 2.x to 3.x (or future major versions), may involve adjustments to the underlying architecture, changes to the executable file name, or even changes to the deployment path.These changes can all lead to the originalcrontabThe task cannot find or execute the main program of AnQiCMS 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 each instance'sanqicmsRename executable files (such astaobaoke), and also modifystart.shit in the script.BINNAMEVariables. After the upgrade, the new executable file may have restored the default name or the path may have changed, all of which require us to update synchronouslycrontabor its callstart.shscript content.
Specific operation steps: adjustcrontabStart the task
After AnQiCMS is upgraded, we need to check and adjust in an orderly mannercrontabTask.
First step: visitcrontabEditor
Type the following command in the terminal to open the current user'scrontabconfiguration file for editing:
crontab -e
After executing this command, the system will default to using the text editor you have configured (such asviornano).crontabfile.
Second step: Locate and modify the existing task
In the openedcrontabfile, find the startup task entry you previously set up for AnQiCMS, usually like:*/1 * * * * /path/to/your/anqicms/start.sh
Pay special attention to the following points:
start.shScript path: Confirm/path/to/your/anqicms/start.shIs this path still correct. The upgrade may have changed the installation directory of AnQiCMS. If the path has changed, you need to update the path here.start.shScript content: Even thoughstart.shThe script's path has not changed, and the variables defined internally may also need to be adjusted. Please openstart.shthe script 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 isanqicmsEnsure that the name here matches the actual executable file name if you have renamed it for purposes such as multi-site deployment.BINPATHThis is the directory path of the AnQiCMS main program. Similarly, make sure that it points to the actual directory of the AnQiCMS main program executable file.
For exampleIf your
start.shAs 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 will need tostart.shChange to:#!/bin/bash BINNAME=anqicms_v3 BINPATH=/new/path/anqicms # ... 其他代码 ... cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &If
start.shThe file content has already been automatically updated by the AnQiCMS upgrade program. Usually, you do not need to manually modify its internal variables. The key is to ensurecrontabthat you can find the correctstart.shandstart.shinternallyBINPATHandBINNAMEThe variable points to the upgraded AnQiCMS main program.
Step 3: Save and exitcrontab
This is a critical step in the operation, and it is also a place where many beginners are easily confused. The operation to save and exit varies depending on the editor you use:
- If you are using the Vim/Vi editor:
- Press
EscPress the key to ensure you exit insert mode. - Enter
:wq(Colon, w, q). - Press
Enterkey.}wIndicates write (save),qIndicates exit.
- Press
- If you are using the Nano editor:
- Press
Ctrl + XCombination key. - The system will prompt "Save modified buffer?" (Do you want to save the modified buffer?) Enter
Y(Yes)。 - The system will prompt “File Name to Write:” (File name to write:), press
Enterthe key to confirm the file name.
- Press
Successfully saved and exited, the system will usually promptcrontab: installing new crontab(or similar information), indicating that your changes have taken effect.
Step 4: Verify whether the task has taken effect
Adjust and savecrontabAfter that, you can manually execute once:start.shScript to ensure that AnQiCMS can start immediately:
/path/to/your/anqicms/start.sh
Then, check if the AnQiCMS process is running with the following command:
ps -ef | grep anqicms
# 如果您重命名了可执行文件,请使用新的名称,例如:
# ps -ef | grep anqicms_v3
If you see 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/Baota 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