1a192e900Samaguire#!/sbin/sh
2a192e900Samaguire#
3a192e900Samaguire# CDDL HEADER START
4a192e900Samaguire#
5a192e900Samaguire# The contents of this file are subject to the terms of the
6a192e900Samaguire# Common Development and Distribution License (the "License").
7a192e900Samaguire# You may not use this file except in compliance with the License.
8a192e900Samaguire#
9a192e900Samaguire# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10a192e900Samaguire# or http://www.opensolaris.org/os/licensing.
11a192e900Samaguire# See the License for the specific language governing permissions
12a192e900Samaguire# and limitations under the License.
13a192e900Samaguire#
14a192e900Samaguire# When distributing Covered Code, include this CDDL HEADER in each
15a192e900Samaguire# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16a192e900Samaguire# If applicable, add the following below this CDDL HEADER, with the
17a192e900Samaguire# fields enclosed by brackets "[]" replaced with your own identifying
18a192e900Samaguire# information: Portions Copyright [yyyy] [name of copyright owner]
19a192e900Samaguire#
20a192e900Samaguire# CDDL HEADER END
21a192e900Samaguire#
22a192e900Samaguire#
23*f4b3ec61Sdh# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24a192e900Samaguire# Use is subject to license terms.
25a192e900Samaguire#
26a192e900Samaguire# ident	"%Z%%M%	%I%	%E% SMI"
27a192e900Samaguire
28a192e900Samaguire# This script is the shared method script for the legacy ipv4/ipv6
29a192e900Samaguire# routing services.
30a192e900Samaguire
31a192e900Samaguire. /lib/svc/share/smf_include.sh
32a192e900Samaguire
33a192e900Samaguiredaemon_prog=`/usr/sbin/svccfg -s $SMF_FMRI listprop routeadm/daemon | \
34a192e900Samaguire	/usr/bin/nawk '{ for (i = 3; i <= NF; i++) printf $i" " }' | \
35a192e900Samaguire	/usr/bin/nawk '{ sub(/^\"/,""); sub(/\"[ \t]*$/,""); print }'`
36a192e900Samaguiredaemon_args=`/usr/sbin/svccfg -s $SMF_FMRI listprop routeadm/daemon-args | \
37a192e900Samaguire	/usr/bin/nawk '{ for (i = 3; i <= NF; i++) printf $i" " }' | \
38a192e900Samaguire	/usr/bin/nawk '{ sub(/^\"/,""); sub(/\"[ \t]*$/,""); print }'`
39a192e900Samaguiredaemon_stop=`/usr/sbin/svccfg -s $SMF_FMRI listprop routeadm/daemon-stop-cmd | \
40a192e900Samaguire	/usr/bin/nawk '{ for (i = 3; i <= NF; i++) printf $i" " }' | \
41a192e900Samaguire	/usr/bin/nawk '{ sub(/^\"/,""); sub(/\"[ \t]*$/,""); print }'`
42a192e900Samaguire
43a192e900Samaguiremethod="$1"
44a192e900Samaguireproto="$2"
45a192e900Samaguire
46a192e900Samaguirecase "$method" in
47a192e900Samaguire'start' )
48a192e900Samaguire	# No legacy daemon specified.
49a192e900Samaguire	if [ -z "$daemon_prog" ]; then
50a192e900Samaguire		echo "${proto}-routing-daemon not specified by routeadm."
51a192e900Samaguire		exit $SMF_EXIT_ERR_CONFIG
52a192e900Samaguire	fi
53a192e900Samaguire	# No legacy stop command specified.
54a192e900Samaguire	if [ -z "$daemon_stop" ]; then
55a192e900Samaguire		echo "${proto}-routing-stop-cmd not specified by routeadm."
56a192e900Samaguire		exit $SMF_EXIT_ERR_CONFIG
57a192e900Samaguire	fi
58*f4b3ec61Sdh	smf_configure_ip || exit $SMF_EXIT_OK
59a192e900Samaguire
60a192e900Samaguire	# Run daemon - fail if it does not successfully daemonize.
61a192e900Samaguire	eval "$daemon_prog $daemon_args"
62a192e900Samaguire	if [ "$?" != "0" ]; then
63a192e900Samaguire		echo "Error: $daemon $daemon_args failed to daemonize."
64a192e900Samaguire		exit $SMF_EXIT_ERR_FATAL
65a192e900Samaguire	fi
66a192e900Samaguire	# Create pidfile.
67a192e900Samaguire	daemon_name=`/usr/bin/basename $daemon_prog`
68*f4b3ec61Sdh	if smf_is_globalzone; then
69*f4b3ec61Sdh		/usr/bin/pgrep -P 1 -z `smf_zonename` -f $daemon_prog > \
70*f4b3ec61Sdh			/var/tmp/${daemon_name}.pid
71*f4b3ec61Sdh	else
72*f4b3ec61Sdh		/usr/bin/pgrep -z `smf_zonename` -f $daemon_prog > \
73*f4b3ec61Sdh			/var/tmp/${daemon_name}.pid
74*f4b3ec61Sdh	fi
75a192e900Samaguire	;;
76a192e900Samaguire'stop' )
77*f4b3ec61Sdh	smf_configure_ip || exit $SMF_EXIT_OK
78a192e900Samaguire
79a192e900Samaguire	# Stop daemon - ignore result.
80a192e900Samaguire	if [ -n "$daemon_stop" ]; then
81a192e900Samaguire		eval "$daemon_stop"
82a192e900Samaguire	fi
83a192e900Samaguire	;;
84a192e900Samaguire'*' )
85a192e900Samaguire	echo "Usage: $0 { start | stop }"
86a192e900Samaguire	exit $SMF_EXIT_ERR_FATAL
87a192e900Samaguire	;;
88a192e900Samaguireesac
89a192e900Samaguire
90a192e900Samaguireexit "$SMF_EXIT_OK"
91