xref: /illumos-gate/usr/src/lib/libdscp/svc/svc-dscp (revision d12abe7ce2663ac39e686a14960eb4febf560195)
1#!/bin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2006 Sun Microsystems, Inc.	 All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27#
28
29#
30# Start script for the SPARC-Enterprise DSCP service.
31#
32
33. /lib/svc/share/smf_include.sh
34
35OPL=SUNW,SPARC-Enterprise
36FJOPL=FJSV,SPARC-Enterprise
37TMPOPL=SUNW,OPL-Enterprise
38OPL_LIB=/usr/platform/${OPL}/lib
39DM2S_DEVICE=/dev/dm2s0
40PPP_OPTIONS=${OPL_LIB}/dscp.ppp.options
41DSCP_IFNAME=/var/run/dscp.ifname
42PRTDSCP=/usr/platform/${OPL}/sbin/prtdscp
43PLATFORM=`/sbin/uname -i`
44SLEEP=/bin/sleep
45PKILL=/bin/pkill
46
47LD_LIBRARY_PATH=/lib:${OPL_LIB}; export LD_LIBRARY_PATH
48
49# This service can only run on OPL.
50if  [ "${PLATFORM}" != "${OPL}" -a \
51      "${PLATFORM}" != "${FJOPL}" -a \
52      "${PLATFORM}" != "${TMPOPL}" ]; then
53
54	exit $SMF_EXIT_ERR_CONFIG
55fi
56
57case "$1" in
58'start')
59
60	if [ ! -x /usr/bin/pppd ]; then
61		exit $SMF_EXIT_ERR_CONFIG
62	fi
63
64	if [ ! -c $DM2S_DEVICE ]; then
65		exit $SMF_EXIT_ERR_CONFIG
66	fi
67
68	if [ ! -f $PPP_OPTIONS ]; then
69		exit $SMF_EXIT_ERR_CONFIG
70	fi
71
72	SUCCESS=0
73	for UNIT in 0 1 2 3 4 5 6 7 8 9; do
74		/usr/bin/pppd $DM2S_DEVICE unit $UNIT file $PPP_OPTIONS
75		if [ ! "$?" = "1" ]; then
76			echo "sppp$UNIT" > $DSCP_IFNAME
77			SUCCESS=1
78			break
79		fi
80	done
81
82	if [ $SUCCESS -ne 1 ]; then
83		exit $SMF_EXIT_ERR_FATAL
84	fi
85
86	# Wait for the DSCP link to come up, but only for 30 seconds
87	for RETRY in 0 1 2 3 4 5; do
88		${PRTDSCP} >/dev/null 2>&1
89		if [ $? -eq 0 ]; then
90			exit $SMF_EXIT_OK
91		fi
92		${SLEEP} 5
93	done
94
95	# Stop pppd before we return failure
96	${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
97	${SLEEP} 1
98	${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
99	rm -f $DSCP_IFNAME
100	exit $SMF_EXIT_ERR_FATAL
101	;;
102
103'stop')
104	# First try SIGTERM and then SIGKILL
105	${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
106	${SLEEP} 1
107	${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
108	rm -f $DSCP_IFNAME
109	exit $SMF_EXIT_OK
110	;;
111esac
112