/[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.8 Revision 1.17
1<?xml version='1.0' encoding='UTF-8'?>
2<!DOCTYPE sections SYSTEM "/dtd/book.dtd">
3
1<!-- 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 -->
2<!-- See http://creativecommons.org/licenses/by-sa/1.0 --> 5<!-- See http://creativecommons.org/licenses/by-sa/1.0 -->
3 6
4<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml,v 1.8 2004/01/06 09:57:49 swift Exp $ --> 7<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml,v 1.17 2004/10/23 11:02:06 swift Exp $ -->
5 8
6<sections> 9<sections>
7<section> 10<section>
8<title>Runlevels</title> 11<title>Runlevels</title>
9<subsection> 12<subsection>
31services you need in order to have a successfully booted system. 34services you need in order to have a successfully booted system.
32</p> 35</p>
33 36
34<p> 37<p>
35Finally, when all scripts are executed, <c>init</c> activates the terminals 38Finally, when all scripts are executed, <c>init</c> activates the terminals
36(in most cases just the virtual consoles which are hidden beneith <c>Alt-F1</c>, 39(in most cases just the virtual consoles which are hidden beneath <c>Alt-F1</c>,
37<c>Alt-F2</c>, etc.) attaching a special process called <c>agetty</c> to it. 40<c>Alt-F2</c>, etc.) attaching a special process called <c>agetty</c> to it.
38This process will then make sure you are able to log on through these terminals 41This process will then make sure you are able to log on through these terminals
39by running <c>login</c>. 42by running <c>login</c>.
40</p> 43</p>
41 44
80configuration file that specifies what actions need to be taken. This 83configuration file that specifies what actions need to be taken. This
81configuration file is <path>/etc/inittab</path>. 84configuration file is <path>/etc/inittab</path>.
82</p> 85</p>
83 86
84<p> 87<p>
85If you remember the boot sequence we have just explained to you, you will 88If you remember the boot sequence we have just described, you will remember
86remember that <c>init</c>'s first action is to mount all filesystems. This is 89that <c>init</c>'s first action is to mount all filesystems. This is defined in
87defined in the following line from <path>/etc/inittab</path>: 90the following line from <path>/etc/inittab</path>:
88</p> 91</p>
89 92
90<pre caption="The system initialisation line in /etc/inittab"> 93<pre caption="The system initialisation line in /etc/inittab">
91si::sysinit:/sbin/rc sysinit 94si::sysinit:/sbin/rc sysinit
92</pre> 95</pre>
268<pre caption="Requesting a list of all services that require Postfix"> 271<pre caption="Requesting a list of all services that require Postfix">
269# <i>/etc/init.d/postfix needsme</i> 272# <i>/etc/init.d/postfix needsme</i>
270</pre> 273</pre>
271 274
272<p> 275<p>
273Finally, you can ask what dependencies the service requires but that are 276Finally, you can ask what dependencies the service requires that are missing:
274missing:
275</p> 277</p>
276 278
277<pre caption="Requesting a list of missing dependencies for Postfix"> 279<pre caption="Requesting a list of missing dependencies for Postfix">
278# <i>/etc/init.d/postfix broken</i> 280# <i>/etc/init.d/postfix broken</i>
279</pre> 281</pre>
287<title>What is rc-update?</title> 289<title>What is rc-update?</title>
288<body> 290<body>
289 291
290<p> 292<p>
291Gentoo's init system uses a dependency-tree to decide what service needs to be 293Gentoo's init system uses a dependency-tree to decide what service needs to be
292started first. As this is a tedious task that we wouldn't want our users to do 294started first. As this is a tedious task that we wouldn't want our users to
293manually, we have created tools that ease the administration of the runlevels 295have to do manually, we have created tools that ease the administration of the
294and init scripts. 296runlevels and init scripts.
295</p> 297</p>
296 298
297<p> 299<p>
298With <c>rc-update</c> you can add and remove init scripts to a runlevel. The 300With <c>rc-update</c> you can add and remove init scripts to a runlevel. The
299<c>rc-update</c> tool will then automatically ask the <c>depscan.sh</c> script 301<c>rc-update</c> tool will then automatically ask the <c>depscan.sh</c> script
339<subsection> 341<subsection>
340<title>Why the Need for Extra Configuration?</title> 342<title>Why the Need for Extra Configuration?</title>
341<body> 343<body>
342 344
343<p> 345<p>
344Init scripts can be quite complex. It is therefore not really interesting to 346Init scripts can be quite complex. It is therefore not really desirable to
345have the users directly edit the init script, as it would make it more 347have the users edit the init script directly, as it would make it more
346error-prone. It is however important to be able to configure such a service. For 348error-prone. It is however important to be able to configure such a service. For
347instance, you might want to give more options to the service itself. 349instance, you might want to give more options to the service itself.
348</p> 350</p>
349 351
350<p> 352<p>
351A second reason to have this configuration outside the init script is to be able 353A second reason to have this configuration outside the init script is to be
352to update the init scripts without being afraid that your configuration changes 354able to update the init scripts without the fear that your configuration
353are undone. 355changes will be undone.
354</p> 356</p>
355 357
356</body> 358</body>
357</subsection> 359</subsection>
358<subsection> 360<subsection>
385<subsection> 387<subsection>
386<title>Do I Have To?</title> 388<title>Do I Have To?</title>
387<body> 389<body>
388 390
389<p> 391<p>
390No. Writing an init script is usually not necessary as Gentoo provides 392No, writing an init script is usually not necessary as Gentoo provides
391ready-to-use init scripts for all provided services. However, you might have 393ready-to-use init scripts for all provided services. However, you might have
392installed a service without using Portage, in which case you will most likely 394installed a service without using Portage, in which case you will most likely
393have to create an init script. 395have to create an init script.
394</p> 396</p>
395 397
499 501
500<p> 502<p>
501In some cases you might not require a service, but want your service to be 503In some cases you might not require a service, but want your service to be
502started <c>before</c> (or <c>after</c>) another service <e>if</e> it is 504started <c>before</c> (or <c>after</c>) another service <e>if</e> it is
503available on the system (note the conditional - this is no dependency anymore) 505available on the system (note the conditional - this is no dependency anymore)
504<e>and</e> ran in the same runlevel (note the conditional - only services in the 506<e>and</e> run in the same runlevel (note the conditional - only services in the
505same runlevel are involved). You can provide this information using the 507same runlevel are involved). You can provide this information using the
506<c>before</c> or <c>after</c> settings. 508<c>before</c> or <c>after</c> settings.
507</p> 509</p>
508 510
509<p> 511<p>
518} 520}
519</pre> 521</pre>
520 522
521<p> 523<p>
522You can also use the "*" glob to catch all services in the same runlevel, 524You can also use the "*" glob to catch all services in the same runlevel,
523although this isn't adviseable. 525although this isn't advisable.
524</p> 526</p>
525 527
526<pre caption="Running an init script as first script in the runlevel"> 528<pre caption="Running an init script as first script in the runlevel">
527depend() { 529depend() {
528 before * 530 before *
536<body> 538<body>
537 539
538<p> 540<p>
539Next to the <c>depend()</c> functionality, you also need to define the 541Next to the <c>depend()</c> functionality, you also need to define the
540<c>start()</c> function. This one contains all the commands necessary to 542<c>start()</c> function. This one contains all the commands necessary to
541initialize your service. It is adviseable to use the <c>ebegin</c> and 543initialize your service. It is advisable to use the <c>ebegin</c> and
542<c>eend</c> functions to inform the user about what is happening: 544<c>eend</c> functions to inform the user about what is happening:
543</p> 545</p>
544 546
545<pre caption="Example start() function"> 547<pre caption="Example start() function">
546start() { 548start() {
562</pre> 564</pre>
563 565
564<p> 566<p>
565Other functions you can define are: <c>stop()</c> and <c>restart()</c>. You are 567Other functions you can define are: <c>stop()</c> and <c>restart()</c>. You are
566not obliged to define these functions! Our init system is intelligent enough to 568not obliged to define these functions! Our init system is intelligent enough to
567fill these functions in herself if you use <c>start-stop-daemon</c>. 569fill these functions by itself if you use <c>start-stop-daemon</c>.
568</p> 570</p>
569 571
570</body> 572</body>
571</subsection> 573</subsection>
572<subsection> 574<subsection>
615</p> 617</p>
616 618
617</body> 619</body>
618</subsection> 620</subsection>
619</section> 621</section>
622<section>
623<title>Changing the Runlevel Behaviour</title>
624<subsection>
625<title>Who might benefit from this?</title>
626<body>
627
628<p>
629Many laptop users know the situation: at home you need to start <c>net.eth0</c>
630while you don't want to start <c>net.eth0</c> while you're on the road (as
631there is no network available). With Gentoo you can alter the runlevel behaviour
632to your own will.
633</p>
634
635<p>
636For instance you can create a second "default" runlevel which you can boot that
637has other init scripts assigned to it. You can then select at boottime what
638default runlevel you want to use.
639</p>
640
641</body>
642</subsection>
643<subsection>
644<title>Using SOFTLEVEL</title>
645<body>
646
647<p>
648First of all, create the runlevel directory for your second "default" runlevel.
649As an example we create the <path>offline</path> runlevel:
650</p>
651
652<pre caption="Creating a runlevel directory">
653# <i>mkdir /etc/runlevels/offline</i>
654</pre>
655
656<p>
657Add the necessary init scripts to the newly created runlevels. For instance, if
658you want to have an exact copy of your current <c>default</c> runlevel but
659without <c>net.eth0</c>:
660</p>
661
662<pre caption="Adding the necessary init scripts">
663# <i>ls /etc/runlevels/default</i>
664acpid domainname local net.eth0 netmount postfix syslog-ng vixie-cron
665# <i>rc-update add acpid offline</i>
666# <i>rc-update add domainname offline</i>
667# <i>rc-update add local offline</i>
668# <i>rc-update add syslog-ng offline</i>
669# <i>rc-update add vixie-cron offline</i>
670</pre>
671
672<p>
673Now edit your bootloader configuration and add a new entry for the
674<c>offline</c> runlevel. For instance, in <path>/boot/grub/grub.conf</path>:
675</p>
676
677<pre caption="Adding an entry for the offline runlevel">
678title Gentoo Linux Offline Usage
679 root (hd0,0)
680 kernel (hd0,0)/kernel-2.4.25 root=/dev/hda3 <i>softlevel=offline</i>
681</pre>
682
683<p>
684Voila, you're all set now. If you boot your system and select the newly added
685entry at boot, the <c>offline</c> runlevel will be used instead of the
686<c>default</c> one.
687</p>
688
689</body>
690</subsection>
691<subsection>
692<title>Using BOOTLEVEL</title>
693<body>
694
695<p>
696Using <c>bootlevel</c> is completely analogous to <c>softlevel</c>. The only
697difference here is that you define a second "boot" runlevel instead of a second
698"default" runlevel.
699</p>
700
701</body>
702</subsection>
703</section>
620</sections> 704</sections>

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.17

  ViewVC Help
Powered by ViewVC 1.1.20