5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 # Copyright 2014 Nexenta Systems, Inc. All rights reserved.
26 .
/lib
/svc
/share
/smf_include.sh
29 # Return a list of running, non-global zones for which a shutdown via
30 # "/sbin/init 0" may work (typically only Solaris zones.)
34 zoneadm list
-p | nawk
-F: '{
41 [ ! -x /usr
/sbin
/zoneadm
] && exit 0 # SUNWzoneu not installed
43 if [ -z "$SMF_FMRI" ]; then
44 echo "this script can only be invoked by smf(5)"
45 exit $SMF_EXIT_ERR_NOSMF
48 # Make sure working directory is / to prevent unmounting problems.
50 PATH
=/usr
/sbin
:/usr
/bin
; export PATH
54 egrep -vs '^#|^global:' /etc
/zones
/index ||
exit 0 # no local zones
57 # Boot the installed zones for which the "autoboot" zone property is
58 # set and invoke the sysboot hook for all other installed zones.
61 for zone
in `zoneadm list -pi | nawk -F: '{
62 if ($3 == "installed") {
66 zonecfg
-z $zone info autoboot |
grep "true" >/dev
/null
2>&1
68 [ -z "$ZONES" ] && echo "Booting zones:\c"
72 # zoneadmd puts itself into its own contract so
73 # this service will lose sight of it. We don't
74 # support restart so it is OK for zoneadmd to
75 # to be in an orphaned contract.
77 zoneadm
-z $zone boot
&
79 zoneadm
-z $zone sysboot
&
84 # Wait for all zoneadm processes to finish before allowing the
85 # start method to exit.
88 [ -n "$ZONES" ] && echo .
92 egrep -vs '^#|^global:' /etc
/zones
/index ||
exit 0 # no local zones
93 [ "`zoneadm list`" = "global" ] && exit 0 # no zones running
95 SVC_TIMEOUT
=`svcprop -p stop/timeout_seconds $SMF_FMRI`
98 # First, try shutting down any running zones for which an "init 0" may
101 MAXSHUT
=`expr 3 \* $SVC_TIMEOUT \/ 4` # 3/4 of time to zone shutdown
102 MAXHALT
=`expr $SVC_TIMEOUT \/ 4` # rest of time goes to halt
104 zonelist
=`shutdown_zones`
106 if [ -n "$zonelist" ]; then
108 echo "Shutting down running zones (for up to $MAXSHUT" \
111 for zone
in $zonelist; do
113 zoneadm
-z $zone shutdown
&
117 [ $SHUTDOWN -eq 1 ] && echo "."
119 # Allow time for zones to shutdown cleanly
121 while [ $MAXSHUT -gt 0 -a "`shutdown_zones`" != "" ]; do
122 MAXSHUT
=`expr $MAXSHUT - 1`
123 sleep 1 # wait a bit longer
128 # Second, try halting any non-global zones still running
131 for zone
in `zoneadm list`; do
132 if [ "$zone" != "global" ]; then
133 [ -z "$WAITPIDS" ] &&
134 echo "Zones failed to shutdown; trying to halt " \
135 "(for up to $MAXHALT seconds):\c"
137 zoneadm
-z $zone halt
&
138 WAITPIDS
="$WAITPIDS $!"
141 [ ! -z "$WAITPIDS" ] && echo .
143 # Wait for the 'zoneadm halt' commands to complete. We will let this
144 # run forever, since the restart daemon will eventually kill us off
145 # anyway if the halts do not complete after a certain period of time.
148 # If the halts complete but a zone is still not shutdown, it might
149 # be in a state like 'shutting_down' or 'down'. So we give it some
150 # time to come all the way down.
152 while [ $MAXHALT -gt 0 -a "`zoneadm list`" != "global" ]; do
153 MAXHALT
=`expr $MAXHALT - 1`
154 sleep 1 # wait a bit longer
157 # If there are any remaining file systems in zones, try to unmount them.
161 # Report on zones which failed to shutdown.
163 for zone
in `zoneadm list`; do
164 if [ "$zone" != "global" ]; then
165 echo "Zone '$zone' failed to halt."
168 [ "`zoneadm list`" != "global" ] && exit 1 # zones still running
172 echo "Usage: $0 { start | stop }"