1
0

hd-idle.init 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008-2011 OpenWrt.org
  3. START=50
  4. STOP=10
  5. USE_PROCD=1
  6. validate_section_hdidle()
  7. {
  8. uci_validate_section hd-idle hd-idle "${1}" \
  9. 'disk:string' \
  10. 'enabled:bool' \
  11. 'idle_time_interval:uinteger:10' \
  12. 'idle_time_unit:string:minutes'
  13. }
  14. compute_seconds() {
  15. local interval="$1"
  16. local unit="$2"
  17. # compute interval in seconds
  18. case "$unit" in
  19. "days" )
  20. interval_seconds=$(($interval*60*60*24))
  21. ;;
  22. "hours" )
  23. interval_seconds=$(($interval*60*60))
  24. ;;
  25. "minutes" )
  26. interval_seconds=$(($interval*60))
  27. ;;
  28. "seconds" )
  29. interval_seconds=$interval
  30. ;;
  31. * )
  32. # default is minutes
  33. interval_seconds=$(($interval*60))
  34. ;;
  35. esac
  36. echo $interval_seconds
  37. }
  38. hdidle_append() {
  39. local disk enabled idle_time_interval idle_time_unit
  40. validate_section_hdidle "${1}" || return
  41. [ "$enabled" -gt 0 ] || return
  42. if [ "$numdisks" = "0" ]; then
  43. procd_open_instance
  44. procd_set_param command /usr/bin/hd-idle
  45. procd_append_param command -d -i 0
  46. fi
  47. procd_append_param command -a $disk
  48. procd_append_param command -i "$(compute_seconds $idle_time_interval $idle_time_unit)"
  49. numdisks=$(( numdisks + 1 ))
  50. }
  51. start_service() {
  52. config_load "hd-idle"
  53. numdisks="0"
  54. config_foreach hdidle_append "hd-idle"
  55. if [ "$numdisks" -gt 0 ]; then
  56. procd_set_param respawn
  57. procd_close_instance
  58. fi
  59. }