From 718dfcdcc8d0753e53703e28cd39dd86b48864ed Mon Sep 17 00:00:00 2001 From: Viktor Ribchev Date: Wed, 8 Nov 2023 16:03:45 +0200 Subject: [PATCH] added volume mounting --- modules/vm/templates/entrypoint.sh.tpl | 35 +++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/modules/vm/templates/entrypoint.sh.tpl b/modules/vm/templates/entrypoint.sh.tpl index 93752fb..022475d 100644 --- a/modules/vm/templates/entrypoint.sh.tpl +++ b/modules/vm/templates/entrypoint.sh.tpl @@ -11,8 +11,7 @@ until ping -c 1 google.com &> /dev/null; do sleep 5 done -# TODO: Find/create/mount volumes -# https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/tutorial-use-disks-cli +# Find/create/attach volumes instanceHostname=\'$(hostname)\' subscriptionID=$(az account show --query "id" --output tsv) @@ -21,10 +20,10 @@ vmssName=$(az vmss list --query "[0].name" --output tsv) instanceID=$(az vmss list-instances --resource-group $resourceGroup --name $vmssName --query "[?contains(osProfile.computerName, ${instanceHostname})].instanceId" --output tsv) zoneID=$(az vmss list-instances --resource-group $resourceGroup --name $vmssName --query "[?contains(osProfile.computerName, ${instanceHostname})].zones" --output tsv) regionID=$(az vmss list-instances --resource-group $resourceGroup --name $vmssName --query "[?contains(osProfile.computerName, ${instanceHostname})].location" --output tsv) - # TODO replace with external variables tier="P40" -lun=2 +lun=2 # device will be mounted as sdb +graphdb_device="/dev/sdb" diskSizeGB=128 # Define the disk name based on the hostname @@ -61,6 +60,34 @@ else echo "Device /dev/sdb is not available. Something went wrong." fi +# create a file system if there isn't any +if [ "$graphdb_device: data" = "$(file -s $graphdb_device)" ]; then + mkfs -t ext4 $graphdb_device +fi + +disk_mount_point="/var/opt/graphdb" + +# Check if the disk is already mounted +if ! mount | grep -q "$graphdb_device"; then + echo "The disk at $graphdb_device is not mounted." + + # Create the mount point if it doesn't exist + if [ ! -d "$disk_mount_point" ]; then + mkdir -p "$disk_mount_point" + fi + + # Add an entry to the fstab file to automatically mount the disk + if ! grep -q "$graphdb_device" /etc/fstab; then + echo "$graphdb_device $disk_mount_point ext4 defaults 0 2" >> /etc/fstab + fi + + # Mount the disk + mount "$disk_mount_point" + echo "The disk at $graphdb_device is now mounted at $disk_mount_point." +else + echo "The disk at $graphdb_device is already mounted." +fi + # # DNS hack #