How to manage the startup of different instances of `crontab` when deploying AnQiCMS across multiple sites?

Calendar 👁️ 66

AnQiCMS with its efficient and flexible architecture provides strong support for enterprise content management.Especially when dealing with multi-site requirements, AnQiCMS provides various deployment solutions, one of which is to run multiple independent AnQiCMS instances on the same server to manage different websites.How to cleverly utilize when adopting this deployment modecrontabSchedule tasks to ensure the stable startup and continuous operation of these different instances have become a key link that website operators need to understand in depth.

This article will focus on this topic, elaborating on the AnQiCMS multi-instance deployment undercrontabmanagement strategy, aimed at helping you build a robust, high-availability multi-site environment.

Understand the multi-site deployment mode of AnQiCMS

There are usually two main ways of multi-site deployment in AnQiCMS. One isSingle AnQiCMS instance manages multiple websitesYou can configure multiple domains in an AnQiCMS backend, and use reverse proxy to direct different domains to the same AnQiCMS service port (such as 8001). The system internally resolves the domain to different website content. In this mode, there is only one AnQiCMS process running, socrontabPay attention only to the startup and maintenance of this process.

However, what we are focusing on today is another deployment method with more isolation:Run multiple independent AnQiCMS instances on a serverThis means that each AnQiCMS instance is an independent Go language executable file and its accompanying data and configuration, each listening on a different port and managing one or more websites.This pattern provides higher isolation and independence, but it also brings the need for multi-process management, especially after server restarts or unexpected process termination, how to ensure that each instance can be automatically started up iscrontabWhere it plays a role.

Of a single AnQiCMS instancecrontabStartup mechanism

AnQiCMS provided a simple and efficientstart.shThe script to manage the startup of a single instance. The core logic of this script is to check if the AnQiCMS process is already running, and if not, start it.This is usually achieved by checking the name of the specific executable file in the process list.

A typicalstart.shThe script content may look like this:

#!/bin/bash
### check and start AnqiCMS
# author fesion
# the bin name is anqicms
BINNAME=anqicms
BINPATH=/www/wwwroot/anqicms_site1 # 假设这是实例1的路径

# 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"
    cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &
fi

In order to run this script automatically in the system background and regularly check the AnQiCMS process, we will configure it tocrontabChinese. For example, set it to execute once every minute to ensure process stability:

# 编辑 crontab
crontab -e

# 在打开的编辑器中添加一行,指向您的 start.sh 脚本路径
*/1 * * * * /www/wwwroot/anqicms_site1/start.sh

Here/www/wwwroot/anqicms_site1is the deployment directory of your first AnQiCMS instance.

Manage expansion to multiple AnQiCMS instances

When you need to run multiple independent AnQiCMS instances on the same server, the core principle of management strategy isProvide a set of independent and distinguishable startup and monitoring mechanisms for each instance. The design of AnQiCMS allows you to achieve this by copying its program code.

  1. Copy instance code and configurationFirstly, you need to create a complete code copy for each independent AnQiCMS instance. For example, if you haveanqicms_site1instance, now you need to addanqicms_site2Then you should create a similar directory on the server/www/wwwroot/anqicms_site2and copy all AnQiCMS files (including executable files,config.jsonetc.) to the new directory.

  2. Configure a separate portEach AnQiCMS instance must listen to a unique port. Find the file in the root directory of each instance,config.jsonand modify the following in the file,portThe field has different values. For example,anqicms_site1Use8001,anqicms_site2then it is modified to8002,anqicms_site3Use8003and so on.

  3. Rename the executable file (recommended practice)for conveniencecrontabScript and system monitoring can clearly distinguish between different AnQiCMS processes, it is strongly recommended that you rename the AnQiCMS executable files in each instance directory. For example, change/www/wwwroot/anqicms_site1/anqicmsRenamed toanqicms_site1_bin, will/www/wwwroot/anqicms_site2/anqicmsRenamed toanqicms_site2_binThe benefit of doing this is that when you executeps -ef | grep anqicmsthe command, you can clearly see the process information of each instance and avoidgrepmismatching with other related processes.

  4. Create an independent one for each instancestart.shscriptCreate customized for each AnQiCMS instance based on the renamed executable file and their respective installation pathsstart.shscript. The logic of these scripts is similar to that of a single instance, butBINNAMEandBINPATHthe variables will point to the unique information of each instance.

    For example,anqicms_site2ofstart.shscript

Related articles

