⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 470-472.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Using Linux:Managing Daemons</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0789716232//-->

<!--TITLE=Using Linux//-->

<!--AUTHOR=William Ball//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Que//-->

<!--CHAPTER=28//-->

<!--PAGES=470-472//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="467-470.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="472-474.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Editing and Creating Run Levels</FONT></H3>

<P><TT>init</TT> reads its configuration from the file <TT>/etc/inittab</TT>, which contains a number of pieces of information for <TT>init</TT>. It outlines what processes <TT>init</TT> should keep running (and restart if necessary) at each run level. Your logon prompts (called <TT>getty</TT> processes) are started and restarted by <TT>init</TT>. <TT>init</TT> reads the names of scripts to run when the system changes run level. This is probably the most confusing point about <TT>init</TT> and how the system starts: The scripts can (and usually do) also start processes. These are very different from the processes directly controlled by <TT>init</TT>, because they are not absolutely vital to the operation of the system (<I>vital</I> being defined here as being necessary to prevent the system from being completely inaccessible, as in not being able to log on at the console). The script that <TT>init</TT> calls, as well as exactly how it operates, is very much distribution dependent.</P>

<P>Red Hat Linux&#146;s set of <TT>init</TT> scripts (so named because they are called by <TT>init</TT>, not because they are the initialization scripts) are kept in the <TT>/etc/rc.d</TT> and <TT>/etc/rc.d/init.d</TT> directories. The scripts in <TT>/etc/rc.d</TT> are there primarily for backward compatibility with other Linux distributions. The most noteworthy file is called <TT>rc.local</TT>, which is a shell script in which modifications specific to the particular Linux system would go on other systems. The standard installation&#146;s <TT>rc.local</TT> script sets the <TT>/etc/issue</TT> file only to the version of Red Hat Linux that&#146;s being used.</P>

<P>The more interesting directory is called the <TT>init.d</TT> directory. This directory holds a number of scripts that control the non-vital system services. If none of the services in this directory start, your system won&#146;t do much, but hopefully <TT>init</TT> will have managed to start a logon prompt.</P>

<P>These directories are pretty vital to your system. In fact, I recommend that the entire <TT>/etc/</TT> directory tree appear in every backup you do. Thank me later for reminding you.</P>



<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">

<TR><TD><FONT SIZE="+1"><B>Where should I start?</B></FONT>

<BR>Most system services are not absolutely vital. If you need <TT>init</TT> to baby-sit the process to make sure it&#146;s always running, it would be worthwhile for the daemon to be started from the <TT>inittab</TT> file. Thankfully, the vast majority of daemon programs do not require this sort of attention, and for ease of maintenance are best started from a script in <TT>/etc/rc.d/init.d</TT> and managed through the <TT>tksysv</TT> tool.

<P>However, if the daemon is started from the <TT>inittab</TT> file and <TT>init</TT> needs to <I>respawn</I> (the term used for restarting a daemon process) the program too often, it disables the program for a while. You&#146;ll see a message like the following in the kernel message file (/var/log/messages):</P>

<!-- CODE SNIP //-->

<PRE>

init: process

respawning too fast.

disabled for 5 minutes

</PRE>

<!-- END CODE SNIP //-->

</TABLE>



<H3><A NAME="Heading3"></A><FONT COLOR="#000077">Editing <I>inittab</I>

</FONT></H3>

<P>Adding a process to the <TT>inittab</TT> file is pretty easy. Like many of the system files in Linux, this file is delimited by the colon (<TT>:</TT>) character. Each line has the following format:</P>

<!-- CODE SNIP //-->

<PRE>

[ID]:[Runlevels to be running at]:[Action]:[program name and

arguments]

</PRE>

<!-- END CODE SNIP //-->

<P>Table 28.2 describes each field in the preceding code.

</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>TABLE 28.2</B> <I>Inittab</I> file layout

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="30%" ALIGN="LEFT">Field Name

<TH WIDTH="70%" ALIGN="LEFT">Description

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD VALIGN="TOP"><TT>ID</TT>

<TD>This is a short description of the line or event. For example, pressing Crtl&#43;Alt&#43;Delete causes <TT>init</TT> to look for the <TT>crtl-alt-del</TT> event in the inittab file. There are events for power failure as well, and along with the proper service process (also called daemon) this mechanism can provide for UPS monitoring (look up <TT>powerd</TT> in the <TT>man</TT> pages if you want to see how to do  this). Services that are attached to terminal devices (virtual terminals or serial ports) use the name of the port after the letters <TT>tty</TT> as their ID (for example, <TT>ttyS1</TT> becomes <TT>S1</TT>), since the <TT>tty</TT> prefix is implied.

<TR>

<TD VALIGN="TOP"><TT>Runlevels</TT>

<TD>This section contains the numbers for the run level on which the command should be executed (for example, 345).

<TR>

<TD VALIGN="TOP"><TT>Action</TT>

<TD>This tells <TT>init</TT> what action to take. A whole list of actions is documented in the inittab(5) man page, but the most commonly used actions are <TT>wait</TT>, <TT>respawn</TT>, and <TT>boot</TT>.

<TR>

<TD VALIGN="TOP"><TT>Program name and arguments</TT>

<TD>The last part of the <TT>inittab</TT> line contains the name of the program and the command-line arguments.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>



<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">

<TR><TD><FONT SIZE="+1"><B>Remember the 3 B&#146;s of system administration: back up, back up, and back up again</B></FONT>

<BR>Make sure you have a backup copy of the <TT>inittab</TT> file before you start editing it.</TABLE>



<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="467-470.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="472-474.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -