/[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.34 Revision 1.35
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/2.5 --> 5<!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
6 6
7<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml,v 1.34 2011/08/14 16:12:13 swift Exp $ --> 7<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml,v 1.35 2011/08/17 07:57:23 swift Exp $ -->
8 8
9<sections> 9<sections>
10 10
11<abstract> 11<abstract>
12Gentoo uses a special initscript format which, amongst other features, allows 12Gentoo uses a special initscript format which, amongst other features, allows
13dependency-driven decisions and virtual initscripts. This chapter explains all 13dependency-driven decisions and virtual initscripts. This chapter explains all
14these aspects and explains how to deal with these scripts. 14these aspects and explains how to deal with these scripts.
15</abstract> 15</abstract>
16 16
17<version>3</version> 17<version>4</version>
18<date>2011-08-12</date> 18<date>2011-08-17</date>
19 19
20<section> 20<section>
21<title>Runlevels</title> 21<title>Runlevels</title>
22<subsection> 22<subsection>
23<title>Booting your System</title> 23<title>Booting your System</title>
452<subsection> 452<subsection>
453<title>Dependencies</title> 453<title>Dependencies</title>
454<body> 454<body>
455 455
456<p> 456<p>
457There are two dependencies you can define: <c>use</c> and <c>need</c>. As we 457There are two dependency-alike settings you can define that influence the
458have mentioned before, the <c>need</c> dependency is more strict than the 458start-up or sequencing of init scripts: <c>use</c> and <c>need</c>. Next to
459<c>use</c> dependency. Following this dependency type you enter the service 459these two, there are also two order-influencing methods called <c>before</c> and
460you depend on, or the <e>virtual</e> dependency. 460<c>after</c>. These last two are no dependencies per se - they do not make the
461original init script fail if the selected one isn't scheduled to start (or fails
462to start).
463</p>
464
465<ul>
466 <li>
467 The <c>use</c> settings informs the init system that this script <e>uses</e>
468 functionality offered by the selected script, but does not directly depend
469 on it. A good example would be <c>use logger</c> or <c>use dns</c>. If those
470 services are available, they will be put in good use, but if you do not have
471 a logger or DNS server the services will still work. If the services exist,
472 then they are started before the script that <c>use</c>'s them.
473 </li>
474 <li>
475 The <c>need</c> setting is a hard dependency. It means that the script that
476 is <c>need</c>'ing another script will not start before the other script is
477 launched successfully. Also, if that other script is restarted, then this
478 one will be restarted as well.
479 </li>
480 <li>
481 When using <c>before</c>, then the given script is launched before the
482 selected one <e>if</e> the selected one is part of the init level. So an
483 init script <path>xdm</path> that defines <c>before alsasound</c> will start
484 before the <path>alsasound</path> script, but only if <path>alsasound</path>
485 is scheduled to start as well in the same init level. If
486 <path>alsasound</path> is not scheduled to start too, then this particular
487 setting has no effect and <path>xdm</path> will be started when the init
488 system deems it most appropriate.
489 </li>
490 <li>
491 Similarly, <c>after</c> informs the init system that the given script should
492 be launched after the selected one <e>if</e> the selected one is part of the
493 init level. If not, then the setting has no effect and the script will be
494 launched by the init system when it deems it most appropriate.
495 </li>
496</ul>
497
498<p>
499It should be clear from the above that <c>need</c> is the only "true" dependency
500setting as it affects if the script will be started or not. All the others are
501merely pointers towards the init system to clarify in which order scripts can be
502(or should be) launched.
503</p>
504
505<p>
506Now, if you look at many of Gentoo's available init scripts, you will notice
507that some have dependencies on things that are no init scripts. These "things"
508we call <e>virtuals</e>.
461</p> 509</p>
462 510
463<p> 511<p>
464A <e>virtual</e> dependency is a dependency that a service provides, but that is 512A <e>virtual</e> dependency is a dependency that a service provides, but that is
465not provided solely by that service. Your init script can depend on a system 513not provided solely by that service. Your init script can depend on a system
509<subsection> 557<subsection>
510<title>Controlling the Order</title> 558<title>Controlling the Order</title>
511<body> 559<body>
512 560
513<p> 561<p>
514In some cases you might not require a service, but want your service to be 562As we described in the previous section, you can tell the init system what order
515started <c>before</c> (or <c>after</c>) another service <e>if</e> it is 563it should use for starting (or stopping) scripts. This ordering is handled both
516available on the system (note the conditional - this is no dependency anymore) 564through the dependency settings <c>use</c> and <c>need</c>, but also through the
517<e>and</e> run in the same runlevel (note the conditional - only services in the 565order settings <c>before</c> and <c>after</c>. As we have described these
518same runlevel are involved). You can provide this information using the 566earlier already, let's take a look at the Portmap service as an example of such
519<c>before</c> or <c>after</c> settings. 567init script.
520</p>
521
522<p>
523As an example we view the settings of the Portmap service:
524</p> 568</p>
525 569
526<pre caption="The depend() function in the Portmap service"> 570<pre caption="The depend() function in the Portmap service">
527depend() { 571depend() {
528 need net 572 need net

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.35

  ViewVC Help
Powered by ViewVC 1.1.20