If AnQiCMS `crontab -e` opens another editor, how to 'save and exit'?

As an experienced website operations expert, I am well aware of the importance of efficient and stable system operation for AnQiCMS and other enterprise-level content management systems.When deploying and maintaining AnQiCMS, we often encounter scenarios where we need to configure scheduled tasks (crontab), such as the `start.sh` script mentioned in the `install.md` that is used to guard the AnQiCMS process.However, when executing the `crontab -e` command, many users may find that the editor opened is not the one they are familiar with

2025-11-06

How to automatically restore the service after the AnQiCMS server restarts using `crontab`?

As an experienced website operations expert, I know that the stable operation of the website is the foundation for the continuous exertion of content value.For systems like AnQiCMS that are dedicated to providing efficient and reliable content management solutions, ensuring the continuous online service is of paramount importance.Unexpected server restarts, whether planned maintenance or sudden situations, can lead to service interruption of AnQiCMS, thereby affecting user access and content presentation.Therefore, mastering how to automatically recover AnQiCMS services after server restart is a necessary skill for every operator. Today

2025-11-06

How to ensure that the AnQiCMS `start.sh` script has the correct execution permissions in `crontab`?

As an experienced website operations expert, I am well aware that the stable operation of AnQiCMS, such an efficient content management system, is inseparable from the careful configuration of every detail.Among them, using `crontab` to guard the `start.sh` script to ensure that the AnQiCMS service remains online is an important means for many operators to ensure the reliability of the website.However, in this process, file execution permission issues often become a "bottleneck" for many users.Today, let's delve into how to ensure your AnQiCMS `start

2025-11-06

After AnQiCMS upgrade, how should the original `crontab` startup task be adjusted and 'save and exit'?

In the daily maintenance of AnQiCMS website operation, system upgrade is the key link to enhance functions, optimize performance, and enhance security.However, after the upgrade, we often need to conduct detailed checks and adjustments on some background tasks, especially those relying on the `crontab` daemon process startup tasks.As an experienced website operation expert, I know the importance of these details for the stable operation of the website.Today, let's delve into how to adjust the original `crontab` startup tasks after the AnQiCMS upgrade, as well as how to correctly 'save and exit' these changes

2025-11-06

What is the role of the `nohup` command in the `start.sh` script for the continuous operation of AnQiCMS?

As an experienced website operations expert, I fully understand the importance of a stable and reliable content management system for a corporate website.AnQiCMS (AnQi CMS) leverages the efficiency and concise architecture of the Go language to provide an excellent content management experience for many enterprises.However, even the most powerful system also needs correct deployment and maintenance to ensure its continuous and efficient operation.Today, let's delve into the seemingly insignificant `nohup` command in the `start.sh` script, and explore its crucial role.

2025-11-06

How to check `crontab` configuration and 'Save and Exit' when AnQiCMS back end is inaccessible?

AnQi CMS is an efficient and customizable enterprise-level content management system, whose stable operation is crucial for website operation.When you suddenly find that the AnQiCMS backend is inaccessible, that anxious feeling is something we operators are all too familiar with.Among many possible reasons, incorrect `crontab` configuration or operation errors during editing are often overlooked yet crucial points.Today, let's delve into how to systematically investigate this issue and master the correct posture for 'save and exit' in `crontab`.

2025-11-06

In AnQiCMS scheduling task, how to correctly delete the `start.sh` task that is no longer needed?

As an experienced website operations expert, I am well aware of the importance of configuring and maintaining each system task for the stable operation of the website.AnQiCMS (AnQiCMS) is highly praised for its efficiency and convenience in the field of content management.In daily operations, we sometimes encounter situations where we need to adjust or remove specific tasks, such as the `start.sh` scheduled task that is no longer needed.Handle these tasks properly, not only does it concern the effective utilization of server resources, but also relates to the overall cleanliness and safety of the system.Today, let's delve into it in detail, when you decide not to let `start

2025-11-06

What is the meaning and modification suggestion of `*/1 * * * *` in the AnQiCMS `crontab` configuration?

As an experienced website operations expert, I am happy to give you a detailed explanation of the meaning and modification suggestions of the `crontab` configuration `*/1 * * * *` in AnQiCMS.An enterprise CMS with its high efficiency, stability, and easy scalability has won the favor of many small and medium-sized enterprises and content operators. The automated mechanisms behind it, such as scheduled tasks (`crontab`), are one of the key factors for its stable operation.

2025-11-06