man-pages/man5/init-d-script.5.html
2021-03-31 01:06:50 +01:00

259 lines
5.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of INIT-D-SCRIPT</TITLE>
</HEAD><BODY>
<H1>INIT-D-SCRIPT</H1>
Section: File Formats (5)<BR>Updated: Debian sysvinit<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<BR>BSD mandoc<BR>
Debian
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
<B>init-d-script</B>
- interpreter for short and simple init.d scripts
<A NAME="lbAC">&nbsp;</A>
<H2>DESCRIPTION</H2>
Generic init.d script framework to reduce the redundant code in
/etc/init.d/
The goal is to create an init.d script that is Debian and LSB compliant.
When the Debian policy conflicts with the LSB, the Debian policy takes
precedence.
<P>
This is a simple example on how init-d-script can be used to start
and stop a daemon with PID file support:
<BLOCKQUOTE>
<PRE>
#!/usr/bin/env /lib/init/init-d-script
### BEGIN INIT INFO
# Provides: atd
# Required-Start: $syslog $time $remote_fs
# Required-Stop: $syslog $time $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: run at jobs
# Description: Debian init script to start the daemon
# running at jobs.
### END INIT INFO
DAEMON=/usr/sbin/atd
</PRE>
</BLOCKQUOTE>
<P>
The following variables affect behaviour of an init script:
<DL COMPACT>
<P>
<DT id="1"><B>DAEMON</B>
<DD>
Path to daemon being started.
If the init script is not supposed to start any kind of daemon, the functions
Fn do_start_override ,
Fn do_stop_override
and
Fn do_status_override
should be defined instead.
<DT id="2"><B>DAEMON_ARGS</B>
<DD>
Additional arguments, passed to daemon during start.
<DT id="3"><B>NAME</B>
<DD>
Additional environment variables are sources from
/etc/default/${NAME}
If unset, this variable defaults to the basename of the
``<B>DAEMON</B>
''
value.
<DT id="4"><B>COMMAND_NAME</B>
<DD>
If this variable is set, it is used as argument to the
-<B>-name</B>
option of
start-stop-daemon8.
It may be useful if the value of the
<B>NAME</B>
variable is too long.
<DT id="5"><B>PIDFILE</B>
<DD>
Path to file where the process identifier of the started daemon
will be stored during start.
If the value is verbatim
``<B>none</B>
''
the process identifier will not be stored in any file.
If this variable is not set, it gets a sensible default value,
so it is rarely necessary to set this variable explicitly.
</DL>
<P>
<P>
Additionally, it is possible to change the behaviour of the resulting
shell script by overriding some of the internal functions.
To do so, define function with an
<B>_override</B>
suffix.
So, for example, to override the
Fn do_status
function, one should define a
Fn do_status_override
function.
The
<I>exception</I>
to this rule is the
Fn do_reload
function, whose override should be defined as-is,
<I>without</I>
the above-mentioned suffix.
<P>
Here is a control flow chart that explains what functions are called and when:
<BLOCKQUOTE>
<PRE>
/etc/init.d/script start
do_start
do_start_prepare # no-op
do_start_cmd # start-stop-daemon is called here
do_start_cleanup # no-op
/etc/init.d/script stop
do_stop
do_stop_prepare # no-op
do_stop_cmd # start-stop-daemon is called here
do_stop_cleanup # no-op
/etc/init.d/script status
do_status
/etc/init.d/script reload
do_reload
do_usage
exit 3
/etc/init.d/script force-reload
do_force_reload
do_reload # if overridden
do_restart
do_restart_prepare
do_stop_cmd
do_start_cmd
do_restart_cleanup
/etc/init.d/script restart
do_force_restart
/etc/init.d/script try-restart
if do_status; then
do_restart
do_restart_prepare
do_stop_cmd # start-stop-daemon is called here
do_start_cmd # start-stop-daemon is called here
do_restart_cleanup
/etc/init.d/script &lt;arg&gt;
do_unknown &lt;arg&gt;
exit 3
/etc/init.d/script
do_usage
</PRE>
</BLOCKQUOTE>
<P>
As can be seen, by default, the script does not support the
<B>reload</B>
action; it should be implemented by the script writer by defining a
Fn do_reload
function.
<P>
If the daemon performs reload action upon receiving a
<B>SIGUSR1</B>
signal, a generic implementation can be used with the following code:
<BLOCKQUOTE>
<PRE>
alias do_reload=do_reload_sigusr1
</PRE>
</BLOCKQUOTE>
<A NAME="lbAD">&nbsp;</A>
<H2>SEE ALSO</H2>
<A HREF="/cgi-bin/man/man2html?8+inittab">inittab</A>(8),
<A HREF="/cgi-bin/man/man2html?8+service">service</A>(8),
update-rc.d8.
<A NAME="lbAE">&nbsp;</A>
<H2>AUTHORS</H2>
An -nosplit
An Petter Reinholdtsen Aq <A HREF="mailto:pere@debian.org">pere@debian.org</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="6"><A HREF="#lbAB">NAME</A><DD>
<DT id="7"><A HREF="#lbAC">DESCRIPTION</A><DD>
<DT id="8"><A HREF="#lbAD">SEE ALSO</A><DD>
<DT id="9"><A HREF="#lbAE">AUTHORS</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:06:03 GMT, March 31, 2021
</BODY>
</HTML>