Root/docs/init-scripts.tex

1Because OpenWrt uses its own init script system, all init scripts must be installed
2as \texttt{/etc/init.d/\textit{name}} use \texttt{/etc/rc.common} as a wrapper.
3
4Example: \texttt{/etc/init.d/httpd}
5
6\begin{Verbatim}
7#!/bin/sh /etc/rc.common
8# Copyright (C) 2006 OpenWrt.org
9
10START=50
11start() {
12    [ -d /www ] && httpd -p 80 -h /www -r OpenWrt
13}
14
15stop() {
16    killall httpd
17}
18\end{Verbatim}
19
20as you can see, the script does not actually parse the command line arguments itself.
21This is done by the wrapper script \texttt{/etc/rc.common}.
22
23\texttt{start()} and \texttt{stop()} are the basic functions, which almost any init
24script should provide. \texttt{start()} is called when the user runs \texttt{/etc/init.d/httpd start}
25or (if the script is enabled and does not override this behavior) at system boot time.
26
27Enabling and disabling init scripts is done by running \texttt{/etc/init.d/\textit{name} enable}
28or \texttt{/etc/init.d/\textit{name} disable}. This creates or removes symbolic links to the
29init script in \texttt{/etc/rc.d}, which is processed by \texttt{/etc/init.d/rcS} at boot time.
30
31The order in which these scripts are run is defined in the variable \texttt{START} in the init
32script. Changing it requires running \texttt{/etc/init.d/\textit{name} enable} again.
33
34You can also override these standard init script functions:
35\begin{itemize}
36    \item \texttt{boot()} \\
37        Commands to be run at boot time. Defaults to \texttt{start()}
38
39    \item \texttt{restart()} \\
40        Restart your service. Defaults to \texttt{stop(); start()}
41
42    \item \texttt{reload()} \\
43        Reload the configuration files for your service. Defaults to \texttt{restart()}
44
45\end{itemize}
46
47You can also add custom commands by creating the appropriate functions and referencing them
48in the \texttt{EXTRA\_COMMANDS} variable. Helptext is added in \texttt{EXTRA\_HELP}.
49
50Example:
51
52\begin{Verbatim}
53status() {
54    # print the status info
55}
56
57EXTRA_COMMANDS="status"
58EXTRA_HELP=" status Print the status of the service"
59\end{Verbatim}
60
61

Archive Download this file



interactive