rc.open-iscsi 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. # Slackware rc.open-iscsi script, derived from init.debian in the
  3. # open-iscsi source package.
  4. DAEMON=/sbin/iscsid
  5. ADM=/sbin/iscsiadm
  6. PIDFILE=/var/run/iscsid.pid
  7. [ -e /etc/default/open-iscsi ] && . /etc/default/open-iscsi
  8. [ -x "$DAEMON" ] || exit 0
  9. if [ ! -d /sys/class/ ]
  10. then
  11. echo "iSCSI requires a mounted sysfs, not started." >&2
  12. exit 1
  13. fi
  14. start() {
  15. echo "Starting iSCSI initiator service" "iscsid"
  16. modprobe -q iscsi_tcp 2>/dev/null || :
  17. modprobe -q ib_iser 2>/dev/null || :
  18. $DAEMON $ARGS
  19. sleep 1
  20. starttargets
  21. }
  22. starttargets() {
  23. echo "Setting up iSCSI targets"
  24. $ADM -m node --loginall=automatic
  25. }
  26. stoptargets() {
  27. echo "Disconnecting iSCSI targets"
  28. sync
  29. $ADM -m node --logoutall=all
  30. }
  31. stop() {
  32. stoptargets
  33. sleep 1
  34. echo "Stopping iSCSI initiator service"
  35. pkill -F $PIDFILE
  36. rm -f $PIDFILE
  37. modprobe -r iscsi_tcp
  38. modprobe -r ib_iser
  39. }
  40. restart() {
  41. stop
  42. sleep 1
  43. start
  44. }
  45. restarttargets() {
  46. stoptargets
  47. starttargets
  48. }
  49. status() {
  50. echo "$(pgrep -c -F $PIDFILE -f $DAEMON) $DAEMON process(es) running"
  51. echo "Current active iSCSI sessions:"
  52. $ADM -m session
  53. }
  54. case "$1" in
  55. start|starttargets|stop|stoptargets|restart|restarttargets|status)
  56. $1
  57. ;;
  58. *)
  59. echo "Usage: $0 {start|stop|restart|status}"
  60. exit 1
  61. ;;
  62. esac