1
0

mdadm.init 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh /etc/rc.common
  2. START=13
  3. STOP=98
  4. USE_PROCD=1
  5. PROG=/sbin/mdadm
  6. NAME=mdadm
  7. CONF="/var/etc/mdadm.conf"
  8. append_list_item() {
  9. append "$2" "$1" "$3"
  10. }
  11. append_option() {
  12. local var="$1"
  13. local cfg="$2"
  14. local opt="$3"
  15. local name="$4"
  16. local sep="$5"
  17. local str
  18. if [ -n "$sep" ]; then
  19. config_list_foreach "$cfg" "$opt" append_list_item str "$sep"
  20. else
  21. config_get str "$cfg" "$opt"
  22. fi
  23. [ -n "$str" ] && append "$var" $(printf "%s=%s" "${name:-${opt//_/-}}" "$str")
  24. }
  25. mdadm_common() {
  26. local cfg="$1"
  27. local email devices
  28. if [ -x /usr/sbin/sendmail ]; then
  29. config_get email "$cfg" email
  30. [ -n "$email" ] && printf "MAILADDR %s\n" "$email" >> $CONF
  31. fi
  32. config_list_foreach "$cfg" devices append_list_item devices " "
  33. [ -n "$devices" ] && printf "DEVICE %s\n" "$devices" >> $CONF
  34. }
  35. mdadm_array() {
  36. local cfg="$1"
  37. local uuid device devices name array
  38. config_get uuid "$cfg" uuid
  39. config_get name "$cfg" name
  40. config_get device "$cfg" device
  41. if [ -z "$device" ] || [ -z "$uuid$name" ]; then
  42. echo "Skipping array without device, uuid or name" >&2
  43. return
  44. fi
  45. [ -n "$uuid" ] && append array "uuid=$uuid"
  46. [ -n "$name" ] && append array "name=$name"
  47. append_option array "$cfg" super_minor
  48. append_option array "$cfg" spares
  49. append_option array "$cfg" spare_group
  50. append_option array "$cfg" bitmap
  51. append_option array "$cfg" container
  52. append_option array "$cfg" member
  53. append_option array "$cfg" devices devices ","
  54. printf "ARRAY %s %s\n" "$device" "$array" >> $CONF
  55. }
  56. start_service() {
  57. local email
  58. mkdir -p "${CONF%/*}"
  59. printf "# Autogenerated from /etc/config/mdadm, do not edit!\n" > $CONF
  60. config_load mdadm
  61. config_foreach mdadm_common mdadm
  62. config_foreach mdadm_array array
  63. $PROG --assemble --scan --config="$CONF"
  64. procd_open_instance
  65. procd_set_param command "$PROG" --monitor --syslog --scan --config="$CONF"
  66. procd_close_instance
  67. }
  68. stop_service() {
  69. $PROG --stop --scan
  70. }