Lines 440-449
Link Here
|
440 |
stop() { |
440 |
stop() { |
441 |
<comment>(Commands necessary to stop the service)</comment> |
441 |
<comment>(Commands necessary to stop the service)</comment> |
442 |
} |
442 |
} |
443 |
|
|
|
444 |
restart() { |
445 |
<comment>(Commands necessary to restart the service)</comment> |
446 |
} |
447 |
</pre> |
443 |
</pre> |
448 |
|
444 |
|
449 |
<p> |
445 |
<p> |
Lines 574-579
Link Here
|
574 |
|
570 |
|
575 |
<pre caption="Example start() function"> |
571 |
<pre caption="Example start() function"> |
576 |
start() { |
572 |
start() { |
|
|
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 |
Lines 591-596
Link Here
|
591 |
service fails to start. |
592 |
service fails to start. |
592 |
</p> |
593 |
</p> |
593 |
|
594 |
|
|
|
595 |
<p> |
596 |
Another notable setting used in the above example is to check the contents of |
597 |
the <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. |
599 |
Instead, the script needs to check the contents of the <c>RC_CMD</c> variable to |
600 |
see if a function (be it <c>start()</c> or <c>stop()</c>) is called as part of a |
601 |
restart or not. |
602 |
</p> |
603 |
|
594 |
<note> |
604 |
<note> |
595 |
Make sure that <c>--exec</c> actually calls a service and not just a shell |
605 |
Make sure that <c>--exec</c> actually calls a service and not just a shell |
596 |
script that launches services and exits -- that's what the init script is |
606 |
script that launches services and exits -- that's what the init script is |
Lines 604-617
Link Here
|
604 |
</p> |
614 |
</p> |
605 |
|
615 |
|
606 |
<p> |
616 |
<p> |
607 |
Other functions you can define are: <c>stop()</c> and <c>restart()</c>. You are |
617 |
Another function you can define is <c>stop()</c>. You are not obliged to define |
608 |
not obliged to define these functions! Our init system is intelligent enough to |
618 |
this function though! Our init system is intelligent enough to fill this |
609 |
fill these functions by itself if you use <c>start-stop-daemon</c>. |
619 |
functions by itself if you use <c>start-stop-daemon</c>. |
610 |
</p> |
620 |
</p> |
611 |
|
621 |
|
612 |
<p> |
622 |
<p> |
613 |
Although you do not <e>have</e> to create a <c>stop()</c> function, here is an |
623 |
Here is an example of a <c>stop()</c> function: |
614 |
example: |
|
|
615 |
</p> |
624 |
</p> |
616 |
|
625 |
|
617 |
<pre caption="Example stop() function"> |
626 |
<pre caption="Example stop() function"> |
Lines 681-686
Link Here
|
681 |
} |
690 |
} |
682 |
</pre> |
691 |
</pre> |
683 |
|
692 |
|
|
|
693 |
<impo> |
694 |
The function <c>restart()</c> however cannot be overridden in openrc! |
695 |
</impo> |
696 |
|
684 |
</body> |
697 |
</body> |
685 |
</subsection> |
698 |
</subsection> |
686 |
<subsection> |
699 |
<subsection> |