startup-checks.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. #
  3. # This script does the required startup checks before the iSCSI
  4. # daemon should be started. It also generates a name if that
  5. # hadn't been done before.
  6. #
  7. PATH=/sbin:/bin
  8. NAMEFILE=/etc/iscsi/initiatorname.iscsi
  9. CONFIGFILE=/etc/iscsi/iscsid.conf
  10. if [ ! -e "$CONFIGFILE" ]; then
  11. echo >&2
  12. echo "Error: configuration file $CONFIGFILE is missing!" >&2
  13. echo "The iSCSI driver has not been correctly installed and cannot start." >&2
  14. echo >&2
  15. exit 1
  16. fi
  17. if [ ! -f $NAMEFILE ]; then
  18. echo >&2
  19. echo "Error: InitiatorName file $NAMEFILE is missing!" >&2
  20. echo "The iSCSI driver has not been correctly installed and cannot start." >&2
  21. echo >&2
  22. exit 1
  23. fi
  24. # see if we need to generate a unique iSCSI InitiatorName
  25. if grep -q "^GenerateName=yes" $NAMEFILE ; then
  26. if [ ! -x /sbin/iscsi-iname ] ; then
  27. echo "Error: /sbin/iscsi-iname does not exist, driver was not successfully installed" >&2
  28. exit 1
  29. fi
  30. # Generate a unique InitiatorName and save it
  31. INAME=`/sbin/iscsi-iname -p iqn.1993-08.org.debian:01`
  32. if [ "$INAME" != "" ] ; then
  33. echo "## DO NOT EDIT OR REMOVE THIS FILE!" > $NAMEFILE
  34. echo "## If you remove this file, the iSCSI daemon will not start." >> $NAMEFILE
  35. echo "## If you change the InitiatorName, existing access control lists" >> $NAMEFILE
  36. echo "## may reject this initiator. The InitiatorName must be unique">> $NAMEFILE
  37. echo "## for each iSCSI initiator. Do NOT duplicate iSCSI InitiatorNames." >> $NAMEFILE
  38. printf "InitiatorName=$INAME\n" >> $NAMEFILE
  39. chmod 600 $NAMEFILE
  40. else
  41. echo "Error: failed to generate an iSCSI InitiatorName, driver cannot start." >&2
  42. echo >&2
  43. exit 1
  44. fi
  45. fi
  46. # make sure there is a valid InitiatorName for the driver
  47. if ! grep -q "^InitiatorName=[^ \t\n]" $NAMEFILE ; then
  48. echo >&2
  49. echo "Error: $NAMEFILE does not contain a valid InitiatorName." >&2
  50. echo "The iSCSI driver has not been correctly installed and cannot start." >&2
  51. echo >&2
  52. exit 1
  53. fi