File: srpd.in

package info (click to toggle)
rdma-core 33.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,844 kB
  • sloc: ansic: 145,804; python: 5,688; sh: 2,761; perl: 1,465; makefile: 73
file content (163 lines) | stat: -rwxr-xr-x 3,532 bytes parent folder | download | duplicates (6)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md
#
# Manage the SRP client daemon (srp_daemon)
#
# chkconfig: - 25 75
# description: Starts/Stops InfiniBand SRP client service
# config:	@CMAKE_INSTALL_FULL_SYSCONFDIR@/srp_daemon.conf
#
### BEGIN INIT INFO
# Provides:       srpd
# Required-Start: $syslog @RDMA_SERVICE@
# Required-Stop: $syslog @RDMA_SERVICE@
# Default-Start: @SRP_DEFAULT_START@
# Default-Stop: @SRP_DEFAULT_STOP@
# Should-Start:
# Should-Stop:
# Short-Description: Starts and stops the InfiniBand SRP client service
# Description: The InfiniBand SRP client service attaches to SRP devices
#	on the InfiniBand fabric and makes them appear as local disks to
#	to the system.  This service starts the client daemon that's
#	responsible for initiating and maintaining the connections to
#	remote devices.
### END INIT INFO

if [ -e /etc/rdma/rdma.conf ]; then
    # RHEL / Fedora.
    RDMA_CONFIG=/etc/rdma/rdma.conf
else
    # OFED
    RDMA_CONFIG=/etc/infiniband/openib.conf
fi
if [ -f $RDMA_CONFIG ]; then
    . $RDMA_CONFIG
fi
pidfile=@CMAKE_INSTALL_FULL_RUNDIR@/srp_daemon.sh.pid
prog=@CMAKE_INSTALL_FULL_SBINDIR@/srp_daemon.sh

checkpid() {
    [ -e "/proc/$1" ]
}

stop_srp_daemon() {
    if ! running; then
        return 1
    fi

    local pid=`cat $pidfile`
    kill $pid
    # timeout 30 seconds for termination
    for i in `seq 300`; do
        if ! checkpid $pid; then
            return 0
        fi
        sleep 0.1
    done
    kill -9 $pid
    # If srp_daemon executables didn't finish by now
    # force kill
    pkill -9 srp_daemon

    return 0
}

# if the ib_srp module is loaded or built into the kernel return 0 otherwise
# return 1.
is_srp_mod_loaded() {
    [ -e /sys/module/ib_srp ]
}

running() {
    [ -f $pidfile ] && checkpid "$(cat $pidfile)"
}

start() {
    if ! is_srp_mod_loaded; then
	echo "SRP kernel module is not loaded, unable to start SRP daemon"
	return 6
    fi
    if running; then
	echo "Already started"
	return 0
    fi

    echo -n "Starting SRP daemon service"

    if [ "$SRP_DEFAULT_TL_RETRY_COUNT" ]; then
        params=$params"-l $SRP_DEFAULT_TL_RETRY_COUNT "
    fi

    setsid $prog $params </dev/null >&/dev/null &
    RC=$?
    [ $RC -eq 0 ] && echo || echo " ...failed"
    return $RC
}

stop() {
    echo -n "Stopping SRP daemon service"

    stop_srp_daemon
    RC=$?
    for ((i=0;i<5;i++)); do
	if ! running; then
	    rm -f $pidfile
	    break
	fi
	sleep 1
    done
    [ $RC -eq 0 ] && echo || echo " ...failed"
    return $RC
}

status() {
    local ret

    if [ ! -f $pidfile ]; then
	ret=3 # program not running
    else
	checkpid "$(cat $pidfile)"
	ret=$? # 1: pid file exists and not running / 0: running
    fi
    if [ $ret -eq 0 ] ; then
	echo "$prog is running... pid=$(cat $pidfile)"
    else
	echo "$prog is not running."
    fi
    return $ret
}

restart() {
    stop
    start
}

condrestart() {
    [ -f $pidfile ] && restart || return 0
}

usage() {
    echo
    echo "Usage: `basename $0` {start|stop|restart|condrestart|try-restart|force-reload|status}"
    echo
    return 2
}

case $1 in
    start|stop|restart|condrestart|try-restart|force-reload)
	[ `id -u` != "0" ] && exit 4 ;;
esac

case $1 in
    start) start; RC=$? ;;
    stop) stop; RC=$? ;;
    restart) restart; RC=$? ;;
    reload) RC=3 ;;
    condrestart) condrestart; RC=$? ;;
    try-restart) condrestart; RC=$? ;;
    force-reload) condrestart; RC=$? ;;
    status) status; RC=$? ;;
    *) usage; RC=$? ;;
esac

exit $RC