Because OpenWrt uses its own init script system, all init scripts must be installed
as \texttt{/etc/init.d/\textit{name}} use \texttt{/etc/rc.common} as a wrapper.

Example: \texttt{/etc/init.d/httpd}

\begin{Verbatim}
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=50
start() {
    [ -d /www ] && httpd -p 80 -h /www -r OpenWrt
}

stop() {
    killall httpd
}
\end{Verbatim}

as you can see, the script does not actually parse the command line arguments itself.
This is done by the wrapper script \texttt{/etc/rc.common}.

\texttt{start()} and \texttt{stop()} are the basic functions, which almost any init
script should provide. \texttt{start()} is called when the user runs \texttt{/etc/init.d/httpd start}
or (if the script is enabled and does not override this behavior) at system boot time.

Enabling and disabling init scripts is done by running \texttt{/etc/init.d/\textit{name} enable}
or \texttt{/etc/init.d/\textit{name} disable}. This creates or removes symbolic links to the
init script in \texttt{/etc/rc.d}, which is processed by \texttt{/etc/init.d/rcS} at boot time.

The order in which these scripts are run is defined in the variable \texttt{START} in the init
script. Changing it requires running \texttt{/etc/init.d/\textit{name} enable} again.

You can also override these standard init script functions:
\begin{itemize}
    \item \texttt{boot()} \\
        Commands to be run at boot time. Defaults to \texttt{start()}

    \item \texttt{restart()} \\
        Restart your service. Defaults to \texttt{stop(); start()}

    \item \texttt{reload()} \\
        Reload the configuration files for your service. Defaults to \texttt{restart()}

\end{itemize}

You can also add custom commands by creating the appropriate functions and referencing them
in the \texttt{EXTRA\_COMMANDS} variable. Helptext is added in \texttt{EXTRA\_HELP}.

Example:

\begin{Verbatim}
status() {
    # print the status info
}

EXTRA_COMMANDS="status"
EXTRA_HELP="        status  Print the status of the service"
\end{Verbatim}

2.03.0-rc5&amp;id=869d3adc379aac12b8933d1f3072a809dcf748c5'>tree</a><a href='/cgit/openwrt/upstream/commit/target/linux/Makefile?h=v22.03.0-rc5&amp;id=869d3adc379aac12b8933d1f3072a809dcf748c5'>commit</a><a href='/cgit/openwrt/upstream/diff/target/linux/Makefile?h=v22.03.0-rc5&amp;id=869d3adc379aac12b8933d1f3072a809dcf748c5'>diff</a><a href='/cgit/openwrt/upstream/stats/target/linux/Makefile?h=v22.03.0-rc5'>stats</a></td><td class='form'><form class='right' method='get' action='/cgit/openwrt/upstream/log/target/linux/Makefile'>
<input type='hidden' name='h' value='v22.03.0-rc5'/><input type='hidden' name='id' value='869d3adc379aac12b8933d1f3072a809dcf748c5'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit/openwrt/upstream/tree/?h=v22.03.0-rc5&amp;id=869d3adc379aac12b8933d1f3072a809dcf748c5'>root</a>/<a href='/cgit/openwrt/upstream/tree/target?h=v22.03.0-rc5&amp;id=869d3adc379aac12b8933d1f3072a809dcf748c5'>target</a>/<a href='/cgit/openwrt/upstream/tree/target/linux?h=v22.03.0-rc5&amp;id=869d3adc379aac12b8933d1f3072a809dcf748c5'>linux</a>/<a href='/cgit/openwrt/upstream/tree/target/linux/Makefile?h=v22.03.0-rc5&amp;id=869d3adc379aac12b8933d1f3072a809dcf748c5'>Makefile</a></div><div class='content'>blob: f7bbdffbf831654ca8617277e5fd7aeb8959f416 (<a href='/cgit/openwrt/upstream/plain/target/linux/Makefile?h=v22.03.0-rc5&amp;id=869d3adc379aac12b8933d1f3072a809dcf748c5'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
<a id='n13' href='#n13'>13</a>
</pre></td>
<td class='lines'><pre><code>