Get To Know Linux: The /etc/init…
来源:互联网 发布:sql2005数据修复 编辑:程序博客网 时间:2024/05/17 00:08
If you use Linux you most likely have heard of theinit.d directory. But what exactly does thisdirectory do? It ultimately does one thing but it does that onething for your entire system, so init.d is veryimportant. The init.d directory contains a numberof start/stop scripts for various services on your system.Everything from acpid to x11-common is controlledfrom this directory. Of course it’s not exactly that simple.
If you look at the /etc directory you will finddirectories that are in the form rc#.d (Where # isa number reflects a specific initialization level – from 0 to 6).Within each of these directories is a number of other scripts thatcontrol processes. These scripts will either begin with a “K” or an“S”. All “K” scripts are run before “S” scripts. And depending uponwhere the scripts are located will determine when the scriptsinitiate. Between the directories the system services work togetherlike a well-oiled machine. But there are times when you need tostart or stop a process cleanly and without using the kill orkillall commands. That is where the /etc/init.ddirectory comes in handy.
Now if you are using a distribution like Fedora you might findthis directory in /etc/rc.d/init.d. Regardless oflocation, it serves the same purpose.
In order to control any of the scripts ininit.d manually you have to have root (or sudo)access. Each script will be run as a command and the structure ofthe command will look like:
/etc/initi.d/command OPTION
Where command is the actual command to run andOPTION can be one of the following:
- start
- stop
- reload
- restart
- force-reload
Most often you will use either start, stop, orrestart. So if you want to stop your network you can issuethe command:
/etc/init.d/networking stop
Or if you make a change to your network and need to restart it,you could do so with the following command:
/etc/init.d/networking restart
Some of the more common init scripts in this directory are:
- networking
- samba
- apache2
- ftpd
- sshd
- dovecot
- mysql
Of course there may be more often-used scripts in your directory– it depends upon what you have installed. The above list was takenfrom a Ubuntu Server 8.10 installation so a standard desktopinstallation would have a few less networking-type scripts.
But what about /etc/rc.local
There is a third option that I used to use quite a bit. Thisoption is the /etc/rc.local script. This file runsafter all other init level scripts have run, so it’s safe to putvarious commands that you want to have issued upon startup. Manytimes I will place mounting instructions for things like nfs inthis script. This is also a good place to place “troubleshooting”scripts in. For instance, once I had a machine that, for somereason, samba seemed to not want to start. Even afer checking tomake sure the Samba daemon was setup to initialize at boot up. Soinstead of spending all of my time up front with this I simplyplaced the line:
/etc/init.d/samba start
in the /etc/rc.local script and Samba workedlike a charm. Eventually I would come back and trouble shoot thisissue.
Final Thoughts
Linux is flexible. Linux is so flexible there is almost,inevitably, numerous ways to solve a single problem. Starting asystem service is one such issue. With the help of the/etc/init.d system (as well as/etc/rc.local) you can pretty much rest assuredyour service will start.
- Get To Know Linux: The /etc/init…
- failed to get the…
- How to get a good idea to perfor…
- Make sure to have the zlib libs …
- Make sure to have the zlib libs …
- How to got the Mac address from …
- How to get Time Separator in Jav…
- POJ 1050 To the Max
- To add a multiplexed copy of the…
- Lesson 73 The way to King Street…
- To represent Asia - the issue of…
- How to Set the Ulimit Values for…
- How to write/use DLL in Linux sy…
- Failed to get gro…
-  
- Failed to create the Java Virtua…
- How to recreate the index fnd_lo…
- How do I get default date and ti…
- 【awk】1-awk基础篇(又名UNIX.She…
- Python 简明教程
- DB2、ORACLE SQL写法的主要区别[转…
- DB2和 Oracle的并发控制(锁)比较
- How to Debug Perl
- Get To Know Linux: The /etc/init…
- 外部表External Table的简单应用[…
- DB2 错误查询命令
- Filtering of Hierarchical Data i…
- Filtering a Flex Tree using an A…
- 利用Perl Net::Ping检测网段IP是否…
- “小米”模式玩不转,国产机该怎么走
- 利用FOR LOOP代替DB2 UNF中不能使…
- DB2 数据库循环使用方法总结[转]