From 4766a96513c4a9e94ded782503deffe2c1649a97 Mon Sep 17 00:00:00 2001 From: sudkul Date: Tue, 30 Nov 2021 16:33:09 +0530 Subject: [PATCH] Add resize.sh --- Supporting-material/Makefile | 6 ++- Supporting-material/requirements.txt | 3 +- Supporting-material/resize.sh | 59 ++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 Supporting-material/resize.sh diff --git a/Supporting-material/Makefile b/Supporting-material/Makefile index af5777db52..85c2572c32 100644 --- a/Supporting-material/Makefile +++ b/Supporting-material/Makefile @@ -10,4 +10,8 @@ test: lint: pylint --disable=R,C,W1203 example_src/*.py -all: install lint test + +format: + black **/*.py + +all: install lint test \ No newline at end of file diff --git a/Supporting-material/requirements.txt b/Supporting-material/requirements.txt index 0bbdfce523..b852c94ddc 100644 --- a/Supporting-material/requirements.txt +++ b/Supporting-material/requirements.txt @@ -1,4 +1,5 @@ pylint wikipedia python-json-logger -boto3 \ No newline at end of file +boto3 +black \ No newline at end of file diff --git a/Supporting-material/resize.sh b/Supporting-material/resize.sh new file mode 100644 index 0000000000..2953d2d151 --- /dev/null +++ b/Supporting-material/resize.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Specify the desired volume size in GiB as a command line argument. If not specified, default to 20 GiB. +SIZE=${1:-20} + +# Get the ID of the environment host Amazon EC2 instance. +INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id) + +# Get the ID of the Amazon EBS volume associated with the instance. +VOLUMEID=$(aws ec2 describe-instances \ + --instance-id $INSTANCEID \ + --query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \ + --output text) + +# Resize the EBS volume. +aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE + +# Wait for the resize to finish. +while [ \ + "$(aws ec2 describe-volumes-modifications \ + --volume-id $VOLUMEID \ + --filters Name=modification-state,Values="optimizing","completed" \ + --query "length(VolumesModifications)"\ + --output text)" != "1" ]; do +sleep 1 +done + +#Check if we're on an NVMe filesystem +if [ $(readlink -f /dev/xvda) = "/dev/xvda" ] +then + # Rewrite the partition table so that the partition takes up all the space that it can. + sudo growpart /dev/xvda 1 + + # Expand the size of the file system. + # Check if we are on AL2 + STR=$(cat /etc/os-release) + SUB="VERSION_ID=\"2\"" + if [[ "$STR" == *"$SUB"* ]] + then + sudo xfs_growfs -d / + else + sudo resize2fs /dev/xvda1 + fi + +else + # Rewrite the partition table so that the partition takes up all the space that it can. + sudo growpart /dev/nvme0n1 1 + + # Expand the size of the file system. + # Check if we're on AL2 + STR=$(cat /etc/os-release) + SUB="VERSION_ID=\"2\"" + if [[ "$STR" == *"$SUB"* ]] + then + sudo xfs_growfs -d / + else + sudo resize2fs /dev/nvme0n1p1 + fi +fi \ No newline at end of file