Skip to content

Commit

Permalink
double $$
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-ribchev committed Nov 9, 2023
1 parent 197f1ec commit 62d535d
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions modules/vm/templates/entrypoint.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,42 @@ done

# Find/create/attach volumes

instanceHostname=\'$(hostname)\'
subscriptionID=$(az account show --query "id" --output tsv)
resourceGroup=$(az vmss list --query "[0].resourceGroup" --output tsv)
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)
instanceHostname=\'$$(hostname)\'
subscriptionID=$$(az account show --query "id" --output tsv)
resourceGroup=$$(az vmss list --query "[0].resourceGroup" --output tsv)
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 # device will be mounted as sdb
graphdb_device="/dev/sdb"
diskSizeGB=128

# Define the disk name based on the hostname
diskName="Disk_${vmssName}_${instanceID}"
diskName="Disk_$${vmssName}_$${instanceID}"

# Check if the device sdb exists
if [ ! -b /dev/sdb ]; then
echo "Device /dev/sdb not found."

# Check if the managed disk is already attached to this instance
if [[ $(az vmss list-instances --resource-group $resourceGroup --name $vmssName --query "[?instanceId==\"$instanceID\"].disks[].name" --output tsv) == "$diskName" ]]; then
if [[ $(az vmss list-instances --resource-group $$resourceGroup --name $$vmssName --query "[?instanceId==\"$$instanceID\"].disks[].name" --output tsv) == "$$diskName" ]]; then
echo "Managed disk is already attached."
else
# Try to attach an existing managed disk
availableDisk=$(az disk list --resource-group $resourceGroup --query "[?diskState=='Unattached' && starts_with(name, 'Disk_${vmssName}') && zones[0]=='${zoneID}'].{Name:name}" --output tsv)
if [ -n "$availableDisk" ]; then
echo "Attaching available disk $availableDisk."
az vmss disk attach --vmss-name $vmssName --resource-group $resourceGroup --instance-id $instanceID --lun $lun --disk "$availableDisk"
availableDisk=$(az disk list --resource-group $$resourceGroup --query "[?diskState=='Unattached' && starts_with(name, 'Disk_$${vmssName}') && zones[0]=='$${zoneID}'].{Name:name}" --output tsv)
if [ -n "$$availableDisk" ]; then
echo "Attaching available disk $$availableDisk."
az vmss disk attach --vmss-name $$vmssName --resource-group $$resourceGroup --instance-id $$instanceID --lun $lun --disk "$$availableDisk"
else
# Create a new managed disk
echo "Creating a new managed disk and attaching it."
az disk create --resource-group $resourceGroup --name $diskName --size-gb $diskSizeGB --location $regionID --sku Premium_LRS --zone $zoneID --tier $tier
az disk create --resource-group $$resourceGroup --name $$diskName --size-gb $$diskSizeGB --location $$regionID --sku Premium_LRS --zone $$zoneID --tier $$tier

# Attach the newly created disk
az vmss disk attach --vmss-name $vmssName --resource-group $resourceGroup --instance-id $instanceID --lun $lun --sku Premium_LRS --disk "/subscriptions/$subscriptionID/resourceGroups/$resourceGroup/providers/Microsoft.Compute/disks/$diskName"
az vmss disk attach --vmss-name $$vmssName --resource-group $$resourceGroup --instance-id $$instanceID --lun $$lun --sku Premium_LRS --disk "/subscriptions/$$subscriptionID/resourceGroups/$$resourceGroup/providers/Microsoft.Compute/disks/$$diskName"
fi
fi
fi
Expand All @@ -62,31 +62,31 @@ else
fi

# create a file system if there isn't any
if [ "$graphdb_device: data" = "$(file -s $graphdb_device)" ]; then
mkfs -t ext4 $graphdb_device
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."
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"
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
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."
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."
echo "The disk at $$graphdb_device is already mounted."
fi

# Recreates folders if necessary and changes owner
Expand Down

0 comments on commit 62d535d

Please sign in to comment.