How to set up AnQiCMS to start automatically on Linux server (Crontab)?

Calendar 👁️ 67

As an experienced CMS website operation personnel of an enterprise security company, I am well aware of the importance of stable operation of the website, especially after the server is unexpectedly restarted, the system can automatically restore the service, which is crucial for ensuring user access experience and avoiding operation interruption.AnQiCMS (AnQiCMS) is an efficient and concise content management system developed in Go language, with flexible deployment methods, but how to ensure it starts up automatically on a Linux server is a concern for many operators.CrontabService, set AnQiCMS to start up automatically at boot.

Understand the necessity of starting up automatically at boot.

During the operation of the website, the server may be restarted due to maintenance, system updates, hardware failures, or unexpected events.If AnQiCMS is not configured to start up automatically, you will need to manually log in to the server and execute the start-up command every time the server is restarted, which will waste valuable time and may cause service interruptions.CrontabWe can ensure that AnQiCMS runs automatically after the server starts, greatly enhancing the stability and operation and maintenance efficiency of the website.

Overview of AnQiCMS's self-starting mechanism

AnQiCMS takes ease of startup and shutdown into consideration during design. Its installation package usually includes astart.shscript.This script is the core of the auto-startup, it is responsible for checking whether the AnQiCMS process is running, if not running, it will start the AnQiCMS service in the background.CrontabThe function is to execute this at regular intervals (usually set to every minute)start.shscript to achieve the purpose of 'monitoring' and 'auto-starting' AnQiCMS. This method is more efficient compared to the traditionalsystemdService configuration, more lightweight and flexible, especially suitable for scenarios with limited resources or those who wish to quickly deploy.

Set Crontab task

To set AnQiCMS to start up automatically at boot, we mainly use the services of the Linux system'sCrontabto complete.Crontabis a service used to set periodic task execution.

First, you need to log in to your Linux server and openCrontabthe configuration file for editing. This is usually done by executing the following command in the terminal:

crontab -e

After executing this command, the system will open a text editor (usually Vim or Nano), where you can add or modify scheduled tasks. Make sure you are familiar with the basic operations of the editor you are using, such as pressingiEnter edit mode, press after editing is completeEscExit edit mode and then enter:wqSave and exit.

InCrontabAt the end of the file, you need to add a new task to execute the AnQiCMS startup script regularly. Here is the recommended configuration example:

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

The meaning of this configuration is:

  • */1 * * * *Indicates that the task will be executed every minute.
  • /www/wwwroot/anqicms.com/start.shThis isstart.shThe complete path of the script. Please make sure to replace this path with the actual installation directory of your AnQiCMS.start.shScript path. For example, if your AnQiCMS is installed in/opt/anqicmsdirectory, then the path should be/opt/anqicms/start.sh.

save and exitCrontabafter the file,CrontabThe service will automatically load the new configuration, and your task will start taking effect.

Deep understandingstart.shscript

To better understand the self-startup process, it is necessary to know.start.shHow scripts work. Provided by AnQiCMS.start.shScripts usually include the following logic:

#!/bin/bash
### check and start AnqiCMS
# author fesion
# the bin name is anqicms
BINNAME=anqicms
BINPATH=/www/wwwroot/anqicms.com # 这里的路径需要根据您的实际安装路径修改

# 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
  • BINNAME=anqicms: Defines the executable file name of AnQiCMS.
  • BINPATH=/www/wwwroot/anqicms.com: Defined the installation path of AnQiCMS.This is the place you need to check and modify during actual operation, ensuring it is consistent with your AnQiCMS deployment path.
  • ps -ef | grep '\<anqicms\>' |grep -v grep |wc -l: A series of pipeline commands to check if there is a namedanqicmsare currently running.
    • ps -ef: List all running processes.
    • grep '\<anqicms\>': Filter lines containing the string "anqicms".\<and\>Is a word boundary, make sure to match the executable file name accurately.
    • grep -v grepExclude:grepIts own process to avoid misjudgment.
    • wc -lCount the number of lines matched, that is, the number of running AnQiCMS processes.
  • if [ $exists -eq 0 ]: If the process count is 0 (i.e., AnQiCMS is not running), then execute the subsequent startup command.
  • cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &: This is the core startup command for AnQiCMS.
    • cd $BINPATHSwitch to the AnQiCMS installation directory to ensure the program runs in the correct environment.
    • nohup $BINPATH/$BINNAME: Use.nohupCommand to start the AnQiCMS executable file.nohupEnsure that the program continues to run in the background even if the terminal is closed.
    • >> $BINPATH/running.log 2>&1Redirect the standard output and standard error of the program torunning.loga file for subsequent viewing of runtime logs and troubleshooting.
    • &Run the program in the background.

