/[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.32 Revision 1.33
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.32 2011/03/02 08:09:48 nightmorph Exp $ --> 7<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml,v 1.33 2011/08/12 19:34:56 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>2</version> 17<version>3</version>
18<date>2011-03-02</date> 18<date>2011-08-12</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>
437 <comment>(Commands necessary to start the service)</comment> 437 <comment>(Commands necessary to start the service)</comment>
438} 438}
439 439
440stop() { 440stop() {
441 <comment>(Commands necessary to stop the service)</comment> 441 <comment>(Commands necessary to stop the service)</comment>
442}
443
444restart() {
445 <comment>(Commands necessary to restart the service)</comment>
446} 442}
447</pre> 443</pre>
448 444
449<p> 445<p>
450Any init script <e>requires</e> the <c>start()</c> function to be defined. All 446Any init script <e>requires</e> the <c>start()</c> function to be defined. All
572<c>eend</c> functions to inform the user about what is happening: 568<c>eend</c> functions to inform the user about what is happening:
573</p> 569</p>
574 570
575<pre caption="Example start() function"> 571<pre caption="Example start() function">
576start() { 572start() {
573 if [ "${RC_CMD}" = "restart" ];
574 then
575 <comment># Do something in case a restart requires more than stop, start</comment>
576 fi
577
577 ebegin "Starting my_service" 578 ebegin "Starting my_service"
578 start-stop-daemon --start --exec /path/to/my_service \ 579 start-stop-daemon --start --exec /path/to/my_service \
579 --pidfile /path/to/my_pidfile 580 --pidfile /path/to/my_pidfile
580 eend $? 581 eend $?
581} 582}
589<c>start-stop-daemon</c> options, but this is not recommended unless the 590<c>start-stop-daemon</c> options, but this is not recommended unless the
590service is extremely verbose. Using <c>--quiet</c> may hinder debugging if the 591service is extremely verbose. Using <c>--quiet</c> may hinder debugging if the
591service fails to start. 592service fails to start.
592</p> 593</p>
593 594
595<p>
596Another notable setting used in the above example is to check the contents of
597the <c>RC_CMD</c> variable. Unlike the previous init script system, the newer
598<c>openrc</c> system does not support script-specific restart functionality.
599Instead, the script needs to check the contents of the <c>RC_CMD</c> variable
600to see if a function (be it <c>start()</c> or <c>stop()</c>) is called as part
601of a restart or not.
602</p>
603
594<note> 604<note>
595Make sure that <c>--exec</c> actually calls a service and not just a shell 605Make sure that <c>--exec</c> actually calls a service and not just a shell
596script that launches services and exits -- that's what the init script is 606script that launches services and exits -- that's what the init script is
597supposed to do. 607supposed to do.
598</note> 608</note>
602source code of the available init scripts in your <path>/etc/init.d</path> 612source code of the available init scripts in your <path>/etc/init.d</path>
603directory. 613directory.
604</p> 614</p>
605 615
606<p> 616<p>
607Other functions you can define are: <c>stop()</c> and <c>restart()</c>. You are 617Another function you can define is <c>stop()</c>. You are not obliged to define
608not obliged to define these functions! Our init system is intelligent enough to 618this function though! Our init system is intelligent enough to fill in this
609fill these functions by itself if you use <c>start-stop-daemon</c>. 619function by itself if you use <c>start-stop-daemon</c>.
610</p>
611
612<p> 620</p>
613Although you do not <e>have</e> to create a <c>stop()</c> function, here is an 621
614example: 622<p>
623Here is an example of a <c>stop()</c> function:
615</p> 624</p>
616 625
617<pre caption="Example stop() function"> 626<pre caption="Example stop() function">
618stop() { 627stop() {
619 ebegin "Stopping my_service" 628 ebegin "Stopping my_service"
678 stop 687 stop
679 sleep 3 <comment># Wait 3 seconds before starting again</comment> 688 sleep 3 <comment># Wait 3 seconds before starting again</comment>
680 start 689 start
681} 690}
682</pre> 691</pre>
692
693<impo>
694The function <c>restart()</c> cannot be overridden in openrc!
695</impo>
683 696
684</body> 697</body>
685</subsection> 698</subsection>
686<subsection> 699<subsection>
687<title>Service Configuration Variables</title> 700<title>Service Configuration Variables</title>

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.33

  ViewVC Help
Powered by ViewVC 1.1.20