Understand Linux system /etc/init.d directory and /etc/rc.local script

  The English version of this article is from: http://www.ghacks.net/2009/04/04/get-to-know-linux-the-etcinitd-directory/

     The following content is the author's own translated version. If you need to reprint it to other websites outside CSDN, please indicate the link to this article.

 1. About /etc/init.d

     If you have ever used a Linux system, then you must have heard of the init.d directory. What is this directory for? It boils down to only one thing, but it's a big thing, it's done for the whole system, so it's very important. The init.d directory contains many start and stop scripts for various system services. It controls everything from acpid to x11-common. Of course, init.d is far from simple. (Translator's Note: acpid is a new power management standard for linux operating systems ; X11 is also called X Window System, X Window System (X11 or X) is a bitmap display window system. It is used in Unix and Unix-like  operating systems  , and  standard toolkits and protocols for building graphical user interfaces on OpenVMS and available for almost existing modern operating systems ).

    When you look in the /etc directory, you will find many directories in the form of rc#.d  (where # represents a specified initialization level, ranging from 0 to 6). Under these directories, there are many scripts that control the process. These scripts either start with "K" or "S". Scripts starting with K run before scripts starting with S. Where these scripts are placed will determine when they start running. Between these directories, system services work together like a healthy machine. However, sometimes you want to be able to cleanly start or kill a process without using the kill or killall commands. This is where /etc/init.d comes in handy!

    If you are using a Fedora system, you can find this directory: /etc/rc.d/init.d. In fact, no matter where init.d is placed, it plays the same role.

     To be able to use the scripts in the init.d directory, you need to have root or sudo privileges. Each script will be run as a command structured roughly like this:

     /etc/init.d/command options

     comand is the actual running command, the options can be as follows:

  • start
  • stop
  • reload
  • restart
  • force-reload

       In most cases, you will use the start,stop,restart options. For example, if you want to shut down the network, you can use a command of the form:

     

         /etc/init.d/networking stop

        As another example, you have changed network settings and need to restart the network. You can use the following command:

        /etc/init.d/networking restart

        Common initialization scripts in the init.d directory are:

       

  • networking
  • samba
  • apache2
  • ftpd
  • sshd
  • dovecot
  • mysql

         Of course, you may have other more commonly used scripts, depending on what linux operating system you have installed.

 2. About /etc/rc.local

      rc.local is also a script I use a lot. This script is executed after the system initialization level script runs, so it is safe to add scripts you want to execute after the system starts. The common situation is that you can add nfs mount/mount script inside. In addition, you can also add some script commands for debugging. For example, I have encountered this situation: the samba service always fails to run normally, and the inspection found that samba should be started and executed during the system startup process, that is to say, the samba daemon configuration guarantees this function. should be executed correctly. In such a similar situation, I usually don't bother to spend a lot of time to find out why, I just need to simply add this line to the /etc/rc.local script:

          /etc/init.d/samba start

     In this way, the problem of abnormal samba service is successfully solved.

 

 3. Summary

         Linux is flexible. Because of its flexibility, we can always find many different solutions to the same problem. The example of starting a system service is a good example. With the scripts in the /etc/init.d directory and /etc/rc.local, you can rest assured that your services are up and running perfectly.

 

http://blog.csdn.net/acs713/article/details/7322082

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326438508&siteId=291194637