/[gentoo]/xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml
Gentoo

Diff of /xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.13 Revision 1.20
2<!DOCTYPE sections SYSTEM "/dtd/book.dtd"> 2<!DOCTYPE sections SYSTEM "/dtd/book.dtd">
3 3
4<!-- The content of this document is licensed under the CC-BY-SA license --> 4<!-- The content of this document is licensed under the CC-BY-SA license -->
5<!-- See http://creativecommons.org/licenses/by-sa/1.0 --> 5<!-- See http://creativecommons.org/licenses/by-sa/1.0 -->
6 6
7<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml,v 1.13 2004/05/06 22:45:58 neysx Exp $ --> 7<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml,v 1.20 2004/11/20 22:23:30 neysx Exp $ -->
8 8
9<sections> 9<sections>
10
11<version>1.17</version>
12<date>2004-10-23</date>
13
10<section> 14<section>
11<title>Runlevels</title> 15<title>Runlevels</title>
12<subsection> 16<subsection>
13<title>Booting your System</title> 17<title>Booting your System</title>
14<body> 18<body>
34services you need in order to have a successfully booted system. 38services you need in order to have a successfully booted system.
35</p> 39</p>
36 40
37<p> 41<p>
38Finally, when all scripts are executed, <c>init</c> activates the terminals 42Finally, when all scripts are executed, <c>init</c> activates the terminals
39(in most cases just the virtual consoles which are hidden beneith <c>Alt-F1</c>, 43(in most cases just the virtual consoles which are hidden beneath <c>Alt-F1</c>,
40<c>Alt-F2</c>, etc.) attaching a special process called <c>agetty</c> to it. 44<c>Alt-F2</c>, etc.) attaching a special process called <c>agetty</c> to it.
41This process will then make sure you are able to log on through these terminals 45This process will then make sure you are able to log on through these terminals
42by running <c>login</c>. 46by running <c>login</c>.
43</p> 47</p>
44 48
83configuration file that specifies what actions need to be taken. This 87configuration file that specifies what actions need to be taken. This
84configuration file is <path>/etc/inittab</path>. 88configuration file is <path>/etc/inittab</path>.
85</p> 89</p>
86 90
87<p> 91<p>
88If you remember the boot sequence we have just explained to you, you will 92If you remember the boot sequence we have just described, you will remember
89remember that <c>init</c>'s first action is to mount all filesystems. This is 93that <c>init</c>'s first action is to mount all filesystems. This is defined in
90defined in the following line from <path>/etc/inittab</path>: 94the following line from <path>/etc/inittab</path>:
91</p> 95</p>
92 96
93<pre caption="The system initialisation line in /etc/inittab"> 97<pre caption="The system initialisation line in /etc/inittab">
94si::sysinit:/sbin/rc sysinit 98si::sysinit:/sbin/rc sysinit
95</pre> 99</pre>
271<pre caption="Requesting a list of all services that require Postfix"> 275<pre caption="Requesting a list of all services that require Postfix">
272# <i>/etc/init.d/postfix needsme</i> 276# <i>/etc/init.d/postfix needsme</i>
273</pre> 277</pre>
274 278
275<p> 279<p>
276Finally, you can ask what dependencies the service requires but that are 280Finally, you can ask what dependencies the service requires that are missing:
277missing:
278</p> 281</p>
279 282
280<pre caption="Requesting a list of missing dependencies for Postfix"> 283<pre caption="Requesting a list of missing dependencies for Postfix">
281# <i>/etc/init.d/postfix broken</i> 284# <i>/etc/init.d/postfix broken</i>
282</pre> 285</pre>
290<title>What is rc-update?</title> 293<title>What is rc-update?</title>
291<body> 294<body>
292 295
293<p> 296<p>
294Gentoo's init system uses a dependency-tree to decide what service needs to be 297Gentoo's init system uses a dependency-tree to decide what service needs to be
295started first. As this is a tedious task that we wouldn't want our users to do 298started first. As this is a tedious task that we wouldn't want our users to
296manually, we have created tools that ease the administration of the runlevels 299have to do manually, we have created tools that ease the administration of the
297and init scripts. 300runlevels and init scripts.
298</p> 301</p>
299 302
300<p> 303<p>
301With <c>rc-update</c> you can add and remove init scripts to a runlevel. The 304With <c>rc-update</c> you can add and remove init scripts to a runlevel. The
302<c>rc-update</c> tool will then automatically ask the <c>depscan.sh</c> script 305<c>rc-update</c> tool will then automatically ask the <c>depscan.sh</c> script
342<subsection> 345<subsection>
343<title>Why the Need for Extra Configuration?</title> 346<title>Why the Need for Extra Configuration?</title>
344<body> 347<body>
345 348
346<p> 349<p>
347Init scripts can be quite complex. It is therefore not really interesting to 350Init scripts can be quite complex. It is therefore not really desirable to
348have the users directly edit the init script, as it would make it more 351have the users edit the init script directly, as it would make it more
349error-prone. It is however important to be able to configure such a service. For 352error-prone. It is however important to be able to configure such a service. For
350instance, you might want to give more options to the service itself. 353instance, you might want to give more options to the service itself.
351</p> 354</p>
352 355
353<p> 356<p>
354A second reason to have this configuration outside the init script is to be able 357A second reason to have this configuration outside the init script is to be
355to update the init scripts without being afraid that your configuration changes 358able to update the init scripts without the fear that your configuration
356are undone. 359changes will be undone.
357</p> 360</p>
358 361
359</body> 362</body>
360</subsection> 363</subsection>
361<subsection> 364<subsection>
388<subsection> 391<subsection>
389<title>Do I Have To?</title> 392<title>Do I Have To?</title>
390<body> 393<body>
391 394
392<p> 395<p>
393No. Writing an init script is usually not necessary as Gentoo provides 396No, writing an init script is usually not necessary as Gentoo provides
394ready-to-use init scripts for all provided services. However, you might have 397ready-to-use init scripts for all provided services. However, you might have
395installed a service without using Portage, in which case you will most likely 398installed a service without using Portage, in which case you will most likely
396have to create an init script. 399have to create an init script.
397</p> 400</p>
398 401
502 505
503<p> 506<p>
504In some cases you might not require a service, but want your service to be 507In some cases you might not require a service, but want your service to be
505started <c>before</c> (or <c>after</c>) another service <e>if</e> it is 508started <c>before</c> (or <c>after</c>) another service <e>if</e> it is
506available on the system (note the conditional - this is no dependency anymore) 509available on the system (note the conditional - this is no dependency anymore)
507<e>and</e> ran in the same runlevel (note the conditional - only services in the 510<e>and</e> run in the same runlevel (note the conditional - only services in the
508same runlevel are involved). You can provide this information using the 511same runlevel are involved). You can provide this information using the
509<c>before</c> or <c>after</c> settings. 512<c>before</c> or <c>after</c> settings.
510</p> 513</p>
511 514
512<p> 515<p>
521} 524}
522</pre> 525</pre>
523 526
524<p> 527<p>
525You can also use the "*" glob to catch all services in the same runlevel, 528You can also use the "*" glob to catch all services in the same runlevel,
526although this isn't adviseable. 529although this isn't advisable.
527</p> 530</p>
528 531
529<pre caption="Running an init script as first script in the runlevel"> 532<pre caption="Running an init script as first script in the runlevel">
530depend() { 533depend() {
531 before * 534 before *
539<body> 542<body>
540 543
541<p> 544<p>
542Next to the <c>depend()</c> functionality, you also need to define the 545Next to the <c>depend()</c> functionality, you also need to define the
543<c>start()</c> function. This one contains all the commands necessary to 546<c>start()</c> function. This one contains all the commands necessary to
544initialize your service. It is adviseable to use the <c>ebegin</c> and 547initialize your service. It is advisable to use the <c>ebegin</c> and
545<c>eend</c> functions to inform the user about what is happening: 548<c>eend</c> functions to inform the user about what is happening:
546</p> 549</p>
547 550
548<pre caption="Example start() function"> 551<pre caption="Example start() function">
549start() { 552start() {
634</p> 637</p>
635 638
636<p> 639<p>
637For instance you can create a second "default" runlevel which you can boot that 640For instance you can create a second "default" runlevel which you can boot that
638has other init scripts assigned to it. You can then select at boottime what 641has other init scripts assigned to it. You can then select at boottime what
639defalt runlevel you want to use. 642default runlevel you want to use.
640</p> 643</p>
641 644
642</body> 645</body>
643</subsection> 646</subsection>
644<subsection> 647<subsection>

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.20