opt_splunk.boothook 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. #
  3. #
  4. exec > /dev/console
  5. exec 2>&1
  6. declare -A EBSMAP
  7. # Build a map of EBS NVMe disks from their AWS-API-name to their NVMe name
  8. # this makes an associative array (like a python hash) of the
  9. # sdX/xvdX name you'd set in AWS API to the corresponding nvmeX name
  10. # Thanks Fred for the awesome id-ctrl stuff I'd never seen before
  11. #
  12. # One interesting side effect observed: the id-ctrl output is different when
  13. # volumes are attached at boot time (no /dev/) versus attached after the OS
  14. # is started (includes /dev/)
  15. function make_nve_ebs_map {
  16. for DEVICE in $( lsblk -d -o NAME,MODEL -n | egrep "Elastic Block Store" | awk '{ print $1 }' ); do
  17. UNDERLYING=$( nvme id-ctrl --raw-binary /dev/${DEVICE} 2>/dev/null | cut -c 3073-3104 | tr -d ' ' | sed "s#/dev/##" )
  18. EBSMAP[$UNDERLYING]=$DEVICE
  19. UNDERLYING2=$( echo $UNDERLYING | sed "s/sd/xvd/" )
  20. EBSMAP[$UNDERLYING2]=$DEVICE
  21. done
  22. }
  23. function do_the_mount
  24. {
  25. VOL_LABEL=$1
  26. VOLUME=$2
  27. MOUNTPOINT=$3
  28. DONE=0
  29. TRIES=0
  30. while [[ $DONE -ne 1 ]] && [[ $TRIES -lt 20 ]]; do
  31. echo "Looking for $VOLUME to come attached"
  32. make_nve_ebs_map
  33. #echo "------- current nvme/ebs map -------"
  34. #for K in "${!EBSMAP[@]}"; do echo $K = ${EBSMAP[$K]} ; done
  35. #echo "------- end current nvme/ebs map -------"
  36. if [[ -b /dev/$VOLUME ]]; then
  37. DEV="/dev/$VOLUME"
  38. DONE=1
  39. elif [[ -b /dev/${EBSMAP[$VOLUME]} ]]; then
  40. DEV="/dev/${EBSMAP[$VOLUME]}"
  41. DONE=1
  42. else
  43. sleep 10
  44. TRIES=$(( $TRIES + 1 ))
  45. fi
  46. echo "Volume $VOLUME available at $DEV"
  47. done
  48. if ! [[ -d ${MOUNTPOINT} ]]; then
  49. echo "Creating mount directory ${MOUNTPOINT}"
  50. mkdir -p ${MOUNTPOINT}
  51. fi
  52. if ! blkid -l -t LABEL=${VOL_LABEL}; then
  53. echo "Making filesystem for LABEL=${VOL_LABEL} on ${DEV}"
  54. mkfs.xfs -L ${VOL_LABEL} ${DEV}
  55. fi
  56. if ! egrep -q "LABEL=${VOL_LABEL}" /etc/fstab; then
  57. echo "Adding LABEL=${VOL_LABEL} to /etc/fstab"
  58. echo "LABEL=${VOL_LABEL} ${MOUNTPOINT} xfs noatime,nofail 0 2" >> /etc/fstab
  59. fi
  60. if ! mountpoint ${MOUNTPOINT} >/dev/null 2>&1; then
  61. echo "Mounting ${MOUNTPOINT}"
  62. mount ${MOUNTPOINT}
  63. fi
  64. }
  65. do_the_mount opt_splunk xvdf /opt/splunk