Foundation (ii): Linux system/etc/init.d directory and/etc/rc.local script

Source: Internet
Author: User

Original from http://www.ghacks.net/2009/04/04/get-to-know-linux-the-etcinitd-directory/

Translation from http://blog.csdn.net/acs713/article/details/7322082 Note: The author has a blog about the LIUNX system kernel knowledge of dry goods

First, about/ETC/INIT.D

If you have used a Linux system, you must have heard of the INIT.D directory. What the hell is this directory for? It's only done one thing in the end, but it's very important that it's done for the whole system. The INIT.D directory contains many system startup and stop scripts for various services. It controls all kinds of transactions from Acpid to X11-common. Of course, INIT.D is far from being so simple. (Translator Note: Acpid is a new power management standard for Linux operating system; X11 is also called the X Window System, and the X Window System (X11 or X) is a bitmap-display windowing system. It is a standard toolkit and protocol for creating graphical user interfaces on Unix and UNIX-like operating systems, as well as OpenVMS, and can be used in almost any modern operating system.

When you look at the/etc directory, you will find many directories that exist in RC#.D form (where # represents a specified initialization level, and the range is 0~6). Under these directories, there are many scripts that control the process. These scripts either start with "K" or start with "S". A script starting with K runs before a script that begins with S. Where these scripts are placed, will determine when these scripts start running. Between these directories, system services work together, just like a well-functioning machine. However, sometimes you want to be able to start or kill a process cleanly without using the kill or Killall command. This is where/etc/init.d can come in handy!

If you are using the Fedora system, you can find this directory:/ETC/RC.D/INIT.D. In fact, no matter where the INIT.D is placed, it plays the same role. In order to be able to use scripts under the INIT.D directory, you need to have root or sudo permissions. Each script will be run as a command with a structure that looks similar to the following:

/etc/init.d/command Options
Comand is a command that is actually running, and the options can be as follows:
Start
Stop
Reload
Restart
Force-reload

Most of the cases, you will use the Start,stop,restart option. For example, if you want to turn off the network, you can use the following form of command:
/etc/init.d/networking stop
Another example is that you change the network settings and need to restart the network. You can use the following command:
/etc/init.d/networking restart
Common init scripts under the INIT.D directory are:
Networking
Samba
Apache2
Ftpd
Sshd
Dovecot
Mysql
Of course, you may have more commonly used scripts, depending on what Linux operating system you have installed.

Second, about/etc/rc.local

Rc.local is also a script that I often use. The script is executed after the system initialization level script runs, so you can safely add scripts that you want to execute after the system starts. The common scenario is that you can add NFS mount/mount scripts inside again. In addition, you can also add some debugging script commands. For example, I've come across a situation where samba services always fail to work, and the check finds that Samba is executing during system startup, which means that the Samba daemon configuration ensures that this functionality should be performed correctly. In this similar situation, I usually do not bother to spend a lot of time to find out why, I just need to simply add this line in the/etc/rc.local script:
/etc/init.d/samba start
This successfully solves the problem of samba service anomalies.

Iii. Summary

Linux is flexible. Because of its flexibility, we can always find many different ways to solve the same problem. An example of starting a system service is a good corroboration. With the script in the/ETC/INIT.D directory, plus the/etc/rc.local, you can be assured that your service will be up and running perfectly.

Foundation (ii): Linux system/etc/init.d directory and/etc/rc.local script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.