As a website operator who is deeply familiar with the operation of AnQiCMS, I know that a stable and reliable online environment is crucial for a content management system.Ensure that the AnQiCMS program can run automatically with the server startup and can recover itself after an unexpected interruption, which is the cornerstone for the website to stay online continuously and provide high-quality content services.The following, I will elaborate on how to set up AnQiCMS program to start automatically at boot and process guardian on a Linux server.
Deploy and monitor the AnQiCMS program on a Linux server
AnQiCMS as an enterprise-level content management system developed based on the Go language is renowned for its efficiency, security, and ease of use.But in the production environment, simply deploying the program is not enough, we also need a set of mechanisms to ensure its continuous operation.This includes the ability to automatically start after the server restarts, and to be timely restarted in case of program crashes, that is, to achieve boot-up self-start and process guardianship.
Preparation of the environment
Before starting the configuration, please ensure that your Linux server meets the following conditions:
- The MySQL database service is installed, AnQiCMS needs it to store website data.
- Installed Nginx or Apache and other Web servers, used to process users' HTTP/HTTPS requests and reverse proxy to AnQiCMS.
- You have connected to the server using the SSH client and have sufficient permissions to perform installation and configuration operations.
- You have downloaded the latest program installation package for Linux from the AnQiCMS official website.
Deployment and automatic startup configuration of AnQiCMS program
First, upload the AnQiCMS Linux installation package you downloaded to the server. Usually, we will choose a standard path for storage, such as/www/wwwroot/your_domain.com/(Please replace)your_domain.comReplace with your actual domain name). After uploading, useunzipcommand to unzip the installation package.
AnQiCMS is usually present as an executable file, for example, namedanqicms。To enable auto-startup and basic process guarding, we can use a Linux system'scrontabtool in conjunction with a simple script.
You need to create a file namedstart.shThe script file, its content is roughly as follows.This script checks if the AnQiCMS process is running, if not, it will start AnQiCMS and redirect its output to a log file.
#!/bin/bash
### check and start AnqiCMS
# author AnQiCMS Operator
# the bin name is anqicms
BINNAME=anqicms # 您的AnQiCMS可执行文件名,默认为anqicms
BINPATH=/www/wwwroot/your_domain.com # 您的AnQiCMS程序所在目录,请替换为实际路径
# 检查AnQiCMS进程是否存在
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"
# 如果进程不存在,则启动AnQiCMS
if [ $exists -eq 0 ]; then
echo "$BINNAME NOT running, attempting to start..."
# 进入程序目录,以后台方式运行AnQiCMS,并将标准输出和错误输出重定向到running.log
cd $BINPATH && nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &
echo "$(date +'%Y%m%d %H:%M:%S') $BINNAME started." >> $BINPATH/check.log
else
echo "$BINNAME is already running." >> $BINPATH/check.log
fi
Please make sure to putBINNAMEandBINPATHVariable modification to the actual path of the AnQiCMS executable file and its directory. Save this script asstart.shGo to the AnQiCMS program directory and give it execution permissions:chmod +x /www/wwwroot/your_domain.com/start.sh.
接下来,我们将配置crontab来实现自启动和进程守护。crontab允许您设置周期性执行的任务。通过让crontab每分钟执行一次start.shscript, you can ensure that AnQiCMS runs at server startup (crontab服务本身会自启动(auto)自动运行,并且即使程序因某些原因意外停止,也会在下一分钟内被crontab检测到并重新启动。
执行以下命令来编辑crontabTask list:
crontab -e
In the open text editor, add the following line of content:
*/1 * * * * /www/wwwroot/your_domain.com/start.sh
Also replace the path with yourstart.shactual script storage path. Save and exit the editor. This configuration willstart.shThe script executes once every minute. To start AnQiCMS immediately, you can execute it manually once.sh /www/wwwroot/your_domain.com/start.sh.
Configure the web server reverse proxy
AnQiCMS program listens by default.8001Port.To allow users to access your website via standard HTTP (port 80) or HTTPS (port 443), you need to configure Nginx or Apache as a reverse proxy.
For example, using Nginx, you can configure it in the site configuration file