blob: 9fc2fe744c479546710280241bff43dc87cac36b [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 Jakma75db03e2006-03-30 13:38:28 +00006# $Id: quagga.init.in,v 1.6 2006/03/30 13:38:28 paul Exp $
paul1b414a12005-04-11 07:05:21 +00007#
Paul Jakma75db03e2006-03-30 13:38:28 +00008# Starts/stops the given daemon
paul1b414a12005-04-11 07:05:21 +00009
10SMFINCLUDE=/lib/svc/share/smf_include.sh
Paul Jakma75db03e2006-03-30 13:38:28 +000011DAEMON_PATH=@sbindir@
paul1b414a12005-04-11 07:05:21 +000012
Paul Jakma75db03e2006-03-30 13:38:28 +000013quagga_is_globalzone () {
14 if [ "${QUAGGA_INIT_ZONENAME:=`/sbin/zonename`}" != "global" ]; then
15 return 1
16 else
17 return 0
18 fi
19}
20
21# Include smf functions, if available. If not, define smf_present to indicate
22# there is no SMF. Should allow this script to work pre-S10.
paul1b414a12005-04-11 07:05:21 +000023if [ -f "$SMFINCLUDE" ] ; then
24 . "$SMFINCLUDE";
Paul Jakma75db03e2006-03-30 13:38:28 +000025else
26 # pre-SMF system, fake up any functions and exit codes
27 # which SMFINCLUDE usually provides.
28 smf_present () {
29 return 1
30 }
31 SMF_EXIT_OK=0;
32 SMF_EXIT_ERR_CONFIG=96;
33 SMF_EXIT_ERR_FATAL=95;
paul1b414a12005-04-11 07:05:21 +000034fi
Paul Jakma75db03e2006-03-30 13:38:28 +000035
36# if there's no SMF, set some default DAEMON_ARGS
37smf_present || DAEMON_ARGS=""
paul1b414a12005-04-11 07:05:21 +000038
39usage () {
Paul Jakma75db03e2006-03-30 13:38:28 +000040 if smf_present ; then
41 echo "Usage: $0 <daemon> <daemon arguments>";
42 else
43 echo "Usage: $0 <stop|start> <daemon> <daemon arguments>";
44 fi
45 echo "The --pid_file argument is implied";
46 echo "This help message: $0 <help|usage>";
47}
paul1b414a12005-04-11 07:05:21 +000048
Paul Jakma75db03e2006-03-30 13:38:28 +000049# parse arguments, different according to SMF or not.
paul1b414a12005-04-11 07:05:21 +000050case $1 in
51 'help' | 'usage')
Paul Jakma75db03e2006-03-30 13:38:28 +000052 usage
53 exit SMF_EXIT_OK
54 ;;
paul1b414a12005-04-11 07:05:21 +000055esac
56
Paul Jakma75db03e2006-03-30 13:38:28 +000057if smf_present ; then
58 QUAGGA_METHOD="start"
59else
60 QUAGGA_METHOD="$1"
61 shift;
paul1b414a12005-04-11 07:05:21 +000062fi
63
Paul Jakma75db03e2006-03-30 13:38:28 +000064DAEMON="$1"
65shift
66DAEMON_ARGS="$@"
paul1b414a12005-04-11 07:05:21 +000067
Paul Jakma75db03e2006-03-30 13:38:28 +000068# daemon path must be given
69if [ -z "$DAEMON_PATH/$DAEMON" ]; then
70 usage
71 exit $SMF_EXIT_ERR_FATAL
72fi
73
74# only bgpd is suitable for running in a non-global zone, at this
75# time.
76case "${DAEMON}" in
77 zebra)
78 quagga_is_globalzone || exit $SMF_EXIT_OK
79 ;;
80 bgpd)
Paul Jakmae24f0632006-02-19 18:59:26 +000081 ;;
82 ospfd | ospf6d | ripd | ripngd )
Paul Jakma75db03e2006-03-30 13:38:28 +000083 quagga_is_globalzone || exit $SMF_EXIT_OK
paul1b414a12005-04-11 07:05:21 +000084 ;;
85 *)
Paul Jakma75db03e2006-03-30 13:38:28 +000086 usage
87 exit $SMF_EXIT_ERR_CONFIG;
paul1b414a12005-04-11 07:05:21 +000088 ;;
89esac
90
Paul Jakma75db03e2006-03-30 13:38:28 +000091# we need @quagga_statedir@ to exist, it probably is on tmpfs.
paul9b78d052005-06-15 11:00:11 +000092if [ ! -d @quagga_statedir@ ] ; then
93 mkdir -p @quagga_statedir@
94 chown @enable_user@:@enable_group@ @quagga_statedir@
95 chmod 751 @quagga_statedir@
96fi
97
Paul Jakma75db03e2006-03-30 13:38:28 +000098PIDFILE="@quagga_statedir@/${DAEMON}.pid"
99
paul1b414a12005-04-11 07:05:21 +0000100start () {
Paul Jakma75db03e2006-03-30 13:38:28 +0000101 $DAEMON_PATH/$DAEMON $DAEMON_ARGS --pid_file ${PIDFILE} &
paul1b414a12005-04-11 07:05:21 +0000102}
103
104stop () {
105 if [ -f "${PIDFILE}" ]; then
106 /usr/bin/kill -TERM `/usr/bin/cat "${PIDFILE}"`
107 fi
108}
109
Paul Jakma75db03e2006-03-30 13:38:28 +0000110case "$QUAGGA_METHOD" in
paul1b414a12005-04-11 07:05:21 +0000111'start')
Paul Jakma75db03e2006-03-30 13:38:28 +0000112 start
paul1b414a12005-04-11 07:05:21 +0000113 ;;
114'stop')
Paul Jakma75db03e2006-03-30 13:38:28 +0000115 stop
paul1b414a12005-04-11 07:05:21 +0000116 ;;
117
paul1b414a12005-04-11 07:05:21 +0000118*)
119 usage
Paul Jakma75db03e2006-03-30 13:38:28 +0000120 exit SMF_EXIT_ERR_FATAL
paul1b414a12005-04-11 07:05:21 +0000121 ;;
122esac
123
124exit $SMF_EXIT_OK;