init-scripts.tex 2.0 KB

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