/[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.25 Revision 1.26
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.25 2006/03/14 19:29:29 neysx Exp $ --> 7<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-rcscripts.xml,v 1.26 2006/09/07 08:23:02 nightmorph Exp $ -->
8 8
9<sections> 9<sections>
10 10
11<version>1.21</version> 11<version>1.22</version>
12<date>2005-05-29</date> 12<date>2006-09-07</date>
13 13
14<section> 14<section>
15<title>Runlevels</title> 15<title>Runlevels</title>
16<subsection> 16<subsection>
17<title>Booting your System</title> 17<title>Booting your System</title>
533depend() { 533depend() {
534 before * 534 before *
535} 535}
536</pre> 536</pre>
537 537
538<p>
539If your service must write to local disks, it should need <c>localmount</c>. If
540it places anything in <path>/var/run</path> such as a pidfile, then should
541start after <c>bootmisc</c>:
542</p>
543
544<pre caption="Example depend() function">
545depend() {
546 need localmount
547 after bootmisc
548}
549</pre>
550
538</body> 551</body>
539</subsection> 552</subsection>
540<subsection> 553<subsection>
541<title>Standard Functions</title> 554<title>Standard Functions</title>
542<body> 555<body>
549</p> 562</p>
550 563
551<pre caption="Example start() function"> 564<pre caption="Example start() function">
552start() { 565start() {
553 ebegin "Starting my_service" 566 ebegin "Starting my_service"
554 start-stop-daemon --start --quiet --exec /path/to/my_service 567 start-stop-daemon --start --exec /path/to/my_service \
568 --pidfile /path/to/my_pidfile
555 eend $? 569 eend $?
556} 570}
557</pre> 571</pre>
558 572
559<p> 573<p>
574Both <c>--exec</c> and <c>--pidfile</c> should be used in start and stop
575functions. If the service does not create a pidfile, then use
576<c>--make-pidfile</c> if possible, though you should test this to be sure.
577Otherwise, don't use pidfiles. You can also add <c>--quiet</c> to the
578<c>start-stop-daemon</c> options, but this is not recommended unless the
579service is extremely verbose. Using <c>--quiet</c> may hinder debugging if the
580service fails to start.
581</p>
582
583<note>
584Make sure that <c>--exec</c> actually calls a service and not just a shell
585script that launches services and exits -- that's what the init script is
586supposed to do.
587</note>
588
589<p>
560If you need more examples of the <c>start()</c> function, please read the source 590If you need more examples of the <c>start()</c> function, please read the
561code of the available init scripts in your <path>/etc/init.d</path> directory. 591source code of the available init scripts in your <path>/etc/init.d</path>
562As for <c>start-stop-daemon</c>, there is an excellent man page available if you 592directory.
563need more information:
564</p>
565
566<pre caption="Getting the man page for start-stop-daemon">
567# <i>man start-stop-daemon</i>
568</pre> 593</p>
569 594
570<p> 595<p>
571Other functions you can define are: <c>stop()</c> and <c>restart()</c>. You are 596Other functions you can define are: <c>stop()</c> and <c>restart()</c>. You are
572not obliged to define these functions! Our init system is intelligent enough to 597not obliged to define these functions! Our init system is intelligent enough to
573fill these functions by itself if you use <c>start-stop-daemon</c>. 598fill these functions by itself if you use <c>start-stop-daemon</c>.
574</p> 599</p>
600
601<p>
602Although you do not <e>have</e> to create a <c>stop()</c> function, here is an
603example:
604</p>
605
606<pre caption="Example stop() function">
607stop() {
608 ebegin "Stopping my_service"
609 start-stop-daemon --stop --exec /path/to/my_service \
610 --pidfile /path/to/my_pidfile
611 eend $?
612}
613</pre>
614
615<p>
616If your service runs some other script (for example, bash, python, or perl),
617and this script later changes names (for example, <c>foo.py</c> to <c>foo</c>),
618then you will need to add <c>--name</c> to <c>start-stop-daemon</c>. You must
619specify the name that your script will be changed to. In this example, a
620service starts <c>foo.py</c>, which changes names to <c>foo</c>:
621</p>
622
623<pre caption="A service that starts the foo script">
624start() {
625 ebegin "Starting my_script"
626 start-stop-daemon --start --exec /path/to/my_script \
627 --pidfile /path/to/my_pidfile --name foo
628 eend $?
629}
630</pre>
631
632<p>
633<c>start-stop-daemon</c> has an excellent man page available if you need more
634information:
635</p>
636
637<pre caption="Getting the man page for start-stop-daemon">
638$ <i>man start-stop-daemon</i>
639</pre>
575 640
576<p> 641<p>
577Gentoo's init script syntax is based on the Bourne Again Shell (bash) so you are 642Gentoo's init script syntax is based on the Bourne Again Shell (bash) so you are
578free to use bash-compatible constructs inside your init script. 643free to use bash-compatible constructs inside your init script.
579</p> 644</p>

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

  ViewVC Help
Powered by ViewVC 1.1.20