2
0

40-dinit 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ### this is sourced at the beginning of any initscript
  2. ### This file used for forward /etc/init.d/$sv to dinit service $sv
  3. ## If this file exist, We forward any initscript which has dinit service
  4. [ -e /run/lsb.sysvredirectdinit ] || forcesysv=1
  5. ## Dinit services directories
  6. [ -d /etc/dinit.d ] && etc_dinit="/etc/dinit.d"
  7. [ -d /lib/dinit.d ] && lib_dinit="/lib/dinit.d"
  8. [ -d /usr/local/lib/dinit.d ] && local_lib_dinit="/usr/local/lib/dinit.d"
  9. # Get the service basename and action, like 40-systemd
  10. if [ -n "${__init_d_script_name:-}" ]; then
  11. service="$__init_d_script_name"
  12. action="$1"
  13. [ x"${2:-}" = 'x--force-sysv' ] && forcesysv=1
  14. elif [ "${0##*/}" = "init-d-script" ] || [ "${0##*/}" = "${1:-}" ]; then
  15. service="$1"
  16. action="$2"
  17. [ x"${3:-}" = 'x--force-sysv' ] && forcesysv=1
  18. else
  19. service="$0"
  20. action="${1:-}"
  21. [ x"${2:-}" = 'x--force-sysv' ] && forcesysv=1
  22. fi
  23. service=${service##*/}
  24. service="${service%.sh}"
  25. for dinitsrv in ${etc_dinit:-} ${lib_dinit:-} ${local_lib_dinit:-}; do
  26. if [ -e "$dinitsrv"/"$service" ]; then
  27. has_dinit=1
  28. break
  29. fi
  30. done
  31. if [ -z "${forcesysv:-}" ] && [ -n "${has_dinit:-}" ]; then # Forward
  32. case "$action" in
  33. start|stop|restart|reload|status)
  34. dinitctl "$action" "$service" || true
  35. exit 0
  36. ;;
  37. force-stop|force-reload|force-restart)
  38. dinitctl --force "${action##*-}" "$service" || true
  39. exit 0
  40. ;;
  41. *)
  42. echo "WARNING: $action not supported by dinitctl, giving up"
  43. exit 0
  44. ;;
  45. esac
  46. fi