rc.common 1.3 KB

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