~ubuntu-branches/ubuntu/hardy/open-iscsi/hardy-updates

« back to all changes in this revision

Viewing changes to etc/initd/initd.suse

  • Committer: Bazaar Package Importer
  • Author(s): Martin Zobel-Helas
  • Date: 2006-12-03 16:54:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061203165421-xhttz5j4l9sowg8u
Tags: 2.0.730-0.2
upload to unstable, as no new bugs arised.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
### END INIT INFO
16
16
 
17
17
PID_FILE=/var/run/iscsi.pid
18
 
CONFIG_FILE=/etc/iscsid.conf
 
18
CONFIG_FILE=/etc/iscsi/iscsid.conf
19
19
DAEMON=/sbin/iscsid
20
20
ISCSIADM=/sbin/iscsiadm
21
21
ARGS="-c $CONFIG_FILE -p $PID_FILE"
23
23
# Source LSB init functions
24
24
. /etc/rc.status
25
25
 
26
 
. /etc/sysconfig/open-iscsi
27
 
 
28
26
# Reset status of this service
29
27
rc_reset
30
28
 
31
 
iscsi_discovery()
32
 
{
33
 
    $ISCSIADM -m discovery --type=$ISCSI_DISCOVERY --portal=$ISCSI_PORTAL > /dev/null
34
 
}
35
 
 
36
29
iscsi_login_all_nodes()
37
30
{
38
 
    TARGETS=$($ISCSIADM -m node | sed 's@\[\(.*\)\] .*@\1@g')
39
 
    for rec in $TARGETS; do
40
 
        STARTUP=`$ISCSIADM -m node -r $rec | grep "node.conn\[0\].startup" | cut -d' ' -f3`
41
 
        NODE=`$ISCSIADM -m node -r $rec | grep "node.name" | cut -d' ' -f3`
42
 
        if [ $STARTUP = "automatic" ] ; then
43
 
            echo -n "Logging into $NODE: "
44
 
            $ISCSIADM -m node -r $rec -l
45
 
            rc_status -v
46
 
        fi
47
 
    done
 
31
        echo -n "Setting up iSCSI targets: "
 
32
        $ISCSIADM -m node --loginall=automatic
 
33
        rc_status -v
48
34
}
49
35
 
50
36
iscsi_logout_all_nodes()
51
37
{
52
 
    TARGETS=$($ISCSIADM -m session | sed 's@\[[^:]*:\(.*\)\] .*@\1@g')
53
 
    for rec in $TARGETS; do
54
 
        NODE=`$ISCSIADM -m node -r $rec | grep "node.name" | cut -d' ' -f3`
55
 
        echo -n "Logging out from $NODE: "
56
 
        if $ISCSIADM -m node --record $rec --logout ; then
57
 
            rc_status -v
 
38
        # Logout from all active sessions
 
39
        if $ISCSIADM -m node --logoutall=all ; then
 
40
                rc_status -v
58
41
        else
59
 
            RETVAL=$?
60
 
            rc_failed $RETVAL
 
42
                RETVAL=$?
 
43
                rc_failed $RETVAL
61
44
        fi
62
 
    done
63
 
    return ${RETVAL:-0}
 
45
 
 
46
        # Not sure whether this is still needed
 
47
        sleep 1
 
48
        return ${RETVAL:-0}
64
49
}
65
50
 
66
51
iscsi_list_all_nodes()
67
52
{
68
 
    TARGETS=$($ISCSIADM -m session | sed 's@\[[^:]*:\(.*\)\] .*@\1@g')
69
 
    if [ "$TARGETS" != "no active sessions" ] ; then
70
 
        echo "Active connections:"
71
 
        for rec in $TARGETS; do
72
 
            NODE=$($ISCSIADM -m node -r $rec | grep "node.name" | cut -d' ' -f3)
73
 
            echo -e "\t$NODE"
74
 
        done
 
53
    # Check for active sessions
 
54
    if $ISCSIADM -m session > /dev/null; then
 
55
        return 0
75
56
    fi
 
57
    echo "Active connections:"
 
58
    $ISCSIADM -m session | while read proto num PORTAL TARGET ; do
 
59
        PORTAL=${PORTAL%,*}
 
60
        echo -e "\t$TARGET at $PORTAL"
 
61
    done
76
62
}
77
63
 
78
64
case "$1" in
79
65
    start)
80
66
        [ ! -d /var/lib/iscsi ] && mkdir -p /var/lib/iscsi
81
 
        echo -n "Starting iSCSI initiator service: "
82
 
        modprobe scsi_transport_iscsi
83
 
        modprobe iscsi_tcp
84
 
        startproc $DAEMON $ARGS
85
 
        RETVAL=$?
86
 
        rc_status -v
 
67
        if checkproc $DAEMON ; then
 
68
            RETVAL=0
 
69
        else
 
70
            echo -n "Starting iSCSI initiator service: "
 
71
            modprobe iscsi_tcp
 
72
            modprobe ib_iser
 
73
            startproc $DAEMON $ARGS
 
74
            RETVAL=$?
 
75
            rc_status -v
 
76
        fi
87
77
        if [ "$RETVAL" == "0" ]; then
88
78
            iscsi_login_all_nodes
89
79
        fi
90
80
        ;;
91
81
    stop)
92
82
        if iscsi_logout_all_nodes ; then
93
 
            sleep 1
94
83
            killproc -KILL $DAEMON
95
84
            RETVAL=$?
96
85
        else
99
88
        echo -n "Stopping iSCSI initiator service: "
100
89
        if [ "$RETVAL" == "0" ]; then
101
90
            rm -f $PID_FILE
102
 
            rmmod iscsi_tcp
103
 
            rmmod scsi_transport_iscsi
 
91
            modprobe -r iscsi_tcp
 
92
            modprobe -r ib_iser
104
93
            rc_failed 0
105
94
        else
106
95
            rc_failed 1