File: redhat-opensm.init.in

package info (click to toggle)
opensm 3.3.23-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,932 kB
  • sloc: ansic: 97,383; yacc: 2,227; sh: 685; lex: 404; makefile: 391; perl: 143
file content (297 lines) | stat: -rwxr-xr-x 6,656 bytes parent folder | download | duplicates (5)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/bin/bash
#
# Bring up/down opensm
#
# chkconfig: - 15 85
# description: Activates/Deactivates InfiniBand Subnet Manager
#
### BEGIN INIT INFO
# Provides:       opensm
# Required-Start: $syslog @RDMA_SERVICE@
# Required-Stop: $syslog @RDMA_SERVICE@
# Default-Start: @DEFAULT_START@
# Default-Stop: @DEFAULT_STOP@
# Description:  Manage OpenSM
### END INIT INFO
#
# Copyright (c) 2008 Voltaire, Inc. All rights reserved.
# Copyright (c) 2006 Mellanox Technologies. All rights reserved.
#
# This Software is licensed under one of the following licenses:
#
# 1) under the terms of the "Common Public License 1.0" a copy of which is
#    available from the Open Source Initiative, see
#    http://www.opensource.org/licenses/cpl.php.
#
# 2) under the terms of the "The BSD License" a copy of which is
#    available from the Open Source Initiative, see
#    http://www.opensource.org/licenses/bsd-license.php.
#
# 3) under the terms of the "GNU General Public License (GPL) Version 2" a
#    copy of which is available from the Open Source Initiative, see
#    http://www.opensource.org/licenses/gpl-license.php.
#
# Licensee has the right to choose one of the above licenses.
#
# Redistributions of source code must retain the above copyright
# notice and one of the license notices.
#
# Redistributions in binary form must reproduce both the above copyright
# notice, one of the license notices in the documentation
# and/or other materials provided with the distribution.
#
#
#  $Id: openib-1.0-opensm.init,v 1.5 2006/08/02 18:18:23 dledford Exp $
#
# processname: @sbindir@/opensm
# config: @sysconfdir@/sysconfig/opensm
# pidfile: /var/run/opensm.pid

prefix=@prefix@
exec_prefix=@exec_prefix@

. /etc/rc.d/init.d/functions

CONFIG=@sysconfdir@/sysconfig/opensm
if [ -f $CONFIG ]; then
    . $CONFIG
fi

prog=@sbindir@/opensm
bin=${prog##*/}

# Handover daemon for updating guid2lid cache file
sldd_prog=@sbindir@/sldd.sh
sldd_bin=${sldd_prog##*/}
sldd_pid_file=/var/run/sldd.pid

ACTION=$1

# Setting OpenSM start parameters
PID_FILE=/var/run/${bin}.pid
touch $PID_FILE

if [[ -n "${OSM_HOSTS}" && $(echo -n ${OSM_HOSTS} | wc -w | tr -d '[:space:]') -gt 1  ]]; then
    HONORE_GUID2LID="--honor_guid2lid"
fi

#########################################################################

start_sldd()
{
    if [ -f $sldd_pid_file ]; then
            local line p
            read line < $sldd_pid_file
            for p in $line ; do
                    [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && sldd_pid="$sldd_pid $p"
            done
    fi

    if [ -z "$sldd_pid" ]; then
        sldd_pid=`pidof -x $sldd_bin`
    fi

    if [ -n "${sldd_pid:-}" ] ; then
	kill -9 ${sldd_pid} > /dev/null 2>&1
    fi

    $sldd_prog > /dev/null 2>&1 &
    sldd_pid=$!

    echo ${sldd_pid} > $sldd_pid_file
    # Sleep is needed in order to update local gid2lid cache file before running opensm
    sleep 3
}

stop_sldd()
{
    if [ -f $sldd_pid_file ]; then
            local line p
            read line < $sldd_pid_file
            for p in $line ; do
                    [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && sldd_pid="$sldd_pid $p"
            done
    fi

    if [ -z "$sldd_pid" ]; then
        sldd_pid=`pidof -x $sldd_bin`
    fi

    if [ -n "${sldd_pid:-}" ] ; then
        kill -15 ${sldd_pid} > /dev/null 2>&1
    fi

}

start()
{
    local OSM_PID=

    pid=""

    if [ -f $PID_FILE ]; then
            local line p
            read line < $PID_FILE
            for p in $line ; do
                    [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
            done
    fi

    if [ -z "$pid" ]; then
        pid=`pidof -o $$ -o $PPID -o %PPID -x $bin`
    fi

    if [ -n "${pid:-}" ] ; then
        echo $"${bin} (pid $pid) is already running..."
    else

	if [ -n "${HONORE_GUID2LID}" ]; then
		# Run sldd daemod
		start_sldd
	fi

        # Start opensm
	echo -n "Starting IB Subnet Manager"
        $prog --daemon ${HONORE_GUID2LID} ${OPTIONS} > /dev/null
        cnt=0; alive=0
        while [ $cnt -lt 6 -a $alive -ne 1 ]; do
		echo -n ".";
		sleep 1
		alive=0
                OSM_PID=`pidof $prog`
                if [ "$OSM_PID" != "" ]; then
                        alive=1
                fi
		let cnt++;
	done

        echo $OSM_PID > $PID_FILE
        checkpid $OSM_PID
        RC=$?
        [ $RC -eq 0 ] && echo_success || echo_failure
        [ $RC -eq 0 ] && touch /var/lock/subsys/opensm
	echo

    fi
return $RC
}

stop()
{
    local pid=
    local pid1=
    local pid2=

    # Stop sldd daemon
    stop_sldd

    if [ -f $PID_FILE ]; then
            local line p
            read line < $PID_FILE
            for p in $line ; do
                    [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid1="$pid1 $p"
            done
    fi

    pid2=`pidof -o $$ -o $PPID -o %PPID -x $bin`

    pid=`echo "$pid1 $pid2" | sed -e 's/\ /\n/g' | sort -n | uniq | sed -e 's/\n/\ /g'`

    if [ -n "${pid:-}" ] ; then
        # Kill opensm
	echo -n "Stopping IB Subnet Manager."
        kill -15 $pid > /dev/null 2>&1
		cnt=0; alive=1
        while [ $cnt -lt 6 -a $alive -ne 0 ]; do
		echo -n ".";
		alive=0
		for p in $pid; do
			if checkpid $p ; then alive=1; echo -n "-"; fi
		done
		let cnt++;
		sleep $alive
	done

        for p in $pid
        do
            while checkpid $p ; do
                kill -KILL $p > /dev/null 2>&1
                echo -n "+"
                sleep 1
            done
        done
        checkpid $pid
        RC=$?
        [ $RC -eq 0 ] && echo_failure || echo_success
	echo
        RC=$((! $RC))
    else
	echo -n "Stopping IB Subnet Manager."
        echo_failure
	echo
        RC=1
    fi

    # Remove pid file if any.
    rm -f $PID_FILE
    rm -f /var/lock/subsys/opensm
    return $RC
}

status()
{
    local pid

    # First try "pidof"
    pid=`pidof -o $$ -o $PPID -o %PPID -x ${bin}`
    if [ -n "$pid" ]; then
            echo $"${bin} (pid $pid) is running..."
            return 0
    fi

     # Next try "/var/run/opensm.pid" files
     if [ -f $PID_FILE ] ; then
             read pid < $PID_FILE
             if [ -n "$pid" ]; then
                     echo $"${bin} dead but pid file $PID_FILE exists"
                     return 1
             fi
     fi
     echo $"${bin} is stopped"
     return 3
}



case $ACTION in
	start)
                start
		;;
	stop)
		stop
		;;
	restart)
		stop
                start
		;;
	status)
		status
		;;
	condrestart)
		pid=`pidof -o $$ -o $PPID -o %PPID -x $bin`
		if [ -n "$pid" ]; then
			stop
			sleep 1
			start
		fi
		;;
	*)
		echo
		echo "Usage: `basename $0` {start|stop|restart|status}"
		echo
		exit 1
		;;
esac

RC=$?
exit $RC