From a2e2a46f77ac1e06c8d3b7bd42b54627254fbc12 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Wed, 31 Aug 2022 11:12:36 -0400 Subject: [PATCH 1/4] Add support for nvme devices --- bin/create-ebs-volume | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bin/create-ebs-volume b/bin/create-ebs-volume index b599069..a368326 100755 --- a/bin/create-ebs-volume +++ b/bin/create-ebs-volume @@ -149,10 +149,11 @@ function get_next_logical_device() { for letter in ${alphabet[@]}; do # use /dev/xvdb* device names to avoid contention for /dev/sd* and /dev/xvda names # only supported by HVM instances - if [ ! -b "/dev/xvdb${letter}" ]; then + if [[ $created_volumes =~ .*/dev/xvdb${letter}.* ]]; then + continue + fi echo "/dev/xvdb${letter}" break - fi done } @@ -328,13 +329,25 @@ function create_and_attach_volume() { --region $region \ --volume-id $volume_id \ > /dev/null - + error "could not attach volume to instance" fi set -e logthis "waiting for volume $volume_id on filesystem" while true; do + # Check for nvme device + # AWS returns e.g. vol-00338247831716a7b4, the kernel changes that to vol00338247831716a7b + valid_volume_id=`echo $volume_id |sed -e 's/[^a-zA-Z0-9]//'` + # example lsblk output: + # nvme4n1 259:7 0 150G 0 disk vol00338247831716a7b + if LSBLK=`lsblk -o NAME,SERIAL |grep $valid_volume_id`; then + nvme_device=/dev/`echo $LSBLK|cut -f1 -d' '` + logthis "volume $volume_id on filesystem as $nvme_device (aws device $device)" + break + fi + + # Check for xvdb device if [ -e "$device" ]; then logthis "volume $volume_id on filesystem as $device" break @@ -350,7 +363,11 @@ function create_and_attach_volume() { > /dev/null logthis "volume $volume_id DeleteOnTermination ENABLED" - echo $device + if [ -n "$nvme_device" ] ; then + echo "$nvme_device" + else + echo "$device" + fi } create_and_attach_volume From 5ca6e24e05787b8ae1184c2a10db80053ddd3038 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Wed, 31 Aug 2022 11:51:57 -0400 Subject: [PATCH 2/4] Script requires bash Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- bin/ebs-autoscale | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ebs-autoscale b/bin/ebs-autoscale index 17494d2..e6fbdca 100755 --- a/bin/ebs-autoscale +++ b/bin/ebs-autoscale @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Copyright Amazon.com, Inc. or its affiliates. # # Redistribution and use in source and binary forms, with or without From 573dcc41223a586f84034a269918c0d8dba1f6be Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Fri, 21 Jul 2023 17:13:20 -0300 Subject: [PATCH 3/4] Sets file permissions without regards of the current umask setting. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 0674c33..9f2d3a8 100644 --- a/install.sh +++ b/install.sh @@ -133,7 +133,7 @@ fi # make executables available on standard PATH mkdir -p /usr/local/amazon-ebs-autoscale/{bin,shared} cp ${BASEDIR}/bin/{create-ebs-volume,ebs-autoscale} /usr/local/amazon-ebs-autoscale/bin -chmod +x /usr/local/amazon-ebs-autoscale/bin/* +chmod 755 /usr/local/amazon-ebs-autoscale/bin/* ln -sf /usr/local/amazon-ebs-autoscale/bin/* /usr/local/bin/ ln -sf /usr/local/amazon-ebs-autoscale/bin/* /usr/bin/ From ee323f0751c2b6f733692e805b51b9bf3c251bac Mon Sep 17 00:00:00 2001 From: Zvika Gart Date: Tue, 7 Feb 2023 17:50:36 +0000 Subject: [PATCH 4/4] fix: imdsv2 loaded from config file --- config/ebs-autoscale.json | 1 + install.sh | 29 +++++++++++++++-------------- shared/utils.sh | 6 +++--- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/config/ebs-autoscale.json b/config/ebs-autoscale.json index a8507de..deb96f5 100644 --- a/config/ebs-autoscale.json +++ b/config/ebs-autoscale.json @@ -1,6 +1,7 @@ { "mountpoint": "%%MOUNTPOINT%%", "filesystem": "%%FILESYSTEM%%", + "imdsv2": "%%IMDSV2%%", "lvm": { "volume_group": "autoscale_vg", "logical_volume": "autoscale_lv" diff --git a/install.sh b/install.sh index b7c44b0..e9b96ee 100644 --- a/install.sh +++ b/install.sh @@ -185,6 +185,21 @@ done eval set -- "$PARAMS" +# install default config +cat ${BASEDIR}/config/ebs-autoscale.json | \ + sed -e "s#%%MOUNTPOINT%%#${MOUNTPOINT}#" | \ + sed -e "s#%%VOLUMETYPE%%#${VOLUMETYPE}#" | \ + sed -e "s#%%VOLUMEIOPS%%#${VOLUMEIOPS}#" | \ + sed -e "s#%%VOLUMETHOUGHPUT%%#${VOLUMETHOUGHPUT}#" | \ + sed -e "s#%%FILESYSTEM%%#${FILE_SYSTEM}#" | \ + sed -e "s#%%IMDSV2%%#${IMDSV2}#" | \ + sed -e "s#%%MINEBSVOLUMESIZE%%#${MIN_EBS_VOLUME_SIZE}#" | \ + sed -e "s#%%MAXEBSVOLUMESIZE%%#${MAX_EBS_VOLUME_SIZE}#" | \ + sed -e "s#%%MAXLOGICALVOLUMESIZE%%#${MAX_LOGICAL_VOLUME_SIZE}#" | \ + sed -e "s#%%MAXATTACHEDVOLUMES%%#${MAX_ATTACHED_VOLUMES}#" | \ + sed -e "s#%%INITIALUTILIZATIONTHRESHOLD%%#${INITIAL_UTILIZATION_THRESHOLD}#" \ + > /etc/ebs-autoscale.json + initialize # for backwards compatibility evaluate positional parameters like previous 2.0.x and 2.1.x releases @@ -214,20 +229,6 @@ cp ${BASEDIR}/shared/utils.sh /usr/local/amazon-ebs-autoscale/shared # install the logrotate config cp ${BASEDIR}/config/ebs-autoscale.logrotate /etc/logrotate.d/ebs-autoscale -# install default config -cat ${BASEDIR}/config/ebs-autoscale.json | \ - sed -e "s#%%MOUNTPOINT%%#${MOUNTPOINT}#" | \ - sed -e "s#%%VOLUMETYPE%%#${VOLUMETYPE}#" | \ - sed -e "s#%%VOLUMEIOPS%%#${VOLUMEIOPS}#" | \ - sed -e "s#%%VOLUMETHOUGHPUT%%#${VOLUMETHOUGHPUT}#" | \ - sed -e "s#%%FILESYSTEM%%#${FILE_SYSTEM}#" | \ - sed -e "s#%%MINEBSVOLUMESIZE%%#${MIN_EBS_VOLUME_SIZE}#" | \ - sed -e "s#%%MAXEBSVOLUMESIZE%%#${MAX_EBS_VOLUME_SIZE}#" | \ - sed -e "s#%%MAXLOGICALVOLUMESIZE%%#${MAX_LOGICAL_VOLUME_SIZE}#" | \ - sed -e "s#%%MAXATTACHEDVOLUMES%%#${MAX_ATTACHED_VOLUMES}#" | \ - sed -e "s#%%INITIALUTILIZATIONTHRESHOLD%%#${INITIAL_UTILIZATION_THRESHOLD}#" \ - > /etc/ebs-autoscale.json - ## Create filesystem if [ -e $MOUNTPOINT ] && ! [ -d $MOUNTPOINT ]; then echo "ERROR: $MOUNTPOINT exists but is not a directory." diff --git a/shared/utils.sh b/shared/utils.sh index d1a216e..68766c7 100644 --- a/shared/utils.sh +++ b/shared/utils.sh @@ -32,19 +32,19 @@ function get_metadata() { local key=$1 local metadata_ip='169.254.169.254' - if [ ! -z "$IMDSV2" ]; then + if [ ! -z "$(get_config_value .imdsv2)" ]; then local token=$(curl -s -X PUT "http://$metadata_ip/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60") local token_wrapper='-H "X-aws-ec2-metadata-token: $token"' fi - echo `curl -s $token_wrapper http://$metadata_ip/latest/meta-data/$key` + eval "curl -s $token_wrapper http://$metadata_ip/latest/meta-data/$key" } function initialize() { + export EBS_AUTOSCALE_CONFIG_FILE=/etc/ebs-autoscale.json export AWS_AZ=$(get_metadata placement/availability-zone) export AWS_REGION=$(echo ${AWS_AZ} | sed -e 's/[a-z]$//') export INSTANCE_ID=$(get_metadata instance-id) - export EBS_AUTOSCALE_CONFIG_FILE=/etc/ebs-autoscale.json } function detect_init_system() {