svc-zones revision 7c478bd95313f5f23a4c958a745db2134aa03244
1690N/A#!/sbin/sh
1690N/A#
1690N/A# CDDL HEADER START
1690N/A#
1690N/A# The contents of this file are subject to the terms of the
1690N/A# Common Development and Distribution License, Version 1.0 only
1690N/A# (the "License"). You may not use this file except in compliance
1690N/A# with the License.
1690N/A#
1690N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1690N/A# or http://www.opensolaris.org/os/licensing.
1690N/A# See the License for the specific language governing permissions
1690N/A# and limitations under the License.
1690N/A#
1690N/A# When distributing Covered Code, include this CDDL HEADER in each
1690N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1690N/A# If applicable, add the following below this CDDL HEADER, with the
1690N/A# fields enclosed by brackets "[]" replaced with your own identifying
1690N/A# information: Portions Copyright [yyyy] [name of copyright owner]
1690N/A#
1690N/A# CDDL HEADER END
1690N/A#
1690N/A#
1690N/A# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
1690N/A# Use is subject to license terms.
1690N/A
1690N/A# ident "%Z%%M% %I% %E% SMI"
1690N/A#
2086N/A
2086N/A[ ! -x /usr/sbin/zoneadm ] && exit 0 # SUNWzoneu not installed
2086N/A
1690N/A# Make sure working directory is / to prevent unmounting problems.
1690N/Acd /
2086N/APATH=/usr/sbin:/usr/bin; export PATH
2086N/A
1690N/Acase "$1" in
1690N/A'start')
1690N/A egrep -vs '^#|^global:' /etc/zones/index || exit 0 # no local zones
1690N/A ZONES=""
1690N/A for zone in `zoneadm list -pi | nawk -F: '{
1690N/A if ($3 == "installed") {
1690N/A print $2
1690N/A }
1690N/A }'`; do
1690N/A zonecfg -z $zone info autoboot | grep "true" >/dev/null 2>&1
1690N/A if [ $? -eq 0 ]; then
1690N/A [ -z "$ZONES" ] && echo "Booting zones:\c"
1690N/A ZONES=yes
1690N/A echo " $zone\c"
1690N/A #
1813N/A # We don't (yet) support restart for zones, so
1690N/A # we need to get all of the zones stuff off into
1690N/A # a different contract.
1690N/A #
1690N/A ctrun -l none -i none zoneadm -z $zone boot &
1690N/A fi
1690N/A done
1690N/A [ -n "$ZONES" ] && echo .
1690N/A ;;
1690N/A
1690N/A'stop')
1690N/A egrep -vs '^#|^global:' /etc/zones/index || exit 0 # no local zones
1690N/A [ "`zoneadm list`" = "global" ] && exit 0 # no zones running
1690N/A
1690N/A MAXSHUT=60 # maximum time we'll wait for all zones to shutdown
1690N/A MAXHALT=30 # maximum time we'll wait for all zones to halt
1690N/A
1690N/A echo "Shutting down running zones:\c"
1690N/A
1690N/A # First, try letting them run their shutdown scripts.
1690N/A
1690N/A SHUTDOWN=0
1690N/A for zone in `zoneadm list`; do
1690N/A if [ "$zone" != "global" ]; then
1690N/A echo " $zone\c"
1690N/A zlogin -S $zone /sbin/init 0 < /dev/null >&0 2>&0 &
1690N/A SHUTDOWN=1
1690N/A fi
1842N/A done
1690N/A [ $SHUTDOWN -eq 1 ] && echo "."
1690N/A
1858N/A # Allow time for zones to shutdown cleanly
1690N/A
1690N/A while [ $MAXSHUT -gt 0 -a "`zoneadm list`" != "global" ]; do
1690N/A MAXSHUT=`expr $MAXSHUT - 1`
1690N/A sleep 1 # wait a bit longer
1690N/A done
1690N/A
1690N/A # Second, try halting them.
1690N/A
1690N/A WAITPIDS=""
1690N/A for zone in `zoneadm list`; do
1690N/A if [ "$zone" != "global" ]; then
1690N/A [ -z "$WAITPIDS" ] &&
1690N/A echo "Zones failed to shutdown; trying to halt:\c"
1690N/A echo " $zone\c"
1690N/A zoneadm -z $zone halt &
1690N/A WAITPIDS="$WAITPIDS $!"
1690N/A fi
1690N/A done
1690N/A [ ! -z "$WAITPIDS" ] && echo .
1690N/A
1690N/A # Wait for the 'zoneadm halt' commands to complete. We will let this
1690N/A # run forever, since the restart daemon will eventually kill us off
1690N/A # anyway if the halts do not complete after a certain period of time.
1690N/A wait $WAITPIDS
1690N/A
1690N/A # If the halts complete but a zone is still not shutdown, it might
1690N/A # be in a state like 'shutting_down' or 'down'. So we give it some
2086N/A # time to come all the way down.
2086N/A while [ $MAXHALT -gt 0 -a "`zoneadm list`" != "global" ]; do
1690N/A MAXHALT=`expr $MAXHALT - 1`
1690N/A sleep 1 # wait a bit longer
1690N/A done
1690N/A
1813N/A #
1690N/A # Report on zones which failed to shutdown.
1690N/A #
1690N/A for zone in `zoneadm list`; do
1690N/A if [ "$zone" != "global" ]; then
1690N/A echo "Zone '$zone' failed to halt."
1690N/A fi
1813N/A done
1690N/A [ "`zoneadm list`" != "global" ] && exit 1 # zones still running
1690N/A ;;
1690N/A
1690N/A*)
1690N/A echo "Usage: $0 { start | stop }"
1690N/A exit 1
1690N/A ;;
1690N/Aesac
1690N/Aexit 0
1690N/A