aboutsummaryrefslogtreecommitdiff
path: root/network/open-iscsi/rc.open-iscsi
blob: 5b18f60d2d8a41a759dfc26448024dba43114526 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh

# Slackware rc.open-iscsi script, derived from init.debian in the
# open-iscsi source package.

DAEMON=/sbin/iscsid
ADM=/sbin/iscsiadm
PIDFILE=/var/run/iscsid.pid

[ -e /etc/default/open-iscsi ] && . /etc/default/open-iscsi 

[ -x "$DAEMON" ] || exit 0

if [ ! -d /sys/class/ ]
then
    echo "iSCSI requires a mounted sysfs, not started." >&2
    exit 1
fi

start() {
    echo "Starting iSCSI initiator service" "iscsid"
    modprobe -q iscsi_tcp 2>/dev/null || :
    modprobe -q ib_iser 2>/dev/null || :
    $DAEMON $ARGS
    sleep 1
    starttargets
}

starttargets() {
    echo "Setting up iSCSI targets"
    $ADM -m node --loginall=automatic
}

stoptargets() {
    echo "Disconnecting iSCSI targets"
    sync
    $ADM -m node --logoutall=all
}

stop() {
    stoptargets
    sleep 1
    echo "Stopping iSCSI initiator service"
    pkill -F $PIDFILE
    rm -f $PIDFILE

    modprobe -r iscsi_tcp
    modprobe -r ib_iser
}

restart() {
    stop
    sleep 1
    start
}

restarttargets() {
    stoptargets
    starttargets
}

status() {
    echo "$(pgrep -c -F $PIDFILE -f $DAEMON) $DAEMON process(es) running"
    echo "Current active iSCSI sessions:"
    $ADM -m session
}

case "$1" in
    start|starttargets|stop|stoptargets|restart|restarttargets|status)
        $1
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac