Why does the AnQiCMS `stop.sh` script use the `pwd` command to determine BINPATH?

Calendar 👁️ 61

As an experienced CMS website operation personnel, I am well aware of the importance of the stable operation of the content management system to the business of the website.In routine maintenance, we frequently deal with the startup and shutdown scripts of the system.For the AnQi CMS, itstop.shScripting usespwdCommand to dynamically determineBINPATHVariables, this reflects the designer's careful consideration in ensuring system robustness and user operation convenience.

AnQi CMS is a system developed based on the Go language, committed to providing an efficient and customizable content management solution. During the deployment and operation process, its executable files, as well as related logs and configuration files, all need to have a clear storage location. In order to facilitate user management, AnQi CMS providesstart.shandstop.shThis Shell script automates the start and stop of services.

First, let's understandBINPATHThe role of these scripts.BINPATHThe variable usually points to the directory where the AnQi CMS executable file is located. When the script needs to execute the executable file (such as the startup command) or access the resources in the same directory (such as log filesrunning.log/check.logor need to depend on searching for the PID of a running processBINPATHto accurately locate these positions.

Instart.shIn the script, we might seeBINPATHexplicitly set to an absolute path, for example/www/wwwroot/anqicmsThis is usually manually configured by the website administrator during the initial installation, based on the actual deployment location. It assumes that the executable file of AnQiCMS will always be located at this fixed position.

However, instop.shIn the script,BINPATHThe definition method is more clever and general:BINPATH="$( cd "$( dirname "$0" )" && pwd )"This command does not directly specify a fixed path, but dynamically calculates the absolute path of the script. This line of command can be understood by breaking it down into several steps:

$0In the Shell script,$0represents the path to the current executed script file, including the filename. For example, ifstop.shIn/www/wwwroot/anqicms/In the directory, then$0may be just/www/wwwroot/anqicms/stop.sh.

dirname "$0"This command is used to$0Extract the directory part, that is, remove the filename. For example,dirname "$0"it will return/www/wwwroot/anqicms.

cd "$( dirname "$0" )"This step is crucial. It changes the working directory of the current Shell session tostop.shThe directory of the script. This is done to ensure that all subsequent commands are executed relative to the script's directory.

pwdIncdAfter the command is executed,pwdThe (Print Working Directory) command prints the absolute path of the current working directory. As the previous step has alreadycdReached the directory of the script, thereforepwdWhat is output at this time isstop.shThe absolute directory of the script.

Finally, through$(...)This Shell command substitution syntax, willpwdAssign the output toBINPATHA variable, thus achieving dynamic acquisition of the absolute path of the script's directory.

Then, why?stop.shIt is necessary to calculate the path dynamically with such effort, rather than likestart.shWhy use a fixed absolute path directly? This is mainly based on the following important considerations:

Flexibility of operation: The website administrator may execute from any directorystop.shScript, for example/rootdirectory, a custom script directory, or directly through/etc/init.d/anqicms stopsuch service management command calls. Ifstop.shit depends on a hard-coded absolute path

Related articles

Is the traditional `start.sh` process guardian method still necessary when deploying AnQiCMS in Docker containers?

As a website manager who is deeply familiar with AnQiCMS (AnQiCMS) operation, I deeply understand that efficiency, stability, and scalability are core considerations when deploying and maintaining a website.With the popularity of containerization technology, many teams choose Docker to deploy AnQiCMS.This naturally leads to a key question: Is the traditional `start.sh` process guardian method still necessary when deploying AnQiCMS in Docker containerization?

2025-11-06

How to simulate the core process crash of AnQiCMS to comprehensively test the automatic restart capability of the `start.sh` script?

As an experienced CMS website operation personnel of an enterprise, I am well aware of the importance of system stability and rapid recovery capabilities for content platforms.Even the most robust systems may terminate their core processes due to unforeseen reasons.This is when a reliable automatic pull-up mechanism becomes the last line of defense to ensure the continuous operation of the website.The `start.sh` script provided by Anqi CMS is for this purpose.

2025-11-06

Does the writing of `start.sh` and `stop.sh` scripts follow the Linux shell script practices and security standards?

As an expert in website operation familiar with Anqi CMS, I know that system stability and security are crucial for the daily operation of any website.The startup and shutdown scripts are critical components for managing AnQiCMS services in the Linux environment, and their coding quality directly affects the reliability and maintainability of the system.Next, I will analyze the `start.sh` and `stop.sh` scripts of AnQiCMS in detail based on the provided AnQiCMS document, evaluating their performance in terms of Linux shell script practices and security standards.

2025-11-06

How does the Go language high concurrency architecture of AnQiCMS协同with process guardian scripts to ensure the high performance and stability of the system?

AnQiCMS is an enterprise-level content management system developed based on the Go language, which has always put high performance and high availability as its core competitiveness since its inception.In actual operation, website performance and stability are the key to attracting and retaining users.AnQiCMS through its unique Go language high concurrency architecture design, combined with mature process guardian scripts, jointly builds a robust system that can withstand huge traffic pressure and ensure continuous online services.

2025-11-06

How should the `start.sh` script-generated `check.log` and `running.log` log files be managed and cleaned on a regular basis?

As a website operator who has been dealing with Anqi CMS for a long time, I know that the stable operation of the system cannot be separated from meticulous maintenance work.The log file, as a faithful recorder of the system's status, is of great importance.However, if not properly managed, they may also become potential sources of problems, such as occupying a large amount of disk space, reducing troubleshooting efficiency, and so on.

2025-11-06

What is the special meaning of the `\<` and `\>` symbols in the `grep` command when matching process names in the `start.sh` script?

As an experienced soldier who deeply understands the operation of AnQiCMS, I know that stable system operation is the foundation of content creation and distribution.When maintaining the AnQiCMS server, we often encounter situations where we need to check or manage processes, and the `start.sh` script is a key component to ensure that the AnQiCMS service remains online.In the `start.sh` script, there is a line used to check if the AnQiCMS process is running, which includes the `grep` command and the unique `<` and `>` symbols, which seem to be simple characters

2025-11-06

`start.sh` script can be integrated with more advanced process monitoring tools (such as `Monit` or `Supervisor`)?

As a professional who has been responsible for the operation of the AnQiCMS website for a long time, I am well aware that the stable and efficient operation of the system is crucial for content publishing and user experience.AnQi CMS has won the favor of users with its high-performance and concise architecture developed in Go language.In the deployment and daily operation and maintenance, we often encounter a problem: how to ensure the continuous and stable operation of the AnQiCMS application, especially in the face of unexpected crashes or server restarts.

2025-11-06

How can the security of the AnQiCMS process be ensured if the `start.sh` script itself fails or is tampered with?

As an experienced AnQiCMS website operations manager, I am well aware that system stability and security are crucial for content management.AnQiCMS provides a solid foundation for users with its high performance and security brought by the Go language development, but even so, any system cannot do without the guarantee of its operating environment.Regarding the security of the `start.sh` script, it is a fundamental issue involving system startup and process management, and its importance should not be overlooked.### `start

2025-11-06