Skip to content

Commit 6dfee9b

Browse files
authored
Update linux_userData.sh -
- Set LUN size to 90% of vol size - Make disk persist after boot - Move ONTAP_USER to user data section - Fix check of multi session update - Fix check if service is running
1 parent 9db6810 commit 6dfee9b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Management-Utilities/ec2-user-data-iscsi-create-and-mount/linux_userData.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@ VOLUME_NAME=[Fsx volume name, e.g. iscsiVol]
1212
VOLUME_SIZE=[volume size in GB, e.g 100g]
1313
# Default value is fsx, but you can change it to any other value according to yours FSx for ONTAP SVM name
1414
SVM_NAME=fsx
15+
# Default value is fsxadmin, but you can change it to any other value according to yours FSx for ONTAP admin user name
16+
ONTAP_USER=fsxadmin
1517
# end - user data
1618

17-
1819
min=100
1920
max=999
2021
LUN_NAME=${VOLUME_NAME}_$(($RANDOM%($max-$min+1)+$min))
2122

2223
# defaults
23-
# All FSxN instances are created with the user 'fsxadmin' which can't be changed
2424
# The script will create a log file in the ec2-user home directory
25-
ONTAP_USER=fsxadmin
2625
LOG_FILE=/home/ec2-user/install.log
2726

2827
VOL_SIZE=$(echo $VOLUME_SIZE | sed 's/.$//')
29-
LUN_SIZE=$(bc -l <<< "0.85*$VOL_SIZE" )
28+
LUN_SIZE=$(bc -l <<< "0.90*$VOL_SIZE" )
3029

3130
echo "# Uninstall file" >> uninstall.sh
3231
chmod u+x uninstall.sh
@@ -76,6 +75,7 @@ addUndoCommand "yum remove -y device-mapper-multipath iscsi-initiator-utils"
7675
commandDescription="Set multisession replacment time from default 120 sec to 5 sec"
7776
logMessage "${commandDescription}"
7877
sed -i 's/node.session.timeo.replacement_timeout = .*/node.session.timeo.replacement_timeout = 5/' /etc/iscsi/iscsid.conf; cat /etc/iscsi/iscsid.conf | grep node.session.timeo.replacement_timeout
78+
cat /etc/iscsi/iscsid.conf | grep "node.session.timeo.replacement_timeout = 5"
7979
checkCommand "${commandDescription}"
8080
addUndoCommand "sed -i 's/node.session.timeo.replacement_timeout = .*/node.session.timeo.replacement_timeout = 120/' /etc/iscsi/iscsid.conf; cat /etc/iscsi/iscsid.conf | grep node.session.timeo.replacement_timeout"
8181

@@ -86,7 +86,7 @@ systemctl start iscsid
8686
checkCommand "${commandDescription}"
8787

8888
# check if the service is running
89-
isIscsciServiceRunning=$(systemctl is-active --quiet iscsid.service && echo "1")
89+
isIscsciServiceRunning=$(systemctl is-active --quiet iscsid.service && echo "1" || echo "0")
9090
if [ "$isIscsciServiceRunning" -eq 1 ]; then
9191
logMessage "iscsi service is running"
9292
addUndoCommand "systemctl --now disable iscsid.service"
@@ -152,7 +152,7 @@ sshpass -p $FSXN_PASSWORD ssh -o StrictHostKeyChecking=no $ONTAP_USER@$FSXN_ADMI
152152
checkCommand "${commandDescription}"
153153
addUndoCommand "sshpass -p ${FSXN_PASSWORD} ssh -o StrictHostKeyChecking=no ${ONTAP_USER}@${FSXN_ADMIN_IP} volume delete -vserver ${SVM_NAME} -volume ${VOLUME_NAME} -force"
154154

155-
commandDescription="Create iscsi lun for vserver: ${SVM_NAME} volume name: ${VOLUME_NAME} and lun name: ${LUN_NAME} and size: ${LUN_SIZE}g"
155+
commandDescription="Create iscsi lun for vserver: ${SVM_NAME} volume name: ${VOLUME_NAME} and lun name: ${LUN_NAME} and size: ${LUN_SIZE}g which is 90% of the volume size"
156156
logMessage "${commandDescription}"
157157
sshpass -p $FSXN_PASSWORD ssh -o StrictHostKeyChecking=no $ONTAP_USER@$FSXN_ADMIN_IP "lun create -vserver $SVM_NAME -path /vol/$VOLUME_NAME/$LUN_NAME -size "${LUN_SIZE}g" -ostype linux -space-allocation enabled"
158158
checkCommand "${commandDescription}"
@@ -306,4 +306,14 @@ cat /$directory_path/$mount_point/testIscsci.txt
306306

307307
logMessage "Mounting the FSXn iSCSI volume was successful."
308308

309+
# Add the mount entry to /etc/fstab
310+
commandDescription="Add the mount entry to /etc/fstab"
311+
logMessage "${commandDescription}"
312+
echo "/dev/mapper/$ALIAS /$directory_path/$mount_point ext4 defaults,_netdev 0 0" >> /etc/fstab
313+
checkCommand "${commandDescription}"
314+
addUndoCommand "sed -i '/\/dev\/mapper\/$ALIAS \/mnt\/$mount_point ext4 defaults,_netdev 0 0/d' /etc/fstab"
315+
# End of script
316+
logMessage "Script completed successfully."
317+
318+
309319
rm -f uninstall.sh

0 commit comments

Comments
 (0)