As a website operator who has been deeply involved in the CMS field for many years, I fully understand the importance of every detail for the stable operation of the website, especially on the server side, where process management is of utmost importance. Today, let's delve into the startup script of AnQiCMS.nohupand&What key roles do these seemingly simple symbols play, and how do they ensure the continuous online operation of our website?

The cornerstone for ensuring the continuous online operation of AnQiCMS

When discussing running a web service like AnQiCMS on a Linux server, a core requirement is to ensure it can run continuously and stably, unaffected by our terminal sessions.Imagine that you connect to the server through SSH and execute the startup command for AnQiCMS. If you just press enter, then once you close the SSH terminal, the AnQiCMS process is likely to terminate as well.This is clearly not what we want to see, as it means the website will go offline immediately.nohupand&Has become an indispensable tool for us.

&: To run commands in the background

Firstly, let's get to know&Symbol. In the Linux command line, when you add it at the end of a command,&It is used to run the command in the background of the current terminal.This means you can immediately get a command-line prompt, continue to input other commands without waiting for the previous command to finish.anqicms &The system will attempt to start the AnQiCMS service in the background.

Although&It allows commands to run in the background, freeing up our terminal, but it has an important limitation: the background process is still a child process of the current terminal session. When the SSH session is closed, the system sends a signal to all processes associated with that session.SIGHUP[Hang up] signal. By default, receivingSIGHUPthe signal will terminate the process. This means, using only&It still cannot be guaranteed that AnQiCMS will continue to run after the terminal is closed, the website still has the risk of going offline.

nohup: The guardian against hang-up signals.

To overcome&The limitations of the situation,nohupCommand was born.nohupis abbreviated as “no hang up”, as the name implies, its main function is to make the subsequent commands ignoreSIGHUPsignal. ThroughnohupExecuted commands, even if the parent process (such as our SSH terminal) exits, will not receiveSIGHUPa signal to terminate and thus can continue to run.

In addition,nohupWhen executing commands, the standard output and standard error will also be automatically redirected tonohup.outIn the file (if no other file is specified), this is done to prevent errors when a process tries to write data to the standard output or standard error without an associated terminal.This provides convenience for us to subsequently view the operation logs and potential errors of AnQiCMS.

Combination attack:nohup command &the powerful effect of

tonohupand&used together, that isnohup command &This is the most commonly used method for starting background services in our production environment. The advantage of this combination is:

  • Process persistence:nohupEnsuring that the AnQiCMS process can withstandSIGHUPSignal, the service can continue to run uninterrupted even if the terminal session is closed.
  • Terminal liberation:&Enables the command to enter the background immediately, allowing the operator to continue using the current terminal to perform other tasks.
  • Log recording:nohupThe default behavior is to redirect the output to a file, which is crucial for AnQiCMS operation monitoring and problem troubleshooting.

In AnQiCMSstart.shIn the startup script, we can see the typical application of this combination:

nohup $BINPATH/$BINNAME >> $BINPATH/running.log 2>&1 &

Let's break down this command:

  • nohup: Ensure that the AnQiCMS main program ($BINPATH/$BINNAME) ignores hangup signals.
  • $BINPATH/$BINNAME: This is the variable pointing to the AnQiCMS executable file.
  • >> $BINPATH/running.log: Append all standard outputs of the AnQiCMS program (such as, information during normal operation) to$BINPATH/running.logthe file.>>Represents appending, avoiding overwriting previous logs.
  • 2>&1This is an important redirection operation.2Represents standard error output.1Represents standard output.2>&1The meaning is to redirect the standard error output to the same place as the standard output. This way, whether it is the normal operation log of AnQiCMS or any possible error information, they will be recorded uniformly.running.logIn the file, it is convenient for us to focus on and analyze.
  • &: Finally, this symbol will put the entirenohupcommand itself into the background to run,start.shThe script execution is complete and the command line prompt is returned immediately.

Passnohupand&The combination, AnQiCMS can be run as an independent background process stably, and its output information is properly recorded without being affected by the disconnection of the terminal.This is of decisive significance for ensuring the website operates 7x24 hours without interruption, enhancing user experience, and enabling our operation team to manage efficiently.

Frequently Asked Questions

How can I confirm that AnQiCMS is really running in the background after it starts?

You can useps -ef | grep anqicmscommand to view all running processes. If AnQiCMS is running, you will see in the output a process that includesanqicmsprocess information with the keyword, which is usually a process bynohupStarted.

How should I stop the AnQiCMS service if I want to?

There is usually a script provided in the AnQiCMS installation directory.stop.shThis script will look foranqicmsProcess sends a termination signal. If manual stopping is needed, first useps -ef | grep anqicmsFind the PID (Process ID) of the AnQiCMS process, then usekill -9 [PID]command to force terminate the process.

If I forget to usenohupor&What will happen when starting AnQiCMS?

If only startinganqicms[en] If not modified, AnQiCMS will run as a foreground process, occupying your terminal until you manually stop or close the terminal. If only usinganqicms &【en】, AnQiCMS will run in the background, but once you close the SSH session, the AnQiCMS process is likely to receiveSIGHUPSignal and terminate, resulting in the website going offline. Therefore, it is imperative to use in a production environment.nohup ... &combination.