As an experienced website operations expert, I am happy to give you a detailed explanation of AnQiCMS incrontabConfiguration*/1 * * * *The meaning and modification suggestions. Anqi CMS, with its efficient, stable and scalable features, has won the favor of many small and medium-sized enterprises and content operators, and its underlying automated mechanisms, such as scheduled tasks (crontabIt is one of the keys to its stable operation.
AnQiCMScrontabIn the configuration.*/1 * * * *Meaning and modification suggestions.
During the deployment of AnQiCMS, especially in the Linux server environment, you may encounter a classiccrontabconfiguration item:*/1 * * * * /www/wwwroot/anqicms.com/start.sh.This brief command is crucial for the stable operation of the system, but what is its specific meaning?In what situations should we consider modifying it again?Today, let's delve deep into this issue.
crontab: The timekeeper of the Linux system
First, we need to understand it simplycrontab.It is like a dedicated 'time manager' in the Linux system, responsible for automatically executing preset tasks at specified times.These tasks are usually referred to as 'scheduled tasks' or 'timed tasks'.In the update log of AnQiCMS, we can see that the "planned task feature" was "added" in version v2.0.0-alpha5 (March 29, 2021), indicating that AnQiCMS has considered the need for automated operation and maintenance from the very beginning.
Analyze*/1 * * * *
crontabThe command format is very strict, usually consisting of five asterisk fields and a command to be executed, each asterisk representing a dimension of the time period.
Let's see.*/1 * * * *These five asterisks represent what:
- The first
*(or)*/1): Represents minutes (Minute), ranging from 0-59. Here is the*/1means 'Every 1 minute.' - the second
*: Represents the hour (Hour), ranging from 0-23. Here*means 'every hour.' - the third
*: Represents the day (Day of Month), ranging from 1-31. Here,*Means 'every day.' - The fourth
*: Represents the month (Month), ranging from 1 to 12. Here is*Means "monthly". - Fifth
*: Represents the day of the week, ranging from 0-7 (both 0 and 7 represent Sunday). Here,*means 'Every day of the week'.
So,*/1 * * * *Combine it, its complete meaning is:“At the 0th second of every minute, execute the specified command”. This is a very frequent execution frequency.
Why does AnQiCMS use*/1 * * * *such a high frequency?
In the installation document of AnQiCMS, this linecrontabusually associates withstart.shscript association.start.shThe script usually checks if the AnQiCMS main program is running, and if not, starts it. This is called the 'application health check and self-starting guardian'.
To be specific,start.shThe script will execute similarps -ef | grep '\<anqicms\>'commands to find the AnQiCMS process. If the process does not exist, it will executenohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &commands to start AnQiCMS.
This strategy of checking every minute and starting if it's not running has several significant advantages:
- High availability guaranteeEven if the AnQiCMS program crashes for some unknown reason, it can be automatically detected and restarted in less than a minute, greatly improving the online rate and stability of the website.
- Simple and effective:Compared to complex process guardian tools (such as Supervisor),
crontabCombining a simple Shell script provides a lightweight and easy-to-understand guard method.
Therefore, for AnQiCMS'sstart.shscript,*/1 * * * *This high frequency is completely reasonable and recommended, ensuring the continuous operation of the website.
Suggestion for modification: distinguish the purpose and adjust cautiously
Understood*/1 * * * *meaning and its backgroundstart.shAfter discussing the purpose of the script, let's talk about modification suggestions. Here, it is necessary to distinguish between two cases:
Target
start.shOf the scriptcrontabConfiguration: For the main program of AnQiCMS to run as a daemon script,start.sh,We strongly recommend that you keep*/1 * * * *the configuration without modification.As mentioned before,start.shThe script is idempotent (the effect of multiple executions is the same), it checks first and then executes, even if it runs every minute, it will only consume a minimal amount of system resources for process checking.Frequent checks are the key to ensuring rapid service recovery.Special cases (rare):unless your server resources are extremely limited, to the extent that they can only be executed once a minute
ps -efIt will cause a significant performance overhead (this situation is very rare, usually indicating that the server configuration is far below the minimum requirements of AnQiCMS), otherwise the check frequency should not be reduced. If you really encounter it, consider changing*/1changed to*/5(Every 5 minutes), but this will increase the recovery time after a service failure. In more advanced deployment environments (such as Kubernetes or using')}]systemdManagement service), there may be a more professional process guard mechanism, at this pointcrontabMay be removable, but it belongs to the advanced deployment category, usually handled by dedicated operation and maintenance personnel.For other scheduled tasks in AnQiCMS
crontabConfiguration: AnQiCMS provides rich backend features such as "Time Factor-Scheduled Publishing Function", "Link Pushing", "Sitemap Generation", "Content Collection", etc. These features may also need to be executed regularly through scheduled tasks. When dealing with such tasks, we need to flexibly configure according to actual needs.crontabExecution frequency.Daily taskFor example, you can set up Sitemap generation or data backup to run at midnight every day.
0 0 * * * /path/to/your/anqicms/scripts/generate_sitemap.sh(Means executing at 0:00 every day)
Hourly taskFor example, some tasks of content collection or data summarization of traffic statistics.
0 * * * * /path/to/your/anqicms/scripts/hourly_task.sh(Indicates execution at 0 minutes of every hour)
Specific interval taskFor example, execute a link push every 5 minutes or every 30 minutes (if AnQiCMS has the corresponding command-line tool or API trigger).
*/5 * * * * /path/to/your/anqicms/scripts/push_links.shThis indicates that it is executed every 5 minutes
Points to note:
- Independent Script: Each different scheduled task should call an independent Shell script or command, which is convenient for management and troubleshooting.
- Resource considerationFor I/O-intensive or CPU-intensive tasks, it should be avoided to execute during peak hours and ensure that the execution frequency is reasonable to prevent unnecessary burden on server performance.
- Log recordingMake sure each scheduled task has good logging to track the execution status and troubleshoot potential problems.
In short, in AnQiCMS of*/1 * * * *Configuration is a "heartbeat mechanism" designed to ensure the continuous operation of core services, and its high frequency is a reflection of stability.For most users, keeping it the same is**practice.crontabentries.
Frequently Asked Questions (FAQ)
Q:
*/1 * * * *Will it occupy a lot of server resources and cause performance degradation if it is executed once a minute?A: Regarding the AnQiCMS main program daemon script (start.shIn this regard, it is usually not the case.The design purpose of this script is to first perform a lightweight process check, and only try to start if the main program is indeed not running.If AnQiCMS is running normally, the script will complete the check in a very short time and exit, consuming almost no additional resources.So, the impact on server performance is negligible.Q: If I want to make AnQiCMS execute some maintenance tasks every day at a specific time, such as cleaning the cache at 3 am, how should I configure it?
crontab?A: You should not modify it.*/1 * * * *To achieve this purpose. On the contrary, you should add a new one for this specific maintenance task.crontabEntry. For example, if AnQiCMS provides a command or script to clear the cache, you can add it like this:0 3 * * * /path/to/your/anqicms/command/clear_cache.shThis indicates that the cache cleaning script is executed at 3:00 AM every day. Please ensure/path/to/your/anqicms/command/clear_cache.shis the actual cleaning command or script path.Q:
start.shin the scriptBINPATHandBINNAMEWhat does this mean, do I need to modify them?A:BINPATHIt usually refers to the complete directory path of the AnQiCMS program, andBINNAMEwhich is the name of the AnQiCMS executable file (usuallyanqicms)。When you first install AnQiCMS, these paths should have been set according to your installation location.start.shin the scriptBINPATHandBINNAMEvariable to ensurecrontabCan correctly find and execute the program.