paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 1 | #!/sbin/sh |
| 2 | # |
| 3 | # Copyright 2001,2003 Sun Microsystems, Inc. All rights reserved. |
| 4 | # Use is subject to license terms. |
| 5 | # |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 6 | # $Id: quagga.init.in,v 1.4 2005/06/15 11:00:11 paul Exp $ |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 7 | # |
| 8 | # Starts/stops the appropriate daemon |
| 9 | |
| 10 | SMFINCLUDE=/lib/svc/share/smf_include.sh |
| 11 | |
| 12 | if [ -f "$SMFINCLUDE" ] ; then |
| 13 | . "$SMFINCLUDE"; |
| 14 | fi |
| 15 | |
| 16 | usage () { |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 17 | echo "Usage: $0 (start|stop) <fmri> <instance>"; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | case $1 in |
| 21 | 'help' | 'usage') |
| 22 | usage |
| 23 | ;; |
| 24 | esac |
| 25 | |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 26 | # fmri and instance must be given. |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 27 | FMRI="$2" |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 28 | INSTANCE="$3" |
| 29 | if [ -z "$FMRI" -o -z "$INSTANCE" ]; then |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 30 | usage |
| 31 | exit $SMF_EXIT_ERR_CONFIG |
| 32 | fi |
| 33 | |
| 34 | # fmri must exist |
| 35 | svcs ${FMRI} > /dev/null 2>&1 || exit $SMF_EXIT_ERR_CONFIG |
| 36 | |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 37 | case ${INSTANCE} in |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 38 | zebra | ospfd | ospf6d | ripd | ripngd | bgpd ) |
| 39 | ;; |
| 40 | *) |
| 41 | usage |
| 42 | exit $SMF_EXIT_ERR_CONFIG; |
| 43 | ;; |
| 44 | esac |
| 45 | |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 46 | svcprop -q -p @PACKAGE_TARNAME@/config_file ${FMRI} && \ |
| 47 | CONFFILE=`svcprop -p @PACKAGE_TARNAME@/config_file ${FMRI}` |
| 48 | svcprop -q -p @PACKAGE_TARNAME@/pid_file ${FMRI} && \ |
| 49 | PIDFILE=`svcprop -p @PACKAGE_TARNAME@/pid_file ${FMRI}` |
| 50 | svcprop -q -p @PACKAGE_TARNAME@/user ${FMRI} && \ |
| 51 | USER=`svcprop -p @PACKAGE_TARNAME@/user ${FMRI}` |
| 52 | svcprop -q -p @PACKAGE_TARNAME@/group ${FMRI} && \ |
| 53 | GROUP=`svcprop -p @PACKAGE_TARNAME@/group ${FMRI}` |
| 54 | svcprop -q -p @PACKAGE_TARNAME@/vty_addr ${FMRI} && \ |
| 55 | VTYADDR=`svcprop -p @PACKAGE_TARNAME@/vty_addr ${FMRI}` |
| 56 | svcprop -q -p @PACKAGE_TARNAME@/vty_port ${FMRI} && \ |
| 57 | VTYPORT=`svcprop -p @PACKAGE_TARNAME@/vty_port ${FMRI}` |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 58 | |
| 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}" |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 63 | |
| 64 | # vty should default to disabled, ie port == 0 |
| 65 | [ -z "${VTYPORT}" ] && VTYPORT=0 |
| 66 | ARGS="${ARGS} --vty_port ${VTYPORT}" |
| 67 | |
| 68 | # default listen address should be localhost |
| 69 | [ -z "${VTYADDR}" ] && VTYADDR=127.1 |
| 70 | ARGS="${ARGS} --vty_addr ${VTYADDR}" |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 71 | |
| 72 | # have to have a pid file for script to work |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 73 | # we can assume it otherwise |
| 74 | if [ -z "${PIDFILE}" ]; then |
| 75 | PIDFILE="@quagga_statedir@/${INSTANCE}.pid" |
| 76 | else |
| 77 | ARGS="${ARGS} --pid_file ${PIDFILE}" |
| 78 | fi |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 79 | |
| 80 | # config file must exist |
paul | a6570ee | 2005-06-02 16:33:53 +0000 | [diff] [blame] | 81 | #[ ! -f "$CONFFILE" ] && exit $SMF_EXIT_ERR_CONFIG |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 82 | |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 83 | # we need @quagga_statedir@ to exist, it might be on tmpfs. |
| 84 | if [ ! -d @quagga_statedir@ ] ; then |
| 85 | mkdir -p @quagga_statedir@ |
| 86 | chown @enable_user@:@enable_group@ @quagga_statedir@ |
| 87 | chmod 751 @quagga_statedir@ |
| 88 | fi |
| 89 | |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 90 | start () { |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 91 | @sbindir@/${INSTANCE} ${ARGS} & |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | stop () { |
| 95 | if [ -f "${PIDFILE}" ]; then |
| 96 | /usr/bin/kill -TERM `/usr/bin/cat "${PIDFILE}"` |
| 97 | fi |
| 98 | } |
| 99 | |
| 100 | restart() { |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 101 | stop ${INSTANCE} |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 102 | sleep 1 |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 103 | start ${INSTANCE} |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | case $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 | ;; |
| 121 | esac |
| 122 | |
| 123 | exit $SMF_EXIT_OK; |