Execute manually for the first time.start.sh

After you have configured it.CrontabConfirm the task.start.shAfter confirming that the script path is correct, it is recommended that you execute it manually once.start.shScript to immediately start the AnQiCMS service and verify if the script works properly:

/www/wwwroot/anqicms.com/start.sh # 替换为您的实际路径

After executing, you can check if AnQiCMS has started, for example by visiting your website, or usingps -ef | grep anqicmsthe command again to view the process list.

Nginx/Apache Reverse Proxy Configuration

Although this does not directly belong to the category of boot-up self-startup, but in order for AnQiCMS to access through standard HTTP/HTTPS ports (such as 80 or 443), it is usually necessary to configure Nginx or Apache as a reverse proxy.AnQiCMS runs by default on port 8001, the reverse proxy will forward external requests to this port.You can refer to the AnQiCMS document for configuration guidelines on Nginx or Apache reverse proxy to ensure your website can be accessed normally.

location @AnqiCMS {
    proxy_pass https://en.anqicms.com;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}

Make sure your Nginx or Apache service is also configured to start on boot (this is usually the default setting, throughsystemctl enable nginxorsystemctl enable apache2Implementation).

Precautions for multi-site deployment

If you deploy multiple AnQiCMS instances on a single server, each instance requires an independentstart.shscript, executable file (or at least a unique process name) and the running port. The document mentions that it can:

  1. Copy multiple copies of AnQiCMS code to different directories.
  2. Edit each instanceconfig.jsonofportChange to a new port (such as 8002, 8003).
  3. Rename the AnQiCMS executable file to a new, different filenameFor example, rename according to the domain name (such astaobaokeReplaceanqicms)
  4. Modify each accordinglystart.shin the scriptBINNAMEVariable, as well asgrepThe name matched in the command to match the new executable file name.
  5. For each instance inCrontabAdd an independent task that points to the correspondingstart.shscript.

For example, if you have a second AnQiCMS instance, the executable file name ismyanqicms, the path is/www/wwwroot/myanqicms.com, and the port is 8002, then itsstart.shThe script should be modified to:

#!/bin/bash
BINNAME=myanqicms
BINPATH=/www/wwwroot/myanqicms.com
exists=`ps -ef | grep '\<myanqicms\>' |grep -v grep |wc -l`
# ... 其他保持不变 ...

and thenCrontabAdd:

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

By following these steps, you can ensure that AnQiCMS can be reliably started up automatically on a Linux server, making your website operation more worry-free.

Frequently Asked Questions (FAQ)

1. I have configured Crontab, but AnQiCMS did not start after the server restart. How should I troubleshoot?

First, please check whether the CDN link you have included in the file is correct and accurate, including the URL address,Crontabconfiguredstart.shThe script path is correct and the script has executable permissions(chmod +x /path/to/start.sh). Next, checkstart.shThe defined in the scriptBINPATHandBINNAMEDoes the variable match the actual installation path and executable file name of your AnQiCMS? You can also checkrunning.logandcheck.logFiles (usually in the AnQiCMS installation directory), these log files record the execution status of the scripts and the startup output of AnQiCMS, from which specific error information can be found. In addition, please ensure that no other process is using the port required by AnQiCMS (default is 8001), you can uselsof -i:8001Check the command.

2. Crontab runs every minute.start.shWill this cause AnQiCMS to be started multiple times?

No. AnQiCMS'sstart.shThe script includes process check logic.It will first check if the executable file of AnQiCMS is already running.If the AnQiCMS process is detected running, the script will exit directly without attempting to start again.The script will execute the actual startup command only when the AnQiCMS process is not running.start.shThe purpose of the script is to "guard" the AnQiCMS process, ensuring it always runs instead of restarting repeatedly.

3. If my AnQiCMS executable file name has been changed,start.shhow should the script be adjusted?

if the AnQiCMS executable file name is no longer the default oneanqicmsFor example, you have changed it tomywebsite_cmsThen you need to editstart.shthe script, andBINNAMEThe value of the variable is fromanqicmsis modified tomywebsite_cms. Meanwhile, the script internally uses `grep '<anq'

Related articles

How to configure AnQiCMS's Nginx proxy in the Linux command line environment?

As a senior CMS website operation person in an enterprise, I know that stable and efficient deployment is the foundation of successful website operation.Under Linux, Nginx, as a high-performance reverse proxy server, is the ideal partner for AnQiCMS, and can effectively improve the speed and security of website access.I will introduce in detail how to configure Nginx in the Linux command line environment to provide a stable and reliable reverse proxy service for AnQiCMS.

2025-11-06

How to configure reverse proxy for AnQiCMS on Apache server?

AnQiCMS (AnQiCMS) is an enterprise-level content management system developed based on the Go language, known for its high performance, security, and ease of use.It is usually not recommended to expose the application listening port (such as the default 8001) directly to the external network when deploying this type of application.On the contrary, by configuring a reverse proxy such as Apache, a more secure, more stable, and feature-rich access method can be provided for the AnQiCMS website.By configuring Apache to set up reverse proxy, you can achieve many advantages: First

2025-11-06

How to configure Nginx pseudo static rules in AnQiCMS multi-site mode?

AnQi CMS is an efficient and customizable content management system that provides strong support for multi-site operations while meeting diverse content display and management needs.For website operators, the configuration of pseudo-static URLs is a key factor in improving user experience and optimizing search engine rankings.It is particularly important to configure Nginx's pseudo-static rules reasonably in the multi-site mode of AnQi CMS.

2025-11-06

What is the practice of installing multiple AnQiCMS sites on the same server?

As an experienced CMS website operation person, I know how important it is to manage multiple websites efficiently on a single server.The AnQi CMS was designed with the need for multi-site management in mind, providing users with a flexible and powerful solution.The following article will detail the **practice** of installing and managing multiple AnQiCMS sites on the same server.

2025-11-06

How to perform local development and testing of AnQiCMS in Windows environment?

As an operator who is deeply familiar with the operation of AnQiCMS, I fully understand the importance of sufficient local development and testing before formal launch to ensure the quality of website content, user experience, and system stability.Set up an efficient AnQiCMS local development environment under the Windows environment, which allows you to freely create, edit, publish, and optimize content, while also performing various function tests, thereby greatly improving work efficiency.The following will elaborate on how to carry out local development and testing of AnQiCMS in a Windows environment.###

2025-11-06

How to safely stop or close the AnQiCMS program running on Windows?

As an experienced website operator who deeply understands the operation of security CMS, I am fully aware of the importance of program security, stable operation, and the ability to stop safely when necessary.Whether it is for system maintenance, version upgrade, or daily development and testing, correctly shutting down the AnQiCMS program is a critical step to ensure data integrity and system stability.Under Windows operating system environment, stopping or closing the AnQiCMS program is usually a direct process.Because AnQiCMS is an independent executable file developed based on the Go language

2025-11-06

How do MacOS users install and test AnQiCMS?

As an experienced enterprise CMS website operator, I know the importance of content management systems for enterprises and self-media.AnQiCMS stands out among many CMS systems for its efficiency, flexibility, and security.For MacOS users, the simple deployment process makes local development and testing particularly convenient.Now, I will give you a detailed introduction on how to install and test AnQiCMS on MacOS.

2025-11-06

What should I do if I encounter port occupation problem during AnQiCMS installation?

As a website operator who has been deeply involved in AnQiCMS for many years, I know that even a small technical detail can become a stumbling block for users to successfully go online.Among them, port occupation problems are typical scenarios often encountered when initially installing or expanding AnQiCMS.Today, let's delve into how to efficiently identify and resolve port occupation issues when installing AnQiCMS.Understanding Port Usage Problem First, let's understand what port usage is.In network communication

2025-11-06