@@ -29,7 +29,7 @@ VOL_SIZE=$(echo $VOLUME_SIZE | sed 's/.$//')
2929LUN_SIZE=$( bc -l <<< " 0.85*$VOL_SIZE" )
3030
3131echo " # Uninstall file" >> uninstall.sh
32- sudo chmod u+x uninstall.sh
32+ chmod u+x uninstall.sh
3333
3434function getSecretValue() {
3535 secret_name=$1
@@ -69,26 +69,27 @@ logMessage "Secret data retrieved successfully"
6969
7070commandDescription=" Install linux iSCSI packages"
7171logMessage " ${commandDescription} "
72- sudo yum install -y device-mapper-multipath iscsi-initiator-utils
72+ yum install -y device-mapper-multipath iscsi-initiator-utils
7373checkCommand " ${commandDescription} "
74- addUndoCommand " sudo yum remove -y device-mapper-multipath iscsi-initiator-utils"
74+ addUndoCommand " yum remove -y device-mapper-multipath iscsi-initiator-utils"
7575
7676commandDescription=" Set multisession replacment time from default 120 sec to 5 sec"
7777logMessage " ${commandDescription} "
78- sudo sed -i ' s/node.session.timeo.replacement_timeout = .*/node.session.timeo.replacement_timeout = 5/' /etc/iscsi/iscsid.conf; sudo cat /etc/iscsi/iscsid.conf | grep node.session.timeo.replacement_timeout
78+ 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
7979checkCommand " ${commandDescription} "
80- addUndoCommand " sudo sed -i 's/node.session.timeo.replacement_timeout = .*/node.session.timeo.replacement_timeout = 120/' /etc/iscsi/iscsid.conf; sudo cat /etc/iscsi/iscsid.conf | grep node.session.timeo.replacement_timeout"
80+ 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
8282commandDescription=" Start iscsi service"
8383logMessage " ${commandDescription} "
84- sudo service iscsid start
84+ systemctl enable iscsid
85+ systemctl start iscsid
8586checkCommand " ${commandDescription} "
8687
8788# check if the service is running
88- isIscsciServiceRunning=$( sudo service iscsid status | grep " Active: active (running) " | wc -l )
89+ isIscsciServiceRunning=$( systemctl is-active --quiet iscsid.service && echo " 1 " )
8990if [ " $isIscsciServiceRunning " -eq 1 ]; then
9091 logMessage " iscsi service is running"
91- addUndoCommand " sudo service iscsid stop "
92+ addUndoCommand " systemctl --now disable iscsid.service "
9293else
9394 logMessage " iscsi service is not running, aborting"
9495 # now we have to rollback and exit
9798
9899commandDescription=" Set multipath configuration which allow automatic failover between yours file servers"
99100logMessage " ${commandDescription} "
100- sudo mpathconf --enable --with_multipathd y
101+ mpathconf --enable --with_multipathd y
101102checkCommand " ${commandDescription} "
102- addUndoCommand " sudo mpathconf --disable"
103+ addUndoCommand " mpathconf --disable"
103104
104105# set the initiator name of your Linux host
105- name=$( sudo cat /etc/iscsi/initiatorname.iscsi)
106+ name=$( cat /etc/iscsi/initiatorname.iscsi)
106107initiatorName=" ${name: 14} "
107108logMessage " initiatorName is: ${initiatorName} "
108109
109110# Configure iSCSI on the FSx for ONTAP file system
110111commandDescription=" Install sshpass which will allow to connect FSXn using SSH"
111112logMessage " ${commandDescription} "
112- sudo yum install -y sshpass
113+ yum install -y sshpass
113114checkCommand " ${commandDescription} "
114- addUndoCommand " sudo yum remove -y sshpass"
115+ addUndoCommand " yum remove -y sshpass"
115116
116117# Test connection to ONTAP
117118commandDescription=" Testing connection to ONTAP."
@@ -124,7 +125,7 @@ groupName=$(hostname)
124125
125126commandDescription=" Create initiator group for vserver: ${SVM_NAME} group name: ${groupName} and intiator name: ${initiatorName} "
126127
127- lunGroupresult=${ sshpass -p $FSXN_PASSWORD ssh -o StrictHostKeyChecking=no $ONTAP_USER @ $FSXN_ADMIN_IP " lun igroup show -vserver $SVM_NAME -igroup $groupName -initiator $initiatorName -protocol iscsi -ostype linux" }
128+ lunGroupresult=$( sshpass -p $FSXN_PASSWORD ssh -o StrictHostKeyChecking=no $ONTAP_USER @$FSXN_ADMIN_IP " lun igroup show -vserver $SVM_NAME -igroup $groupName -initiator $initiatorName -protocol iscsi -ostype linux" )
128129if [[ " $lunGroupresult " == * " There are no entries matching your query." * ]]; then
129130 logMessage " Initiator ${initiatorName} with group ${groupName} does not exist, creating it."
130131 logMessage " ${commandDescription} "
194195
195196commandDescription=" Discover the target iSCSI nodes, iscsi IP: ${iscsi1IP} "
196197logMessage " ${commandDescription} "
197- sudo iscsiadm --mode discovery --op update --type sendtargets --portal $iscsi1IP
198+ iscsiadm --mode discovery --op update --type sendtargets --portal $iscsi1IP
198199checkCommand " ${commandDescription} "
199- addUndoCommand " sudo iscsiadm --mode discovery --op delete --type sendtargets --portal $iscsi1IP "
200- addUndoCommand " sudo iscsiadm --mode discovery --op delete --type sendtargets --portal $iscsi2IP "
200+ addUndoCommand " iscsiadm --mode discovery --op delete --type sendtargets --portal $iscsi1IP "
201+ addUndoCommand " iscsiadm --mode discovery --op delete --type sendtargets --portal $iscsi2IP "
201202
202203logMessage " Getting target initiator"
203- targetInitiator=$( sudo iscsiadm --mode discovery --op update --type sendtargets --portal $iscsi1IP | awk ' {print $2}' | head -n 1)
204+ targetInitiator=$( iscsiadm --mode discovery --op update --type sendtargets --portal $iscsi1IP | awk ' {print $2}' | head -n 1)
204205logMessage " Target initiator is: ${targetInitiator} "
205206
206207# update the number of sessions to 8 (optional step)
207- # sudo iscsiadm --mode node -T $targetInitiator --op update -n node.session.nr_sessions -v 8
208+ # iscsiadm --mode node -T $targetInitiator --op update -n node.session.nr_sessions -v 8
208209
209210# Log into the target initiators. Your iSCSI LUNs are presented as available disks
210211logMessage " Log into target initiator: ${targetInitiator} "
211- sudo iscsiadm --mode node -T $targetInitiator --login
212- addUndoCommand " sudo iscsiadm --mode node -T $targetInitiator --logout"
212+ iscsiadm --mode node -T $targetInitiator --login
213+ addUndoCommand " iscsiadm --mode node -T $targetInitiator --logout"
213214
214215# verify that dm-multipath has identified and merged the iSCSI sessions
215- sudo multipath -ll
216+ multipath -ll
216217device_name=fsxontap
217218
218219# Add the following section to the /etc/multipath.conf file:
@@ -225,29 +226,29 @@ device_name=fsxontap
225226# Assign name to block device, this should be function that will get serial hex and device name
226227commandDescription=" Update /etc/multipath.conf file, Assign name to block device."
227228logMessage " ${commandDescription} "
228- sudo cp /etc/multipath.conf /etc/multipath.conf_backup
229+ cp /etc/multipath.conf /etc/multipath.conf_backup
229230
230231SERIAL_HEX=$serialHex
231232# ALIAS=$device_name
232233ALIAS=$VOLUME_NAME
233234CONF=/etc/multipath.conf
234- sudo chmod o+rw $CONF
235- sudo grep -q ' ^multipaths {' $CONF
235+ chmod o+rw $CONF
236+ grep -q ' ^multipaths {' $CONF
236237UNCOMMENTED=$?
237238if [ $UNCOMMENTED -eq 0 ]; then
238- sudo sed -i ' /^multipaths {/a\\tmultipath {\n\t\twwid 3600a0980' " ${SERIAL_HEX} " ' \n\t\talias ' " ${ALIAS} " ' \n\t}\n' $CONF
239+ sed -i ' /^multipaths {/a\\tmultipath {\n\t\twwid 3600a0980' " ${SERIAL_HEX} " ' \n\t\talias ' " ${ALIAS} " ' \n\t}\n' $CONF
239240else
240- sudo printf " multipaths {\n\tmultipath {\n\t\twwid 3600a0980$SERIAL_HEX \n\t\talias $ALIAS \n\t}\n}" >> $CONF
241+ printf " multipaths {\n\tmultipath {\n\t\twwid 3600a0980$SERIAL_HEX \n\t\talias $ALIAS \n\t}\n}" >> $CONF
241242fi
242243
243244fileContent=$( cat $CONF )
244245logMessage " Updated /etc/multipath.conf file content: $fileContent "
245246
246247commandDescription=" Restart the multipathd service for the changes at: /etc/multipathd.conf will take effect."
247248logMessage " ${commandDescription} "
248- sudo systemctl restart multipathd.service
249+ systemctl restart multipathd.service
249250checkCommand " ${commandDescription} "
250- addUndoCommand " sudo cp /etc/multipath.conf_backup /etc/multipath.conf"
251+ addUndoCommand " cp /etc/multipath.conf_backup /etc/multipath.conf"
251252addUndoCommand " systemctl restart multipathd.service"
252253
253254logMessage " Checking if the new partition exists."
@@ -278,25 +279,25 @@ mount_point=$VOLUME_NAME
278279
279280commandDescription=" Create a directory /${directory_path} /${mount_point} as the mount point for your file system"
280281logMessage " ${commandDescription} "
281- sudo mkdir /$directory_path /$mount_point
282+ mkdir /$directory_path /$mount_point
282283checkCommand " ${commandDescription} "
283- addUndoCommand " sudo rm -rf /$directory_path /$mount_point "
284+ addUndoCommand " rm -rf /$directory_path /$mount_point "
284285
285286# check this command
286287# volume_name=the frindly device name as we set it in the multipath.conf file
287288commandDescription=" Creating the file system for the new partition: /dev/mapper/${ALIAS} "
288289logMessage " ${commandDescription} "
289- sudo mkfs.ext4 /dev/mapper/$ALIAS
290+ mkfs.ext4 /dev/mapper/$ALIAS
290291checkCommand " ${commandDescription} "
291292
292293commandDescription=" Mount the file system using the following command."
293294logMessage " ${commandDescription} "
294- sudo mount -t ext4 /dev/mapper/$ALIAS /$directory_path /$mount_point
295+ mount -t ext4 /dev/mapper/$ALIAS /$directory_path /$mount_point
295296checkCommand " ${commandDescription} "
296- addUndoCommand " sudo umount /$directory_path /$mount_point "
297+ addUndoCommand " umount /$directory_path /$mount_point "
297298
298299username=$( whoami)
299- sudo chown $username :$username /$directory_path /$mount_point
300+ chown $username :$username /$directory_path /$mount_point
300301
301302# verify read write
302303# example: echo "test mount iscsci" > /mnt/myIscsi/testIscsi.txt
0 commit comments