rc.common 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. # Copyright (C) 2006 OpenWrt.org
  3. . $IPKG_INSTROOT/etc/functions.sh
  4. start() {
  5. return 0
  6. }
  7. stop() {
  8. return 0
  9. }
  10. reload() {
  11. return 1
  12. }
  13. restart() {
  14. trap '' TERM
  15. stop "$@"
  16. start "$@"
  17. }
  18. boot() {
  19. start "$@"
  20. }
  21. shutdown() {
  22. return 0
  23. }
  24. disable() {
  25. name="$(basename "${initscript}")"
  26. rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
  27. rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
  28. }
  29. enable() {
  30. name="$(basename "${initscript}")"
  31. disable
  32. [ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
  33. [ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
  34. }
  35. enabled() {
  36. name="$(basename "${initscript}")"
  37. [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
  38. }
  39. depends() {
  40. return 0
  41. }
  42. help() {
  43. cat <<EOF
  44. Syntax: $initscript [command]
  45. Available commands:
  46. start Start the service
  47. stop Stop the service
  48. restart Restart the service
  49. reload Reload configuration files (or restart if that fails)
  50. enable Enable service autostart
  51. disable Disable service autostart
  52. $EXTRA_HELP
  53. EOF
  54. }
  55. initscript="$1"
  56. [ "$#" -ge 1 ] && shift
  57. action="$1"
  58. [ "$#" -ge 1 ] && shift
  59. . "$initscript"
  60. cmds=
  61. for cmd in $EXTRA_COMMANDS; do
  62. cmds="${cmds:+$cmds$N}$cmd) $cmd \"\$@\";;"
  63. done
  64. eval "case \"\$action\" in
  65. start) start \"\$@\";;
  66. stop) stop \"\$@\";;
  67. reload) reload \"\$@\" || restart \"\$@\";;
  68. restart) restart \"\$@\";;
  69. boot) boot \"\$@\";;
  70. shutdown) shutdown \"\$@\";;
  71. enable) enable \"\$@\";;
  72. enabled) enabled \"\$@\";;
  73. disable) disable \"\$@\";;
  74. $cmds
  75. *) help;;
  76. esac"