1
0

rc.common 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/bin/sh
  2. # Copyright (C) 2006-2012 OpenWrt.org
  3. . $IPKG_INSTROOT/lib/functions.sh
  4. . $IPKG_INSTROOT/lib/functions/service.sh
  5. initscript=$1
  6. action=${2:-help}
  7. shift 2
  8. start() {
  9. return 0
  10. }
  11. stop() {
  12. return 0
  13. }
  14. reload() {
  15. restart
  16. }
  17. restart() {
  18. trap '' TERM
  19. stop "$@"
  20. trap - TERM
  21. start "$@"
  22. }
  23. boot() {
  24. start "$@"
  25. }
  26. shutdown() {
  27. stop
  28. }
  29. disable() {
  30. name="$(basename "${initscript}")"
  31. rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
  32. rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
  33. }
  34. enable() {
  35. err=1
  36. name="$(basename "${initscript}")"
  37. [ "$START" ] && \
  38. ln -sf "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" && \
  39. err=0
  40. [ "$STOP" ] && \
  41. ln -sf "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}" && \
  42. err=0
  43. return $err
  44. }
  45. enabled() {
  46. name="$(basename "${initscript}")"
  47. [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
  48. }
  49. depends() {
  50. return 0
  51. }
  52. help() {
  53. cat <<EOF
  54. Syntax: $initscript [command]
  55. Available commands:
  56. start Start the service
  57. stop Stop the service
  58. restart Restart the service
  59. reload Reload configuration files (or restart if service does not implement reload)
  60. enable Enable service autostart
  61. disable Disable service autostart
  62. $EXTRA_HELP
  63. EOF
  64. }
  65. # for procd
  66. start_service() {
  67. return 0
  68. }
  69. stop_service() {
  70. return 0
  71. }
  72. service_triggers() {
  73. return 0
  74. }
  75. service_data() {
  76. return 0
  77. }
  78. service_running() {
  79. return 0
  80. }
  81. ${INIT_TRACE:+set -x}
  82. . "$initscript"
  83. [ -n "$USE_PROCD" ] && {
  84. EXTRA_COMMANDS="${EXTRA_COMMANDS} running trace"
  85. . $IPKG_INSTROOT/lib/functions/procd.sh
  86. basescript=$(readlink "$initscript")
  87. rc_procd() {
  88. local method="set"
  89. [ -n "$2" ] && method="add"
  90. procd_open_service "$(basename ${basescript:-$initscript})" "$initscript"
  91. "$@"
  92. procd_close_service "$method"
  93. }
  94. start() {
  95. rc_procd start_service "$@"
  96. if eval "type service_started" 2>/dev/null >/dev/null; then
  97. service_started
  98. fi
  99. }
  100. trace() {
  101. TRACE_SYSCALLS=1
  102. start "$@"
  103. }
  104. stop() {
  105. procd_lock
  106. stop_service "$@"
  107. procd_kill "$(basename ${basescript:-$initscript})" "$1"
  108. if eval "type service_stopped" 2>/dev/null >/dev/null; then
  109. service_stopped
  110. fi
  111. }
  112. reload() {
  113. if eval "type reload_service" 2>/dev/null >/dev/null; then
  114. procd_lock
  115. reload_service "$@"
  116. else
  117. start
  118. fi
  119. }
  120. running() {
  121. service_running "$@"
  122. }
  123. }
  124. ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
  125. list_contains ALL_COMMANDS "$action" || action=help
  126. $action "$@"