paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 1 | #!/sbin/sh |
| 2 | # |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 3 | # Copyright 2007 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 | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 28 | ROUTEADMINCLUDE=/lib/svc/share/routing_include.sh |
| 29 | GLOBAL_OPTIONS="PAfiug" |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 30 | DAEMON_PATH=@sbindir@ |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 31 | USER=@enable_user@ |
| 32 | GROUP=@enable_group@ |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 33 | |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 34 | # handle upgrade of daemon-args SMF property to new routeadm properties |
| 35 | # used during upgrade too by routeadm. |
| 36 | # relevant to S10U4+ only. |
| 37 | handle_routeadm_upgrade () { |
| 38 | GLOBAL_OPTIONS="PAfiug" |
| 39 | |
| 40 | daemon_args=`get_daemon_args $SMF_FMRI` |
| 41 | |
| 42 | if [ -n "$daemon_args" ]; then |
| 43 | set_daemon_value_property "$SMF_FMRI" "$daemon_args" \ |
| 44 | "$GLOBAL_OPTIONS" "P" vty_port 0 |
| 45 | set_daemon_value_property "$SMF_FMRI" "$daemon_args" \ |
| 46 | "$GLOBAL_OPTIONS" "A" vty_address |
| 47 | set_daemon_value_property "$SMF_FMRI" "$daemon_args" \ |
| 48 | "$GLOBAL_OPTIONS" "f" config_file |
| 49 | set_daemon_value_property "$SMF_FMRI" "$daemon_args" \ |
| 50 | "$GLOBAL_OPTIONS" "i" pid_file |
| 51 | set_daemon_value_property "$SMF_FMRI" "$daemon_args" \ |
| 52 | "$GLOBAL_OPTIONS" "u" user |
| 53 | set_daemon_value_property "$SMF_FMRI" "$daemon_args" \ |
| 54 | "$GLOBAL_OPTIONS" "g" group |
| 55 | |
| 56 | case "$1" in |
| 57 | zebra) |
| 58 | set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \ |
| 59 | "${GLOBAL_OPTIONS}b" "b" batch true false |
| 60 | ;; |
| 61 | ripd|ripngd) |
| 62 | set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \ |
| 63 | "${GLOBAL_OPTIONS}r" "r" retain true false |
| 64 | ;; |
| 65 | bgpd) |
| 66 | set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \ |
| 67 | "${GLOBAL_OPTIONS}rnp" "r" retain true false |
| 68 | set_daemon_boolean_property "$SMF_FMRI" "$daemon_args" \ |
| 69 | "${GLOBAL_OPTIONS}rnp" "n" no_kernel true false |
| 70 | set_daemon_value_property "$SMF_FMRI" "$daemon_args" \ |
| 71 | "${GLOBAL_OPTIONS}rnp" "p" bgp_port |
| 72 | esac |
| 73 | clear_daemon_args $SMF_FMRI |
| 74 | fi |
| 75 | } |
| 76 | |
| 77 | upgrade_config () { |
| 78 | DAEMON=$1 |
| 79 | # handle upgrade of SUNWzebra to Quagga |
| 80 | if [ -d "/etc/quagga" -a ! -f "/etc/quagga/${DAEMON}.conf" ] ; then |
| 81 | if [ -f "/etc/sfw/zebra/${DAEMON}.conf" ] ; then |
| 82 | cp "/etc/sfw/zebra/${DAEMON}.conf" \ |
| 83 | "/etc/quagga/${DAEMON}.conf.upgrade" \ |
| 84 | || exit $SMF_EXIT_ERR_FATAL |
| 85 | chown "${USER}:${GROUP}" "/etc/quagga/${DAEMON}.conf.upgrade" \ |
| 86 | || exit $SMF_EXIT_ERR_FATAL |
| 87 | chmod 0600 "/etc/quagga/${DAEMON}.conf.upgrade" \ |
| 88 | || exit $SMF_EXIT_ERR_FATAL |
| 89 | mv "/etc/quagga/${DAEMON}.conf.upgrade" "/etc/quagga/${DAEMON}.conf" \ |
| 90 | || exit $SMF_EXIT_ERR_FATAL |
| 91 | fi |
| 92 | fi |
| 93 | |
| 94 | if [ ! -f "/etc/quagga/${DAEMON}.conf" ] ; then |
| 95 | touch "/etc/quagga/${DAEMON}.conf.new" \ |
| 96 | || exit $SMF_EXIT_ERR_FATAL |
| 97 | chown "${USER}:${GROUP}" "/etc/quagga/${DAEMON}.conf.new" \ |
| 98 | || exit $SMF_EXIT_ERR_FATAL |
| 99 | chmod 0600 "/etc/quagga/${DAEMON}.conf.new" \ |
| 100 | || exit $SMF_EXIT_ERR_FATAL |
| 101 | mv "/etc/quagga/${DAEMON}.conf.new" "/etc/quagga/${DAEMON}.conf" \ |
| 102 | || exit $SMF_EXIT_ERR_FATAL |
| 103 | fi |
| 104 | } |
| 105 | |
| 106 | # Relevant to S10+ |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 107 | quagga_is_globalzone () { |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 108 | if [ "${QUAGGA_INIT_ZONENAME:=`/sbin/zonename`}" = "global" \ |
| 109 | -o `/sbin/zonename -t` = "exclusive" ]; then |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 110 | return 0 |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 111 | else |
| 112 | return 1 |
| 113 | fi |
| 114 | } |
| 115 | |
| 116 | routeadm_daemon_args () { |
| 117 | # globals |
| 118 | args="`get_daemon_option_from_property $SMF_FMRI config_file f`" |
| 119 | args="${args} `get_daemon_option_from_property $SMF_FMRI vty_port P`" |
| 120 | args="${args} `get_daemon_option_from_property $SMF_FMRI vty_address A`" |
| 121 | args="${args} `get_daemon_option_from_property $SMF_FMRI pid_file i`" |
| 122 | |
| 123 | # user and group we need for config file upgrade.. |
| 124 | SMF_USER=`get_routeadm_property $SMF_FMRI user` |
| 125 | SMF_GROUP=`get_routeadm_property()$SMF_FMRI group` |
| 126 | if [ "${SMF_USER}" ] ; then |
| 127 | USER="${SMF_USER}" |
| 128 | args="${args} -u ${SMF_USER}" |
| 129 | fi |
| 130 | if [ "${SMF_GROUP}" ] ; then |
| 131 | GROUP="${SMF_GROUP}" |
| 132 | args="${args} -g ${SMF_GROUP}" |
| 133 | fi |
| 134 | |
| 135 | case $1 in |
| 136 | zebra) |
| 137 | args="${args} `get_daemon_option_from_boolean_property $SMF_FMRI batch -b true`" |
| 138 | ;; |
| 139 | ripd|ripngd) |
| 140 | args="${args} `get_daemon_option_from_boolean_property $SMF_FMRI retain -r true`" |
| 141 | ;; |
| 142 | bgpd) |
| 143 | args="${args} `get_daemon_option_from_boolean_property $SMF_FMRI retain -r true`" |
| 144 | args="${args} `get_daemon_option_from_boolean_property $SMF_FMRI no_kernel -n true`" |
| 145 | args="${args} `get_daemon_option_from_property $SMF_FMRI bgp_port p 179`" |
| 146 | ;; |
| 147 | esac |
| 148 | echo ${args} |
| 149 | } |
| 150 | |
| 151 | # certain daemons need zebra |
| 152 | routeadm_zebra_enable () { |
| 153 | |
| 154 | if [ "$DAEMON" = "zebra" ]; then |
| 155 | return |
| 156 | fi |
| 157 | |
| 158 | enable_zebra=`/usr/bin/svcprop -p \ |
| 159 | routing/enable_zebra $SMF_FMRI 2> /dev/null` |
| 160 | if [ "$enable_zebra" != "false" ]; then |
| 161 | zenabled=`/usr/bin/svcprop -p general/enabled zebra:quagga` |
| 162 | zenabledt=`/usr/bin/svcprop -p general_ovr/enabled zebra:quagga` |
| 163 | if [ "$zenabled" = "true" -o "$zenabledt" = "true" ]; then |
| 164 | /usr/sbin/svcadm disable zebra:quagga |
| 165 | /usr/sbin/svcadm enable -st zebra:quagga |
| 166 | else |
| 167 | /usr/sbin/svcadm enable -st zebra:quagga |
| 168 | fi |
| 169 | if [ "$?" != "0" ]; then |
| 170 | echo "Could not enable zebra:quagga" |
| 171 | exit $SMF_EXIT_ERR_FATAL |
| 172 | fi |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 173 | fi |
| 174 | } |
| 175 | |
| 176 | # Include smf functions, if available. If not, define smf_present to indicate |
| 177 | # there is no SMF. Should allow this script to work pre-S10. |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 178 | if [ -f "$SMFINCLUDE" ] ; then |
| 179 | . "$SMFINCLUDE"; |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 180 | |
| 181 | # source the SMF-routeadm include if present.. |
| 182 | if [ -f "$ROUTEADMINCLUDE" ] ; then |
| 183 | . "$ROUTEADMINCLUDE" |
| 184 | fi |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 185 | else |
| 186 | # pre-SMF system, fake up any functions and exit codes |
| 187 | # which SMFINCLUDE usually provides. |
| 188 | smf_present () { |
| 189 | return 1 |
| 190 | } |
| 191 | SMF_EXIT_OK=0; |
| 192 | SMF_EXIT_ERR_CONFIG=96; |
| 193 | SMF_EXIT_ERR_FATAL=95; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 194 | fi |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 195 | |
| 196 | # if there's no SMF, set some default DAEMON_ARGS |
| 197 | smf_present || DAEMON_ARGS="" |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 198 | |
| 199 | usage () { |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 200 | if smf_present ; then |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 201 | echo "Usage: $0 <daemon>"; |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 202 | else |
| 203 | echo "Usage: $0 <stop|start> <daemon> <daemon arguments>"; |
| 204 | fi |
| 205 | echo "The --pid_file argument is implied"; |
| 206 | echo "This help message: $0 <help|usage>"; |
| 207 | } |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 208 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 209 | # parse arguments, different according to SMF or not. |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 210 | case $1 in |
| 211 | 'help' | 'usage') |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 212 | usage |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 213 | exit $SMF_EXIT_OK |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 214 | ;; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 215 | esac |
| 216 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 217 | if smf_present ; then |
| 218 | QUAGGA_METHOD="start" |
| 219 | else |
| 220 | QUAGGA_METHOD="$1" |
| 221 | shift; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 222 | fi |
| 223 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 224 | DAEMON="$1" |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 225 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 226 | # daemon path must be given |
| 227 | if [ -z "$DAEMON_PATH/$DAEMON" ]; then |
| 228 | usage |
| 229 | exit $SMF_EXIT_ERR_FATAL |
| 230 | fi |
| 231 | |
| 232 | # only bgpd is suitable for running in a non-global zone, at this |
| 233 | # time. |
| 234 | case "${DAEMON}" in |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 235 | bgpd) |
Paul Jakma | e24f063 | 2006-02-19 18:59:26 +0000 | [diff] [blame] | 236 | ;; |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 237 | zebra | ospfd | ospf6d | ripd | ripngd ) |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 238 | quagga_is_globalzone || exit $SMF_EXIT_OK |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 239 | ;; |
| 240 | *) |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 241 | usage |
| 242 | exit $SMF_EXIT_ERR_CONFIG; |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 243 | ;; |
| 244 | esac |
| 245 | |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 246 | # Older Quagga SMF packages pass daemon args on the commandline |
| 247 | # Newer SMF routeadm model uses properties for each argument |
| 248 | # so we must handle that. |
| 249 | if [ smf_present -a -f "$ROUTEADMINCLUDE" ]; then |
| 250 | handle_routeadm_upgrade $DAEMON; |
| 251 | DAEMON_ARGS=`routeadm_daemon_args`; |
| 252 | routeadm_zebra_enable $DAEMON; |
| 253 | else |
| 254 | if [ $# -gt 0 ] ; then |
| 255 | shift |
| 256 | DAEMON_ARGS="$@" |
| 257 | fi |
| 258 | fi |
| 259 | |
| 260 | upgrade_config "$DAEMON" |
| 261 | |
| 262 | if [ ! -f "@sysconfdir@/${DAEMON}.conf" ] ; then |
| 263 | echo "Could not find config file, @sysconfdir@/${DAEMON}.conf" |
| 264 | exit $SMF_EXIT_ERR_CONFIG |
| 265 | fi |
| 266 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 267 | # we need @quagga_statedir@ to exist, it probably is on tmpfs. |
paul | 9b78d05 | 2005-06-15 11:00:11 +0000 | [diff] [blame] | 268 | if [ ! -d @quagga_statedir@ ] ; then |
| 269 | mkdir -p @quagga_statedir@ |
| 270 | chown @enable_user@:@enable_group@ @quagga_statedir@ |
| 271 | chmod 751 @quagga_statedir@ |
| 272 | fi |
| 273 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 274 | PIDFILE="@quagga_statedir@/${DAEMON}.pid" |
| 275 | |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 276 | start () { |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 277 | if [ ! -x "$DAEMON_PATH/$DAEMON" ] ; then |
| 278 | echo "Error, could not find daemon, $DAEMON_PATH/$DAEMON" |
| 279 | exit $SMF_EXIT_ERR_FATAL |
| 280 | fi |
| 281 | eval exec $DAEMON_PATH/$DAEMON $DAEMON_ARGS --pid_file ${PIDFILE} & |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | stop () { |
| 285 | if [ -f "${PIDFILE}" ]; then |
| 286 | /usr/bin/kill -TERM `/usr/bin/cat "${PIDFILE}"` |
| 287 | fi |
| 288 | } |
| 289 | |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 290 | case "$QUAGGA_METHOD" in |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 291 | 'start') |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 292 | start |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 293 | ;; |
| 294 | 'stop') |
Paul Jakma | 75db03e | 2006-03-30 13:38:28 +0000 | [diff] [blame] | 295 | stop |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 296 | ;; |
| 297 | |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 298 | *) |
| 299 | usage |
Paul Jakma | c2be59b | 2008-07-03 20:41:08 +0000 | [diff] [blame] | 300 | exit $SMF_EXIT_ERR_FATAL |
paul | 1b414a1 | 2005-04-11 07:05:21 +0000 | [diff] [blame] | 301 | ;; |
| 302 | esac |
| 303 | |
| 304 | exit $SMF_EXIT_OK; |