xref: /illumos-gate/usr/src/lib/libdscp/svc/svc-dscp (revision e4f5a11d4a234623168c1558fcdf4341e11769e1)
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
36OPL_LIB=/usr/platform/${OPL}/lib
37DM2S_DEVICE=/dev/dm2s0
38PPP_OPTIONS=${OPL_LIB}/dscp.ppp.options
39DSCP_IFNAME=/var/run/dscp.ifname
40PRTDSCP=/usr/platform/${OPL}/sbin/prtdscp
41PLATFORM=`/sbin/uname -i`
42SLEEP=/bin/sleep
43PKILL=/bin/pkill
44
45LD_LIBRARY_PATH=/lib:${OPL_LIB}; export LD_LIBRARY_PATH
46
47# This service can only run on OPL.
48if  [ "${PLATFORM}" != "${OPL}" ]; then
49	exit $SMF_EXIT_ERR_CONFIG
50fi
51
52case "$1" in
53'start')
54
55	if [ ! -x /usr/bin/pppd ]; then
56		exit $SMF_EXIT_ERR_CONFIG
57	fi
58
59	if [ ! -c $DM2S_DEVICE ]; then
60		exit $SMF_EXIT_ERR_CONFIG
61	fi
62
63	if [ ! -f $PPP_OPTIONS ]; then
64		exit $SMF_EXIT_ERR_CONFIG
65	fi
66
67	SUCCESS=0
68	for UNIT in 0 1 2 3 4 5 6 7 8 9; do
69		/usr/bin/pppd $DM2S_DEVICE unit $UNIT file $PPP_OPTIONS
70		if [ ! "$?" = "1" ]; then
71			echo "sppp$UNIT" > $DSCP_IFNAME
72			SUCCESS=1
73			break
74		fi
75	done
76
77	if [ $SUCCESS -ne 1 ]; then
78		exit $SMF_EXIT_ERR_FATAL
79	fi
80
81	# Wait for the DSCP link to come up, but only for 30 seconds
82	for RETRY in 0 1 2 3 4 5; do
83		${PRTDSCP} >/dev/null 2>&1
84		if [ $? -eq 0 ]; then
85			exit $SMF_EXIT_OK
86		fi
87		${SLEEP} 5
88	done
89
90	# Stop pppd before we return failure
91	${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
92	${SLEEP} 1
93	${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
94	rm -f $DSCP_IFNAME
95	exit $SMF_EXIT_ERR_FATAL
96	;;
97
98'stop')
99	# First try SIGTERM and then SIGKILL
100	${PKILL} -TERM -f "pppd ${DM2S_DEVICE}"
101	${SLEEP} 1
102	${PKILL} -KILL -f "pppd ${DM2S_DEVICE}"
103	rm -f $DSCP_IFNAME
104	exit $SMF_EXIT_OK
105	;;
106esac
107