|
|
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> |
… | |
… | |
31 | services you need in order to have a successfully booted system. |
34 | services you need in order to have a successfully booted system. |
32 | </p> |
35 | </p> |
33 | |
36 | |
34 | <p> |
37 | <p> |
35 | Finally, when all scripts are executed, <c>init</c> activates the terminals |
38 | Finally, 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. |
38 | This process will then make sure you are able to log on through these terminals |
41 | This process will then make sure you are able to log on through these terminals |
39 | by running <c>login</c>. |
42 | by running <c>login</c>. |
40 | </p> |
43 | </p> |
41 | |
44 | |
… | |
… | |
80 | configuration file that specifies what actions need to be taken. This |
83 | configuration file that specifies what actions need to be taken. This |
81 | configuration file is <path>/etc/inittab</path>. |
84 | configuration file is <path>/etc/inittab</path>. |
82 | </p> |
85 | </p> |
83 | |
86 | |
84 | <p> |
87 | <p> |
85 | If you remember the boot sequence we have just explained to you, you will |
88 | If you remember the boot sequence we have just described, you will remember |
86 | remember that <c>init</c>'s first action is to mount all filesystems. This is |
89 | that <c>init</c>'s first action is to mount all filesystems. This is defined in |
87 | defined in the following line from <path>/etc/inittab</path>: |
90 | the 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"> |
91 | si::sysinit:/sbin/rc sysinit |
94 | si::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> |
273 | Finally, you can ask what dependencies the service requires but that are |
276 | Finally, you can ask what dependencies the service requires that are missing: |
274 | missing: |
|
|
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> |
291 | Gentoo's init system uses a dependency-tree to decide what service needs to be |
293 | Gentoo's init system uses a dependency-tree to decide what service needs to be |
292 | started first. As this is a tedious task that we wouldn't want our users to do |
294 | started first. As this is a tedious task that we wouldn't want our users to |
293 | manually, we have created tools that ease the administration of the runlevels |
295 | have to do manually, we have created tools that ease the administration of the |
294 | and init scripts. |
296 | runlevels and init scripts. |
295 | </p> |
297 | </p> |
296 | |
298 | |
297 | <p> |
299 | <p> |
298 | With <c>rc-update</c> you can add and remove init scripts to a runlevel. The |
300 | With <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> |
344 | Init scripts can be quite complex. It is therefore not really interesting to |
346 | Init scripts can be quite complex. It is therefore not really desirable to |
345 | have the users directly edit the init script, as it would make it more |
347 | have the users edit the init script directly, as it would make it more |
346 | error-prone. It is however important to be able to configure such a service. For |
348 | error-prone. It is however important to be able to configure such a service. For |
347 | instance, you might want to give more options to the service itself. |
349 | instance, you might want to give more options to the service itself. |
348 | </p> |
350 | </p> |
349 | |
351 | |
350 | <p> |
352 | <p> |
351 | A second reason to have this configuration outside the init script is to be able |
353 | A second reason to have this configuration outside the init script is to be |
352 | to update the init scripts without being afraid that your configuration changes |
354 | able to update the init scripts without the fear that your configuration |
353 | are undone. |
355 | changes 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> |
390 | No. Writing an init script is usually not necessary as Gentoo provides |
392 | No, writing an init script is usually not necessary as Gentoo provides |
391 | ready-to-use init scripts for all provided services. However, you might have |
393 | ready-to-use init scripts for all provided services. However, you might have |
392 | installed a service without using Portage, in which case you will most likely |
394 | installed a service without using Portage, in which case you will most likely |
393 | have to create an init script. |
395 | have to create an init script. |
394 | </p> |
396 | </p> |
395 | |
397 | |
… | |
… | |
499 | |
501 | |
500 | <p> |
502 | <p> |
501 | In some cases you might not require a service, but want your service to be |
503 | In some cases you might not require a service, but want your service to be |
502 | started <c>before</c> (or <c>after</c>) another service <e>if</e> it is |
504 | started <c>before</c> (or <c>after</c>) another service <e>if</e> it is |
503 | available on the system (note the conditional - this is no dependency anymore) |
505 | available 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 |
505 | same runlevel are involved). You can provide this information using the |
507 | same 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> |
522 | You can also use the "*" glob to catch all services in the same runlevel, |
524 | You can also use the "*" glob to catch all services in the same runlevel, |
523 | although this isn't adviseable. |
525 | although 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"> |
527 | depend() { |
529 | depend() { |
528 | before * |
530 | before * |
… | |
… | |
536 | <body> |
538 | <body> |
537 | |
539 | |
538 | <p> |
540 | <p> |
539 | Next to the <c>depend()</c> functionality, you also need to define the |
541 | Next 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 |
541 | initialize your service. It is adviseable to use the <c>ebegin</c> and |
543 | initialize 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"> |
546 | start() { |
548 | start() { |
… | |
… | |
562 | </pre> |
564 | </pre> |
563 | |
565 | |
564 | <p> |
566 | <p> |
565 | Other functions you can define are: <c>stop()</c> and <c>restart()</c>. You are |
567 | Other functions you can define are: <c>stop()</c> and <c>restart()</c>. You are |
566 | not obliged to define these functions! Our init system is intelligent enough to |
568 | not obliged to define these functions! Our init system is intelligent enough to |
567 | fill these functions in herself if you use <c>start-stop-daemon</c>. |
569 | fill 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> |
|
|
629 | Many laptop users know the situation: at home you need to start <c>net.eth0</c> |
|
|
630 | while you don't want to start <c>net.eth0</c> while you're on the road (as |
|
|
631 | there is no network available). With Gentoo you can alter the runlevel behaviour |
|
|
632 | to your own will. |
|
|
633 | </p> |
|
|
634 | |
|
|
635 | <p> |
|
|
636 | For instance you can create a second "default" runlevel which you can boot that |
|
|
637 | has other init scripts assigned to it. You can then select at boottime what |
|
|
638 | default runlevel you want to use. |
|
|
639 | </p> |
|
|
640 | |
|
|
641 | </body> |
|
|
642 | </subsection> |
|
|
643 | <subsection> |
|
|
644 | <title>Using SOFTLEVEL</title> |
|
|
645 | <body> |
|
|
646 | |
|
|
647 | <p> |
|
|
648 | First of all, create the runlevel directory for your second "default" runlevel. |
|
|
649 | As 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> |
|
|
657 | Add the necessary init scripts to the newly created runlevels. For instance, if |
|
|
658 | you want to have an exact copy of your current <c>default</c> runlevel but |
|
|
659 | without <c>net.eth0</c>: |
|
|
660 | </p> |
|
|
661 | |
|
|
662 | <pre caption="Adding the necessary init scripts"> |
|
|
663 | # <i>ls /etc/runlevels/default</i> |
|
|
664 | acpid 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> |
|
|
673 | Now 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"> |
|
|
678 | title 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> |
|
|
684 | Voila, you're all set now. If you boot your system and select the newly added |
|
|
685 | entry 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> |
|
|
696 | Using <c>bootlevel</c> is completely analogous to <c>softlevel</c>. The only |
|
|
697 | difference 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> |