| Current File : //usr/share/desktop-cache/restart_fmri |
#!/bin/ksh
if [ "$LUBIN" != "" ]; then
#
# Live Upgrade.
#
# No need to restart any services, we will do that at system boot
#
echo "Postinstall actions deferred until the next system boot"
exit 0
elif [ "$PKG_INSTALL_ROOT" != "" -a "$PKG_INSTALL_ROOT" != "/" -a \
"x$postrun_alt_root_okay" != xyes ]; then
#
# Installation to an alternate root directory
#
# Not safe to restart the services in the altroot, wait for the next
# system boot
#
echo "Postinstall actions deferred until the next system boot"
exit 0
fi
usage() {
echo "Usage: $0 [options] [sevices]"
echo
echo "Options:"
echo
echo " -h, --help display this usage information"
echo " -n test mode; print what would be done, but don't do it"
}
check_svc() {
svc_fmri=unknown
svc_state=unknown
svc_next_state=unknown
cmd_out="$(LC_ALL=C /usr/bin/svcs -l "$1" 2>&1)"
if [ $? != 0 ]; then
svc_exists=0
return
fi
svc_exists=1
svc_fmri=$(echo "$cmd_out" | /bin/grep "^fmri " | /bin/awk '{ print $2 }')
svc_state=$(echo "$cmd_out" | /bin/grep "^state " | /bin/awk '{ print $2 }')
svc_next_state=$(echo "$cmd_out" | /bin/grep "^next_state " | /bin/awk '{ print $2 }')
}
test_mode=0
svcs_to_restart=
svcs_to_enable=
retval=0
for arg in "${@}"; do
if [ "x$arg" == "x-h" -o "x$arg" == "x--help" ]; then
usage
exit 0
fi
if [ "x$arg" == "x-n" ]; then
test_mode=1
continue
fi
# sets svc_exists, svc_state, svc_fmri
check_svc "$arg"
if [ $svc_exists == 0 ]; then
echo "ERROR: smf service not found: $arg"
retval=1
continue
fi
if [ "$svc_state" == "online" ]; then
svcs_to_restart="$svcs_to_restart $svc_fmri"
elif [ "$svc_state" == "offline" -a "$svc_next_state" == "online" ]; then
# the service is still running its start method
svcs_to_restart="$svcs_to_restart $svc_fmri"
elif [ "$svc_state" == "disabled" ]; then
svcs_to_enable="$svcs_to_enable $svc_fmri"
elif [ "$svc_state" == "maintenance" ]; then
echo "ERROR: smf service $svc_fmri is in maintenance mode, try svcadm clear"
retval=1
else
echo "ERROR: smf service $svc_fmri is in $svc_state state."
retval=1
fi
done
if [ -n "$svcs_to_restart" ]; then
if [ $test_mode == 1 ]; then
echo "Restarting services [test mode, not actually restarting them]:"
else
echo "Restarting services:"
fi
fi
for fmri in $svcs_to_restart; do
echo " $fmri"
if [ $test_mode == 0 ]; then
/usr/sbin/svcadm restart $fmri
fi
done
if [ -n "$svcs_to_enable" ]; then
if [ $test_mode == 1 ]; then
echo "Enabling services [test mode, not actually enabling them]:"
else
echo "Enabling services:"
fi
fi
for fmri in $svcs_to_enable; do
echo " $fmri"
if [ $test_mode == 0 ]; then
/usr/sbin/svcadm enable $fmri
fi
done
return $retval