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 | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 6 | # $Id: quagga.init.in,v 1.6 2006/03/30 13:38:28 paul Exp $ |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 7 | # |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 8 | # Starts/stops the given daemon |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 9 | |
| 10 | SMFINCLUDE=/lib/svc/share/smf_include.sh |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 11 | DAEMON_PATH=@sbindir@ |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 12 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 13 | quagga_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. |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 23 | if [ -f "$SMFINCLUDE" ] ; then |
| 24 | . "$SMFINCLUDE"; |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 25 | else |
| 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; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 34 | fi |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 35 | |
| 36 | # if there's no SMF, set some default DAEMON_ARGS |
| 37 | smf_present || DAEMON_ARGS="" |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 38 | |
| 39 | usage () { |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 40 | 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 | } |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 48 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 49 | # parse arguments, different according to SMF or not. |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 50 | case $1 in |
| 51 | 'help' | 'usage') |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 52 | usage |
| 53 | exit SMF_EXIT_OK |
| 54 | ;; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 55 | esac |
| 56 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 57 | if smf_present ; then |
| 58 | QUAGGA_METHOD="start" |
| 59 | else |
| 60 | QUAGGA_METHOD="$1" |
| 61 | shift; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 62 | fi |
| 63 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 64 | DAEMON="$1" |
| 65 | shift |
| 66 | DAEMON_ARGS="$@" |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 67 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 68 | # daemon path must be given |
| 69 | if [ -z "$DAEMON_PATH/$DAEMON" ]; then |
| 70 | usage |
| 71 | exit $SMF_EXIT_ERR_FATAL |
| 72 | fi |
| 73 | |
| 74 | # only bgpd is suitable for running in a non-global zone, at this |
| 75 | # time. |
| 76 | case "${DAEMON}" in |
| 77 | zebra) |
| 78 | quagga_is_globalzone || exit $SMF_EXIT_OK |
| 79 | ;; |
| 80 | bgpd) |
Paul Jakma | e24f063 | 2006-02-19 18:59:26 +0000 | [diff] [blame] | 81 | ;; |
| 82 | ospfd | ospf6d | ripd | ripngd ) |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 83 | quagga_is_globalzone || exit $SMF_EXIT_OK |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 84 | ;; |
| 85 | *) |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 86 | usage |
| 87 | exit $SMF_EXIT_ERR_CONFIG; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 88 | ;; |
| 89 | esac |
| 90 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 91 | # we need @quagga_statedir@ to exist, it probably is on tmpfs. |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 92 | if [ ! -d @quagga_statedir@ ] ; then |
| 93 | mkdir -p @quagga_statedir@ |
| 94 | chown @enable_user@:@enable_group@ @quagga_statedir@ |
| 95 | chmod 751 @quagga_statedir@ |
| 96 | fi |
| 97 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 98 | PIDFILE="@quagga_statedir@/${DAEMON}.pid" |
| 99 | |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 100 | start () { |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 101 | $DAEMON_PATH/$DAEMON $DAEMON_ARGS --pid_file ${PIDFILE} & |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | stop () { |
| 105 | if [ -f "${PIDFILE}" ]; then |
| 106 | /usr/bin/kill -TERM `/usr/bin/cat "${PIDFILE}"` |
| 107 | fi |
| 108 | } |
| 109 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 110 | case "$QUAGGA_METHOD" in |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 111 | 'start') |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 112 | start |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 113 | ;; |
| 114 | 'stop') |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 115 | stop |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 116 | ;; |
| 117 | |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 118 | *) |
| 119 | usage |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 120 | exit SMF_EXIT_ERR_FATAL |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 121 | ;; |
| 122 | esac |
| 123 | |
| 124 | exit $SMF_EXIT_OK; |