3 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
4 # Use is subject to license terms.
6 # This file is part of Quagga.
8 # Quagga is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the
10 # Free Software Foundation; either version 2, or (at your option) any
13 # Quagga is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Quagga; see the file COPYING. If not, write to the Free
20 # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 # Starts/stops the given daemon
25 SMFINCLUDE=/lib/svc/share/smf_include.sh
26 ROUTEADMINCLUDE=/lib/svc/share/routing_include.sh
27 GLOBAL_OPTIONS="PAfiug"
32 # handle upgrade of daemon-args SMF property to new routeadm properties
33 # used during upgrade too by routeadm.
34 # relevant to S10U4+ only.
35 handle_routeadm_upgrade () {
36 GLOBAL_OPTIONS="PAfiug"
38 daemon_args=`get_daemon_args $SMF_FMRI`
40 if [ -n "$daemon_args" ]; then
41 set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
42 "$GLOBAL_OPTIONS" "P" vty_port 0
43 set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
44 "$GLOBAL_OPTIONS" "A" vty_address
45 set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
46 "$GLOBAL_OPTIONS" "f" config_file
47 set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
48 "$GLOBAL_OPTIONS" "i" pid_file
49 set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
50 "$GLOBAL_OPTIONS" "u" user
51 set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
52 "$GLOBAL_OPTIONS" "g" group
56 set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
57 "${GLOBAL_OPTIONS}b" "b" batch true false
60 set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
61 "${GLOBAL_OPTIONS}r" "r" retain true false
64 set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
65 "${GLOBAL_OPTIONS}rnp" "r" retain true false
66 set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \
67 "${GLOBAL_OPTIONS}rnp" "n" no_kernel true false
68 set_daemon_value_property "$SMF_FMRI" "$daemon_args" \
69 "${GLOBAL_OPTIONS}rnp" "p" bgp_port
71 clear_daemon_args $SMF_FMRI
77 # handle upgrade of SUNWzebra to Quagga
78 if [ -d "/etc/quagga" -a ! -f "/etc/quagga/${DAEMON}.conf" ] ; then
79 if [ -f "/etc/sfw/zebra/${DAEMON}.conf" ] ; then
80 cp "/etc/sfw/zebra/${DAEMON}.conf" \
81 "/etc/quagga/${DAEMON}.conf.upgrade" \
82 || exit $SMF_EXIT_ERR_FATAL
83 chown "${USER}:${GROUP}" "/etc/quagga/${DAEMON}.conf.upgrade" \
84 || exit $SMF_EXIT_ERR_FATAL
85 chmod 0600 "/etc/quagga/${DAEMON}.conf.upgrade" \
86 || exit $SMF_EXIT_ERR_FATAL
87 mv "/etc/quagga/${DAEMON}.conf.upgrade" "/etc/quagga/${DAEMON}.conf" \
88 || exit $SMF_EXIT_ERR_FATAL
92 if [ ! -f "/etc/quagga/${DAEMON}.conf" ] ; then
93 touch "/etc/quagga/${DAEMON}.conf.new" \
94 || exit $SMF_EXIT_ERR_FATAL
95 chown "${USER}:${GROUP}" "/etc/quagga/${DAEMON}.conf.new" \
96 || exit $SMF_EXIT_ERR_FATAL
97 chmod 0600 "/etc/quagga/${DAEMON}.conf.new" \
98 || exit $SMF_EXIT_ERR_FATAL
99 mv "/etc/quagga/${DAEMON}.conf.new" "/etc/quagga/${DAEMON}.conf" \
100 || exit $SMF_EXIT_ERR_FATAL
105 quagga_is_globalzone () {
106 if [ "${QUAGGA_INIT_ZONENAME:=`/sbin/zonename`}" = "global" \
107 -o `/sbin/zonename -t` = "exclusive" ]; then
114 routeadm_daemon_args () {
116 args="`get_daemon_option_from_property $SMF_FMRI config_file f`"
117 args="${args} `get_daemon_option_from_property $SMF_FMRI vty_port P`"
118 args="${args} `get_daemon_option_from_property $SMF_FMRI vty_address A`"
119 args="${args} `get_daemon_option_from_property $SMF_FMRI pid_file i`"
121 # user and group we need for config file upgrade..
122 SMF_USER=`get_routeadm_property $SMF_FMRI user`
123 SMF_GROUP=`get_routeadm_property()$SMF_FMRI group`
124 if [ "${SMF_USER}" ] ; then
126 args="${args} -u ${SMF_USER}"
128 if [ "${SMF_GROUP}" ] ; then
130 args="${args} -g ${SMF_GROUP}"
135 args="${args} `get_daemon_option_from_boolean_property $SMF_FMRI batch -b true`"
138 args="${args} `get_daemon_option_from_boolean_property $SMF_FMRI retain -r true`"
141 args="${args} `get_daemon_option_from_boolean_property $SMF_FMRI retain -r true`"
142 args="${args} `get_daemon_option_from_boolean_property $SMF_FMRI no_kernel -n true`"
143 args="${args} `get_daemon_option_from_property $SMF_FMRI bgp_port p 179`"
149 # certain daemons need zebra
150 routeadm_zebra_enable () {
152 if [ "$DAEMON" = "zebra" ]; then
156 enable_zebra=`/usr/bin/svcprop -p \
157 routing/enable_zebra $SMF_FMRI 2> /dev/null`
158 if [ "$enable_zebra" != "false" ]; then
159 zenabled=`/usr/bin/svcprop -p general/enabled zebra:quagga`
160 zenabledt=`/usr/bin/svcprop -p general_ovr/enabled zebra:quagga`
161 if [ "$zenabled" = "true" -o "$zenabledt" = "true" ]; then
162 /usr/sbin/svcadm disable zebra:quagga
163 /usr/sbin/svcadm enable -st zebra:quagga
165 /usr/sbin/svcadm enable -st zebra:quagga
167 if [ "$?" != "0" ]; then
168 echo "Could not enable zebra:quagga"
169 exit $SMF_EXIT_ERR_FATAL
174 # Include smf functions, if available. If not, define smf_present to indicate
175 # there is no SMF. Should allow this script to work pre-S10.
176 if [ -f "$SMFINCLUDE" ] ; then
179 # source the SMF-routeadm include if present..
180 if [ -f "$ROUTEADMINCLUDE" ] ; then
184 # pre-SMF system, fake up any functions and exit codes
185 # which SMFINCLUDE usually provides.
190 SMF_EXIT_ERR_CONFIG=96;
191 SMF_EXIT_ERR_FATAL=95;
194 # if there's no SMF, set some default DAEMON_ARGS
195 smf_present || DAEMON_ARGS=""
198 if smf_present ; then
199 echo "Usage: $0 <daemon>";
201 echo "Usage: $0 <stop|start> <daemon> <daemon arguments>";
203 echo "The --pid_file argument is implied";
204 echo "This help message: $0 <help|usage>";
207 # parse arguments, different according to SMF or not.
215 if smf_present ; then
216 QUAGGA_METHOD="start"
224 # daemon path must be given
225 if [ -z "$DAEMON_PATH/$DAEMON" ]; then
227 exit $SMF_EXIT_ERR_FATAL
230 # only bgpd is suitable for running in a non-global zone, at this
235 zebra | ospfd | ospf6d | ripd | ripngd )
236 quagga_is_globalzone || exit $SMF_EXIT_OK
240 exit $SMF_EXIT_ERR_CONFIG;
244 # Older Quagga SMF packages pass daemon args on the commandline
245 # Newer SMF routeadm model uses properties for each argument
246 # so we must handle that.
247 if [ smf_present -a -f "$ROUTEADMINCLUDE" ]; then
248 handle_routeadm_upgrade $DAEMON;
249 DAEMON_ARGS=`routeadm_daemon_args`;
250 routeadm_zebra_enable $DAEMON;
252 if [ $# -gt 0 ] ; then
258 upgrade_config "$DAEMON"
260 if [ ! -f "@sysconfdir@/${DAEMON}.conf" ] ; then
261 echo "Could not find config file, @sysconfdir@/${DAEMON}.conf"
262 exit $SMF_EXIT_ERR_CONFIG
265 # we need @quagga_statedir@ to exist, it probably is on tmpfs.
266 if [ ! -d @quagga_statedir@ ] ; then
267 mkdir -p @quagga_statedir@
268 chown @enable_user@:@enable_group@ @quagga_statedir@
269 chmod 751 @quagga_statedir@
272 PIDFILE="@quagga_statedir@/${DAEMON}.pid"
275 if [ ! -x "$DAEMON_PATH/$DAEMON" ] ; then
276 echo "Error, could not find daemon, $DAEMON_PATH/$DAEMON"
277 exit $SMF_EXIT_ERR_FATAL
279 eval exec $DAEMON_PATH/$DAEMON $DAEMON_ARGS --pid_file ${PIDFILE} &
283 if [ -f "${PIDFILE}" ]; then
284 /usr/bin/kill -TERM `/usr/bin/cat "${PIDFILE}"`
288 case "$QUAGGA_METHOD" in
298 exit $SMF_EXIT_ERR_FATAL