iscsid-init.d 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2015 Gentoo Foundation, Inc.
  3. # Distributed under the terms of the GNU General Public License, v2 or later
  4. command="/usr/sbin/iscsid"
  5. command_args="${OPTS}"
  6. start_stop_daemon_args="-w 100" # iscsid might fail e.g. when the iSCSI kernel modules aren't available
  7. pidfile=${PIDFILE:-/var/run/${SVCNAME}.pid}
  8. extra_started_commands="starttargets stoptargets"
  9. extra_commands="restarttargets"
  10. ISCSIADM=/usr/sbin/iscsiadm
  11. depend() {
  12. after modules multipath
  13. use net
  14. }
  15. checkconfig() {
  16. if [ ! -e /etc/conf.d/${SVCNAME} ]; then
  17. eerror "Config file /etc/conf.d/${SVCNAME} does not exist!"
  18. return 1
  19. fi
  20. if [ ! -e "${CONFIG_FILE}" ]; then
  21. eerror "Config file ${CONFIG_FILE} does not exist!"
  22. return 1
  23. fi
  24. if [ -e ${INITIATORNAME_FILE} ]; then
  25. . ${INITIATORNAME_FILE}
  26. fi
  27. if [ ! -e ${INITIATORNAME_FILE} -o -z "${InitiatorName}" ]; then
  28. ewarn "${INITIATORNAME_FILE} should contain a string with your initiatior name."
  29. local IQN=$(/usr/sbin/iscsi-iname)
  30. ebegin "Creating InitiatorName ${IQN} in ${INITIATORNAME_FILE}"
  31. echo "InitiatorName=${IQN}" >> "${INITIATORNAME_FILE}"
  32. eend $?
  33. fi
  34. }
  35. starttargets() {
  36. ebegin "Setting up iSCSI targets"
  37. $ISCSIADM -m node --loginall=automatic
  38. local ret=$?
  39. eend $ret
  40. return $ret
  41. }
  42. stoptargets() {
  43. ebegin "Disconnecting iSCSI targets"
  44. sync
  45. $ISCSIADM -m node --logoutall=all
  46. local ret=$?
  47. if [ $ret -eq 21 ]; then
  48. # See man iscsiadm(8)
  49. einfo "No active sessions to disconnect"
  50. eend 0
  51. return 0
  52. fi
  53. eend $ret
  54. return $ret
  55. }
  56. restarttargets() {
  57. stoptargets
  58. starttargets
  59. }
  60. status() {
  61. ebegin "Showing current active iSCSI sessions"
  62. $ISCSIADM -m session
  63. }
  64. start_pre() {
  65. local ret=1
  66. ebegin "Checking Open-iSCSI configuration"
  67. checkconfig
  68. ret=$?
  69. if [ $ret -ne 0 ]; then
  70. eend 1
  71. return 1
  72. fi
  73. eend 0
  74. }
  75. start_post() {
  76. # Start automatic targets when iscsid is started
  77. if [ "${AUTOSTARTTARGETS}" = "yes" ]; then
  78. starttargets
  79. local ret=$?
  80. if [ "${AUTOSTART}" = "strict" -a $ret -ne 0 ]; then
  81. stop
  82. return $ret
  83. fi
  84. fi
  85. return 0
  86. }
  87. stop_pre() {
  88. stoptargets
  89. }