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