-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CA-333441: Add script to update iscsi IQN and restart iscsid if needed
Signed-off-by: Mark Syms <mark.syms@citrix.com>
- Loading branch information
1 parent
227cd11
commit 1e14eb6
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright (C) Citrix Systems Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation; version 2.1 only. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
SCRIPT=$(basename $0) | ||
TMPDIR=$(mktemp --tmpdir -d $SCRIPT.XXXXXXXXX) | ||
cleanup() { | ||
if [ -n "$TMPDIR" ]; then | ||
rm -rf "$TMPDIR" | ||
fi | ||
} | ||
ecleanup() { | ||
cleanup | ||
exit 1 | ||
} | ||
trap cleanup EXIT | ||
trap ecleanup INT | ||
trap ecleanup TERM | ||
|
||
INITIATORFILE=/etc/iscsi/initiatorname.iscsi | ||
TMPFILE=$TMPDIR/initiatorname.iscsi | ||
|
||
( | ||
flock -s 200 | ||
|
||
iscsiadm -m session > /dev/null 2>&1 | ||
if [ $? -eq 0 ] | ||
then | ||
logger -p local2.err "set-iscsi-initiator active sessions so not updating" | ||
exit 1 | ||
fi | ||
|
||
echo "InitiatorName=$1" > $TMPFILE | ||
echo "InitiatorAlias=$2" >> $TMPFILE | ||
|
||
diff $INITIATORFILE $TMPFILE > /dev/null 2>&1 | ||
if [ $? -eq 0 ] | ||
then | ||
# unchanged so remove the tmp file | ||
rm $TMPFILE | ||
exit 0 | ||
fi | ||
|
||
mv $TMPFILE $INITIATORFILE | ||
|
||
systemctl is-active -q iscsid | ||
if [ $? -eq 0 ] | ||
then | ||
# iscsid is running so restart | ||
systemctl restart iscsid | ||
fi | ||
|
||
) 200>/var/lock/sm/iscsiadm/running |