As an experienced website operations expert, I know that a stable-running website cannot do without proper management of the background scripts.AnQiCMS with its efficient and secure features is deeply loved by our operations staff.In routine maintenance, whether it is for version upgrades, configuration adjustments, or simple restart operations, we may need to use the system's built-instop.shandstart.shScript. However, a seemingly simple operation may be受阻 due to a minor permission issue. Today, let's delve into how to ensure the stability of AnQiCMS'sstop.shThe script has sufficient execution permissions to make your maintenance work smoother.
Understandingstop.shThe importance of the script
In the AnQiCMS running environment,stop.shThe script plays a crucial role. It is usually responsible for safely terminating the background process of AnQiCMS.Imagine when we need to update the system, adjust the configuration, or simply restart the service, ifstop.shUnable to execute normally, may cause the service to stop abnormally, affecting subsequent operations, or may cause data inconsistency or service exceptions.The essence of this script is a set of shell commands, which will find the PID (Process Identifier) of the AnQiCMS process and then send a signal to terminate it.Therefore, ensuring that it can be "executed" and "has the right to execute" the corresponding system operations is the foundation for the stable operation of the website.
Why do permission issues occur?
In Linux systems, file permissions are very strict, which is for system security reasons.Each file and directory has its owner, group, and read (r), write (w), and execute (x) permissions for the owner, group, and other users.A shell script, if it is not marked as 'executable', then the system does not know how to run it.It's like you've got a manual, but it's locked in a box and you can't open it to read.
Generally, when we manually upload files or during certain automated deployment processes,stop.shscripts may lose execution permissions due to incorrect permission settings. For example, file permissions may be-rw-r--r--This means that the owner has read and write permissions but no execution permissions, while other users can only read.
How to checkstop.shexecution permissions?
Checkstop.shThe execution permission of the script is not complicated, we need to connect to the Linux server where your AnQiCMS is located via the SSH client.
First, you need to locate the installation directory of AnQiCMS. According to the deployment guidelines of AnQiCMS, this directory is usually located in/www/wwwroot/anqicmsor a similar path. You can usecdCommand to enter the directory:
cd /www/wwwroot/anqicms # 替换为你的实际安装路径
After entering the directory, usels -lCommand to viewstop.shThe detailed permission information of the file:
ls -l stop.sh
You will see a line output similar to the following:
-rw-r--r-- 1 www www 500 Jun 7 10:30 stop.sh
Or:
-rwxr-xr-x 1 www www 500 Jun 7 10:30 stop.sh
We need to focus on the first 10 characters on the left.
- the first character
.ordIndicates the file type (-Indicates a regular file,dIndicates a directory). - The next 9 characters are divided into three groups, representing the permissions of the file owner (owner), the file group (group), and other users (others):
rwxIndicates read, write, and execute permissions.rw-Indicates read and write permissions, no execute permission.r-xIndicates read and execute permissions, no write permission.
Ifstop.shPermissions displayed as-rw-r--r--This means that the owner and other users do not have execution permissions (x), then when you try to run./stop.shWhen, the system will prompt “Permission denied” (insufficient permissions).
How to grantstop.shexecution permissions?
Granting script execution permission is very direct. In the Linux system, we usechmodcommands to modify file permissions.
The simplest and most common method is to usechmod +xThe command, it adds execute permission for the owner, group, and other users:
chmod +x stop.sh
After executing this command, you can use it againls -l stop.shConfirm that the permissions have been changed to-rwxr-xr-x.
If you want to control permissions more finely, or ensure that it has secure universal permissions, you can use the numeric pattern:
chmod 755 stop.sh
Here755Means:
7(rwx): The file owner has read, write, and execute permissions.5(r-x): The group owning the file has read and execute permissions.5(r-x): Other users have read and execute permissions.
This755The permission setting is usually the recommended practice for shell scripts, as it allows the owner of the script to have complete control over the script while allowing other users to run but not modify the script.
when executingchmodWhen issuing commands, if the currently logged-in user is not the file owner or does not have sufficient permissions, the system may prompt insufficient permissions. At this time, you need to add before the commandsudoExecute with superuser privileges:
sudo chmod +x stop.sh
Or
sudo chmod 755 stop.sh
Verify and test the script
After modifying the permissions, be sure to verify and test.
- Confirm the permissions again:Run
ls -l stop.shTo ensure that the permissions are displayed as-rwxr-xr-x. - Start AnQiCMS:Ensure AnQiCMS is running. You can check if there is a running process for AnQiCMS by executing
ps -ef | grep anqicms. - Attempt to stop the service:Now, try to run
stop.shScript:
If your current user is not./stop.shstop.shthe owner, oranqicmsthe process is run by another user (such aswwwUser initiated, to ensurestop.shYou have permission to terminate the process, you may need to usesudoTo run:sudo ./stop.sh - Verify the stop result:Run again
ps -ef | grep anqicmsIf the AnQiCMS process does not display or only remainsgrepthe command itself, then congratulations to you,stop.shthe script has been executed successfully.
By this series of steps, you have not only solvedstop.shThe issue of execution permissions also deepened my understanding of Linux file permission management. This is a very practical skill for any website operator.
Frequently Asked Questions (FAQ)
Q1:chmod +xandchmod 755What is the difference? Which one should I use?
chmod +x stop.shThe command will add (+) execution (x) permissions for the file owner, group, and other users, but will not change other permissions (read/write). While `chmod 7