summaryrefslogtreecommitdiff
path: root/solaris/quagga.init.in
blob: 30a9c6943fb6ae7c5c9e5fb49deb0b3d724144b1 (plain)
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
#!/sbin/sh
#
# Copyright 2001,2003 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# This file is part of Quagga.
#
# Quagga is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
#
# Quagga is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Quagga; see the file COPYING.  If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
# $Id$
#
# Starts/stops the given daemon

SMFINCLUDE=/lib/svc/share/smf_include.sh
DAEMON_PATH=@sbindir@

quagga_is_globalzone () {
	if [ "${QUAGGA_INIT_ZONENAME:=`/sbin/zonename`}" != "global" ]; then
		return 1
	else
		return 0
	fi
}

# Include smf functions, if available. If not, define smf_present to indicate
# there is no SMF. Should allow this script to work pre-S10.
if [ -f "$SMFINCLUDE" ] ; then
	. "$SMFINCLUDE";
else
	# pre-SMF system, fake up any functions and exit codes
	# which SMFINCLUDE usually provides.
	smf_present () {
		return 1
	}
	SMF_EXIT_OK=0;
	SMF_EXIT_ERR_CONFIG=96;
	SMF_EXIT_ERR_FATAL=95;
fi
	
# if there's no SMF, set some default DAEMON_ARGS
smf_present || DAEMON_ARGS=""

usage () {
	if smf_present ; then
		echo "Usage: $0 <daemon> <daemon arguments>";
	else
		echo "Usage: $0 <stop|start> <daemon> <daemon arguments>";
	fi
	echo "The --pid_file argument is implied";
	echo "This help message: $0 <help|usage>";
}

# parse arguments, different according to SMF or not.
case $1 in
	'help' | 'usage')
		usage
		exit SMF_EXIT_OK
		;;
esac

if smf_present ; then
	QUAGGA_METHOD="start"
else
	QUAGGA_METHOD="$1"
	shift;
fi

DAEMON="$1"
shift
DAEMON_ARGS="$@"

# daemon path must be given
if [ -z "$DAEMON_PATH/$DAEMON" ]; then
	usage
	exit $SMF_EXIT_ERR_FATAL
fi

# only bgpd is suitable for running in a non-global zone, at this
# time.
case "${DAEMON}" in
	zebra)
		quagga_is_globalzone || exit $SMF_EXIT_OK
	;;
	bgpd)
	;;
	ospfd | ospf6d | ripd | ripngd )
		quagga_is_globalzone || exit $SMF_EXIT_OK
	;;
	*)
		usage
		exit $SMF_EXIT_ERR_CONFIG;
	;;
esac

# we need @quagga_statedir@ to exist, it probably is on tmpfs.
if [ ! -d @quagga_statedir@ ] ; then
	mkdir -p @quagga_statedir@
	chown @enable_user@:@enable_group@ @quagga_statedir@
	chmod 751 @quagga_statedir@
fi

PIDFILE="@quagga_statedir@/${DAEMON}.pid"

start () {
	$DAEMON_PATH/$DAEMON $DAEMON_ARGS --pid_file ${PIDFILE} &
}

stop () {
	if [ -f "${PIDFILE}" ]; then
		/usr/bin/kill -TERM `/usr/bin/cat "${PIDFILE}"`
	fi
}

case "$QUAGGA_METHOD" in
'start')
	start
	;;
'stop')
	stop
	;;

*)
	usage
	exit SMF_EXIT_ERR_FATAL
	;;
esac	

exit $SMF_EXIT_OK;