blob: 30a9c6943fb6ae7c5c9e5fb49deb0b3d724144b1 [file] [log] [blame]
paul1b414a12005-04-11 07:05:21 +00001#!/sbin/sh
2#
Paul Jakma75db03e2006-03-30 13:38:28 +00003# Copyright 2001,2003 Sun Microsystems, Inc. All rights reserved.
paul1b414a12005-04-11 07:05:21 +00004# Use is subject to license terms.
5#
Paul Jakmadef09df2007-02-22 17:55:20 +00006# This file is part of Quagga.
7#
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
11# later version.
12#
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.
17#
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
21# 02111-1307, USA.
22#
23# $Id$
paul1b414a12005-04-11 07:05:21 +000024#
Paul Jakma75db03e2006-03-30 13:38:28 +000025# Starts/stops the given daemon
paul1b414a12005-04-11 07:05:21 +000026
27SMFINCLUDE=/lib/svc/share/smf_include.sh
Paul Jakma75db03e2006-03-30 13:38:28 +000028DAEMON_PATH=@sbindir@
paul1b414a12005-04-11 07:05:21 +000029
Paul Jakma75db03e2006-03-30 13:38:28 +000030quagga_is_globalzone () {
31 if [ "${QUAGGA_INIT_ZONENAME:=`/sbin/zonename`}" != "global" ]; then
32 return 1
33 else
34 return 0
35 fi
36}
37
38# Include smf functions, if available. If not, define smf_present to indicate
39# there is no SMF. Should allow this script to work pre-S10.
paul1b414a12005-04-11 07:05:21 +000040if [ -f "$SMFINCLUDE" ] ; then
41 . "$SMFINCLUDE";
Paul Jakma75db03e2006-03-30 13:38:28 +000042else
43 # pre-SMF system, fake up any functions and exit codes
44 # which SMFINCLUDE usually provides.
45 smf_present () {
46 return 1
47 }
48 SMF_EXIT_OK=0;
49 SMF_EXIT_ERR_CONFIG=96;
50 SMF_EXIT_ERR_FATAL=95;
paul1b414a12005-04-11 07:05:21 +000051fi
Paul Jakma75db03e2006-03-30 13:38:28 +000052
53# if there's no SMF, set some default DAEMON_ARGS
54smf_present || DAEMON_ARGS=""
paul1b414a12005-04-11 07:05:21 +000055
56usage () {
Paul Jakma75db03e2006-03-30 13:38:28 +000057 if smf_present ; then
58 echo "Usage: $0 <daemon> <daemon arguments>";
59 else
60 echo "Usage: $0 <stop|start> <daemon> <daemon arguments>";
61 fi
62 echo "The --pid_file argument is implied";
63 echo "This help message: $0 <help|usage>";
64}
paul1b414a12005-04-11 07:05:21 +000065
Paul Jakma75db03e2006-03-30 13:38:28 +000066# parse arguments, different according to SMF or not.
paul1b414a12005-04-11 07:05:21 +000067case $1 in
68 'help' | 'usage')
Paul Jakma75db03e2006-03-30 13:38:28 +000069 usage
70 exit SMF_EXIT_OK
71 ;;
paul1b414a12005-04-11 07:05:21 +000072esac
73
Paul Jakma75db03e2006-03-30 13:38:28 +000074if smf_present ; then
75 QUAGGA_METHOD="start"
76else
77 QUAGGA_METHOD="$1"
78 shift;
paul1b414a12005-04-11 07:05:21 +000079fi
80
Paul Jakma75db03e2006-03-30 13:38:28 +000081DAEMON="$1"
82shift
83DAEMON_ARGS="$@"
paul1b414a12005-04-11 07:05:21 +000084
Paul Jakma75db03e2006-03-30 13:38:28 +000085# daemon path must be given
86if [ -z "$DAEMON_PATH/$DAEMON" ]; then
87 usage
88 exit $SMF_EXIT_ERR_FATAL
89fi
90
91# only bgpd is suitable for running in a non-global zone, at this
92# time.
93case "${DAEMON}" in
94 zebra)
95 quagga_is_globalzone || exit $SMF_EXIT_OK
96 ;;
97 bgpd)
Paul Jakmae24f0632006-02-19 18:59:26 +000098 ;;
99 ospfd | ospf6d | ripd | ripngd )
Paul Jakma75db03e2006-03-30 13:38:28 +0000100 quagga_is_globalzone || exit $SMF_EXIT_OK
paul1b414a12005-04-11 07:05:21 +0000101 ;;
102 *)
Paul Jakma75db03e2006-03-30 13:38:28 +0000103 usage
104 exit $SMF_EXIT_ERR_CONFIG;
paul1b414a12005-04-11 07:05:21 +0000105 ;;
106esac
107
Paul Jakma75db03e2006-03-30 13:38:28 +0000108# we need @quagga_statedir@ to exist, it probably is on tmpfs.
paul9b78d052005-06-15 11:00:11 +0000109if [ ! -d @quagga_statedir@ ] ; then
110 mkdir -p @quagga_statedir@
111 chown @enable_user@:@enable_group@ @quagga_statedir@
112 chmod 751 @quagga_statedir@
113fi
114
Paul Jakma75db03e2006-03-30 13:38:28 +0000115PIDFILE="@quagga_statedir@/${DAEMON}.pid"
116
paul1b414a12005-04-11 07:05:21 +0000117start () {
Paul Jakma75db03e2006-03-30 13:38:28 +0000118 $DAEMON_PATH/$DAEMON $DAEMON_ARGS --pid_file ${PIDFILE} &
paul1b414a12005-04-11 07:05:21 +0000119}
120
121stop () {
122 if [ -f "${PIDFILE}" ]; then
123 /usr/bin/kill -TERM `/usr/bin/cat "${PIDFILE}"`
124 fi
125}
126
Paul Jakma75db03e2006-03-30 13:38:28 +0000127case "$QUAGGA_METHOD" in
paul1b414a12005-04-11 07:05:21 +0000128'start')
Paul Jakma75db03e2006-03-30 13:38:28 +0000129 start
paul1b414a12005-04-11 07:05:21 +0000130 ;;
131'stop')
Paul Jakma75db03e2006-03-30 13:38:28 +0000132 stop
paul1b414a12005-04-11 07:05:21 +0000133 ;;
134
paul1b414a12005-04-11 07:05:21 +0000135*)
136 usage
Paul Jakma75db03e2006-03-30 13:38:28 +0000137 exit SMF_EXIT_ERR_FATAL
paul1b414a12005-04-11 07:05:21 +0000138 ;;
139esac
140
141exit $SMF_EXIT_OK;