paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 1 | #!/sbin/sh |
| 2 | # |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 3 | # Copyright 2001,2003 Sun Microsystems, Inc. All rights reserved. |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 4 | # Use is subject to license terms. |
| 5 | # |
Paul Jakma | def09df | 2007-02-22 17:55:20 +0000 | [diff] [blame] | 6 | # 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$ |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 24 | # |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 25 | # Starts/stops the given daemon |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 26 | |
| 27 | SMFINCLUDE=/lib/svc/share/smf_include.sh |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 28 | DAEMON_PATH=@sbindir@ |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 29 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 30 | quagga_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. |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 40 | if [ -f "$SMFINCLUDE" ] ; then |
| 41 | . "$SMFINCLUDE"; |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 42 | else |
| 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; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 51 | fi |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 52 | |
| 53 | # if there's no SMF, set some default DAEMON_ARGS |
| 54 | smf_present || DAEMON_ARGS="" |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 55 | |
| 56 | usage () { |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 57 | 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 | } |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 65 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 66 | # parse arguments, different according to SMF or not. |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 67 | case $1 in |
| 68 | 'help' | 'usage') |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 69 | usage |
| 70 | exit SMF_EXIT_OK |
| 71 | ;; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 72 | esac |
| 73 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 74 | if smf_present ; then |
| 75 | QUAGGA_METHOD="start" |
| 76 | else |
| 77 | QUAGGA_METHOD="$1" |
| 78 | shift; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 79 | fi |
| 80 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 81 | DAEMON="$1" |
| 82 | shift |
| 83 | DAEMON_ARGS="$@" |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 84 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 85 | # daemon path must be given |
| 86 | if [ -z "$DAEMON_PATH/$DAEMON" ]; then |
| 87 | usage |
| 88 | exit $SMF_EXIT_ERR_FATAL |
| 89 | fi |
| 90 | |
| 91 | # only bgpd is suitable for running in a non-global zone, at this |
| 92 | # time. |
| 93 | case "${DAEMON}" in |
| 94 | zebra) |
| 95 | quagga_is_globalzone || exit $SMF_EXIT_OK |
| 96 | ;; |
| 97 | bgpd) |
Paul Jakma | e24f063 | 2006-02-19 18:59:26 +0000 | [diff] [blame] | 98 | ;; |
| 99 | ospfd | ospf6d | ripd | ripngd ) |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 100 | quagga_is_globalzone || exit $SMF_EXIT_OK |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 101 | ;; |
| 102 | *) |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 103 | usage |
| 104 | exit $SMF_EXIT_ERR_CONFIG; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 105 | ;; |
| 106 | esac |
| 107 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 108 | # we need @quagga_statedir@ to exist, it probably is on tmpfs. |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 109 | if [ ! -d @quagga_statedir@ ] ; then |
| 110 | mkdir -p @quagga_statedir@ |
| 111 | chown @enable_user@:@enable_group@ @quagga_statedir@ |
| 112 | chmod 751 @quagga_statedir@ |
| 113 | fi |
| 114 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 115 | PIDFILE="@quagga_statedir@/${DAEMON}.pid" |
| 116 | |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 117 | start () { |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 118 | $DAEMON_PATH/$DAEMON $DAEMON_ARGS --pid_file ${PIDFILE} & |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | stop () { |
| 122 | if [ -f "${PIDFILE}" ]; then |
| 123 | /usr/bin/kill -TERM `/usr/bin/cat "${PIDFILE}"` |
| 124 | fi |
| 125 | } |
| 126 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 127 | case "$QUAGGA_METHOD" in |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 128 | 'start') |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 129 | start |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 130 | ;; |
| 131 | 'stop') |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 132 | stop |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 133 | ;; |
| 134 | |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 135 | *) |
| 136 | usage |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 137 | exit SMF_EXIT_ERR_FATAL |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 138 | ;; |
| 139 | esac |
| 140 | |
| 141 | exit $SMF_EXIT_OK; |