restart_fmri revision 5887
18N/A#!/bin/ksh
18N/A#
18N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
18N/A# Use is subject to license terms.
18N/A#
18N/A# Permission is hereby granted, free of charge, to any person obtaining a
18N/A# copy of this software and associated documentation files (the
18N/A# "Software"), to deal in the Software without restriction, including
18N/A# without limitation the rights to use, copy, modify, merge, publish,
18N/A# distribute, and/or sell copies of the Software, and to permit persons
18N/A# to whom the Software is furnished to do so, provided that the above
18N/A# copyright notice(s) and this permission notice appear in all copies of
18N/A# the Software and that both the above copyright notice(s) and this
18N/A# permission notice appear in supporting documentation.
18N/A#
18N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18N/A# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18N/A# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
18N/A# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18N/A# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
18N/A# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
58N/A# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
18N/A# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
18N/A# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18N/A#
18N/A# Except as contained in this notice, the name of a copyright holder
18N/A# shall not be used in advertising or otherwise to promote the sale, use
18N/A# or other dealings in this Software without prior written authorization
18N/A# of the copyright holder.
18N/A#
18N/A###########################################################################
18N/A#
42N/A
42N/Aif [ "$LUBIN" != "" ]; then
135N/A #
18N/A # Live Upgrade.
136N/A #
136N/A # No need to restart any services, we will do that at system boot
136N/A #
136N/A echo "Postinstall actions deferred until the next system boot"
136N/A exit 0
136N/Aelif [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" -a \
136N/A "x$postrun_alt_root_okay" != xyes ]; then
136N/A #
136N/A # Installation to an alternate root directory
135N/A #
58N/A # Not safe to restart the services in the altroot, wait for the next
18N/A # system boot
18N/A #
18N/A echo "Postinstall actions deferred until the next system boot"
18N/A exit 0
18N/Afi
18N/A
137N/Ausage() {
137N/A echo "Usage: $0 [options] [sevices]"
137N/A echo
137N/A echo "Options:"
137N/A echo
137N/A echo " -h, --help display this usage information"
18N/A echo " -n test mode; print what would be done, but don't do it"
18N/A}
18N/A
18N/Acheck_svc() {
58N/A svc_fmri=unknown
18N/A svc_state=unknown
135N/A svc_next_state=unknown
135N/A cmd_out="$(LC_ALL=C /usr/bin/svcs -l "$1" 2>&1)"
135N/A if [ $? != 0 ]; then
136N/A svc_exists=0
136N/A return
135N/A fi
135N/A svc_exists=1
135N/A svc_fmri=$(echo "$cmd_out" | /bin/grep "^fmri " | /bin/awk '{ print $2 }')
135N/A svc_state=$(echo "$cmd_out" | /bin/grep "^state " | /bin/awk '{ print $2 }')
135N/A svc_next_state=$(echo "$cmd_out" | /bin/grep "^next_state " | /bin/awk '{ print $2 }')
135N/A}
135N/A
135N/Atest_mode=0
135N/Asvcs_to_restart=
135N/Asvcs_to_enable=
135N/Aretval=0
135N/A
135N/Afor arg in "${@}"; do
135N/A if [ "x$arg" == "x-h" -o "x$arg" == "x--help" ]; then
137N/A usage
135N/A exit 0
135N/A fi
135N/A
135N/A if [ "x$arg" == "x-n" ]; then
136N/A test_mode=1
136N/A continue
135N/A fi
135N/A
135N/A # sets svc_exists, svc_state, svc_fmri
135N/A check_svc "$arg"
42N/A
18N/A if [ $svc_exists == 0 ]; then
18N/A echo "ERROR: smf service not found: $arg"
42N/A retval=1
42N/A continue
136N/A fi
136N/A
18N/A if [ "$svc_state" == "online" ]; then
18N/A svcs_to_restart="$svcs_to_restart $svc_fmri"
212N/A elif [ "$svc_state" == "offline" -a "$svc_next_state" == "online" ]; then
212N/A # the service is still running its start method
212N/A svcs_to_restart="$svcs_to_restart $svc_fmri"
212N/A elif [ "$svc_state" == "disabled" ]; then
212N/A svcs_to_enable="$svcs_to_enable $svc_fmri"
18N/A elif [ "$svc_state" == "maintenance" ]; then
42N/A echo "ERROR: smf service $svc_fmri is in maintenance mode, try svcadm clear"
18N/A retval=1
42N/A else
18N/A echo "ERROR: smf service $svc_fmri is in $svc_state state."
136N/A retval=1
136N/A fi
42N/Adone
42N/A
42N/Aif [ -n "$svcs_to_restart" ]; then
42N/A if [ $test_mode == 1 ]; then
42N/A echo "Restarting services [test mode, not actually restarting them]:"
42N/A else
42N/A echo "Restarting services:"
42N/A fi
42N/Afi
42N/Afor fmri in $svcs_to_restart; do
42N/A echo " $fmri"
18N/A if [ $test_mode == 0 ]; then
18N/A /usr/sbin/svcadm restart $fmri
18N/A fi
18N/Adone
42N/A
18N/Aif [ -n "$svcs_to_enable" ]; then
18N/A if [ $test_mode == 1 ]; then
42N/A echo "Enabling services [test mode, not actually enabling them]:"
42N/A else
42N/A echo "Enabling services:"
42N/A fi
42N/Afi
42N/Afor fmri in $svcs_to_enable; do
42N/A echo " $fmri"
42N/A if [ $test_mode == 0 ]; then
42N/A /usr/sbin/svcadm enable $fmri
42N/A fi
42N/Adone
42N/A
42N/Areturn $retval
42N/A