You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.4 KiB

  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_load_validate hd-idle hd-idle "$1" "$2" \
  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. [ "$2" = 0 ] || return
  40. [ "$enabled" -gt 0 ] || return
  41. if [ "$numdisks" = "0" ]; then
  42. procd_open_instance
  43. procd_set_param command /usr/bin/hd-idle
  44. procd_append_param command -d -i 0
  45. fi
  46. procd_append_param command -a $disk
  47. procd_append_param command -i "$(compute_seconds $idle_time_interval $idle_time_unit)"
  48. numdisks=$(( numdisks + 1 ))
  49. }
  50. start_service() {
  51. config_load "hd-idle"
  52. numdisks="0"
  53. config_foreach validate_section_hdidle "hd-idle" hdidle_append
  54. if [ "$numdisks" -gt 0 ]; then
  55. procd_set_param respawn
  56. procd_close_instance
  57. fi
  58. }
  59. service_triggers() {
  60. procd_add_reload_trigger "hd-idle"
  61. procd_add_validation validate_section_hdidle
  62. }