blob: ba3b484a904436431aed4615027dab06272c2127 [file] [log] [blame]
paul1b414a12005-04-11 07:05:21 +00001#!/sbin/sh
2#
3# Copyright 2001,2003 Sun Microsystems, Inc. All rights reserved.
4# Use is subject to license terms.
5#
paul9b78d052005-06-15 11:00:11 +00006# $Id: quagga.init.in,v 1.4 2005/06/15 11:00:11 paul Exp $
paul1b414a12005-04-11 07:05:21 +00007#
8# Starts/stops the appropriate daemon
9
10SMFINCLUDE=/lib/svc/share/smf_include.sh
11
12if [ -f "$SMFINCLUDE" ] ; then
13 . "$SMFINCLUDE";
14fi
15
16usage () {
paul9b78d052005-06-15 11:00:11 +000017 echo "Usage: $0 (start|stop) <fmri> <instance>";
paul1b414a12005-04-11 07:05:21 +000018}
19
20case $1 in
21 'help' | 'usage')
22 usage
23 ;;
24esac
25
paul9b78d052005-06-15 11:00:11 +000026# fmri and instance must be given.
paul1b414a12005-04-11 07:05:21 +000027FMRI="$2"
paul9b78d052005-06-15 11:00:11 +000028INSTANCE="$3"
29if [ -z "$FMRI" -o -z "$INSTANCE" ]; then
paul1b414a12005-04-11 07:05:21 +000030 usage
31 exit $SMF_EXIT_ERR_CONFIG
32fi
33
34# fmri must exist
35svcs ${FMRI} > /dev/null 2>&1 || exit $SMF_EXIT_ERR_CONFIG
36
paul9b78d052005-06-15 11:00:11 +000037case ${INSTANCE} in
paul1b414a12005-04-11 07:05:21 +000038 zebra | ospfd | ospf6d | ripd | ripngd | bgpd )
39 ;;
40 *)
41 usage
42 exit $SMF_EXIT_ERR_CONFIG;
43 ;;
44esac
45
paul9b78d052005-06-15 11:00:11 +000046svcprop -q -p @PACKAGE_TARNAME@/config_file ${FMRI} && \
47 CONFFILE=`svcprop -p @PACKAGE_TARNAME@/config_file ${FMRI}`
48svcprop -q -p @PACKAGE_TARNAME@/pid_file ${FMRI} && \
49 PIDFILE=`svcprop -p @PACKAGE_TARNAME@/pid_file ${FMRI}`
50svcprop -q -p @PACKAGE_TARNAME@/user ${FMRI} && \
51 USER=`svcprop -p @PACKAGE_TARNAME@/user ${FMRI}`
52svcprop -q -p @PACKAGE_TARNAME@/group ${FMRI} && \
53 GROUP=`svcprop -p @PACKAGE_TARNAME@/group ${FMRI}`
54svcprop -q -p @PACKAGE_TARNAME@/vty_addr ${FMRI} && \
55 VTYADDR=`svcprop -p @PACKAGE_TARNAME@/vty_addr ${FMRI}`
56svcprop -q -p @PACKAGE_TARNAME@/vty_port ${FMRI} && \
57 VTYPORT=`svcprop -p @PACKAGE_TARNAME@/vty_port ${FMRI}`
paul1b414a12005-04-11 07:05:21 +000058
59[ -n "${CONFFILE}" ] && ARGS=" -f ${CONFFILE}"
60[ -n "${PIDFILE}" ] && ARGS="${ARGS} --pid_file ${PIDFILE}"
61[ -n "${USER}" ] && ARGS="${ARGS} --user ${USER}"
62[ -n "${GROUP}" ] && ARGS="${ARGS} --group ${GROUP}"
paul9b78d052005-06-15 11:00:11 +000063
64# vty should default to disabled, ie port == 0
65[ -z "${VTYPORT}" ] && VTYPORT=0
66ARGS="${ARGS} --vty_port ${VTYPORT}"
67
68# default listen address should be localhost
69[ -z "${VTYADDR}" ] && VTYADDR=127.1
70ARGS="${ARGS} --vty_addr ${VTYADDR}"
paul1b414a12005-04-11 07:05:21 +000071
72# have to have a pid file for script to work
paul9b78d052005-06-15 11:00:11 +000073# we can assume it otherwise
74if [ -z "${PIDFILE}" ]; then
75 PIDFILE="@quagga_statedir@/${INSTANCE}.pid"
76else
77 ARGS="${ARGS} --pid_file ${PIDFILE}"
78fi
paul1b414a12005-04-11 07:05:21 +000079
80# config file must exist
paula6570ee2005-06-02 16:33:53 +000081#[ ! -f "$CONFFILE" ] && exit $SMF_EXIT_ERR_CONFIG
paul1b414a12005-04-11 07:05:21 +000082
paul9b78d052005-06-15 11:00:11 +000083# we need @quagga_statedir@ to exist, it might be on tmpfs.
84if [ ! -d @quagga_statedir@ ] ; then
85 mkdir -p @quagga_statedir@
86 chown @enable_user@:@enable_group@ @quagga_statedir@
87 chmod 751 @quagga_statedir@
88fi
89
paul1b414a12005-04-11 07:05:21 +000090start () {
paul9b78d052005-06-15 11:00:11 +000091 @sbindir@/${INSTANCE} ${ARGS} &
paul1b414a12005-04-11 07:05:21 +000092}
93
94stop () {
95 if [ -f "${PIDFILE}" ]; then
96 /usr/bin/kill -TERM `/usr/bin/cat "${PIDFILE}"`
97 fi
98}
99
100restart() {
paul9b78d052005-06-15 11:00:11 +0000101 stop ${INSTANCE}
paul1b414a12005-04-11 07:05:21 +0000102 sleep 1
paul9b78d052005-06-15 11:00:11 +0000103 start ${INSTANCE}
paul1b414a12005-04-11 07:05:21 +0000104}
105
106case $1 in
107'start')
108 start ${2}
109 ;;
110'stop')
111 stop ${2}
112 ;;
113
114'restart')
115 restart ${2}
116 ;;
117*)
118 usage
119 exit 1
120 ;;
121esac
122
123exit $SMF_EXIT_OK;