4 #
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.
8 #
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.
13 #
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]
19 #
20 # CDDL HEADER END
21 #
22 #
23 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24
25 . /lib/svc/share/smf_include.sh
26
27 #
28 # Return a list of running, non-global zones for which a shutdown via
29 # "/sbin/init 0" may work (typically only Solaris zones.)
30 #
31 shutdown_zones()
32 {
33 zoneadm list -p | nawk -F: '{
34 if ($2 != "global") {
35 print $2
36 }
37 }'
38 }
39
40 [ ! -x /usr/sbin/zoneadm ] && exit 0 # SUNWzoneu not installed
41
42 if [ -z "$SMF_FMRI" ]; then
43 echo "this script can only be invoked by smf(5)"
92 [ "`zoneadm list`" = "global" ] && exit 0 # no zones running
93
94 SVC_TIMEOUT=`svcprop -p stop/timeout_seconds $SMF_FMRI`
95
96 #
97 # First, try shutting down any running zones for which an "init 0" may
98 # work.
99 #
100 MAXSHUT=`expr 3 \* $SVC_TIMEOUT \/ 4` # 3/4 of time to zone shutdown
101 MAXHALT=`expr $SVC_TIMEOUT \/ 4` # rest of time goes to halt
102
103 zonelist=`shutdown_zones`
104
105 if [ -n "$zonelist" ]; then
106 SHUTDOWN=0
107 echo "Shutting down running zones (for up to $MAXSHUT" \
108 "seconds):\c"
109
110 for zone in $zonelist; do
111 echo " $zone\c"
112 zlogin -S $zone /sbin/init 0 < /dev/null >&0 2>&0 &
113 SHUTDOWN=1
114 done
115
116 [ $SHUTDOWN -eq 1 ] && echo "."
117
118 # Allow time for zones to shutdown cleanly
119
120 while [ $MAXSHUT -gt 0 -a "`shutdown_zones`" != "" ]; do
121 MAXSHUT=`expr $MAXSHUT - 1`
122 sleep 1 # wait a bit longer
123 done
124 fi
125
126 #
127 # Second, try halting any non-global zones still running
128 #
129 WAITPIDS=""
130 for zone in `zoneadm list`; do
131 if [ "$zone" != "global" ]; then
132 [ -z "$WAITPIDS" ] &&
|
4 #
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.
8 #
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.
13 #
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]
19 #
20 # CDDL HEADER END
21 #
22 #
23 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 # Copyright 2014 Nexenta Systems, Inc. All rights reserved.
25
26 . /lib/svc/share/smf_include.sh
27
28 #
29 # Return a list of running, non-global zones for which a shutdown via
30 # "/sbin/init 0" may work (typically only Solaris zones.)
31 #
32 shutdown_zones()
33 {
34 zoneadm list -p | nawk -F: '{
35 if ($2 != "global") {
36 print $2
37 }
38 }'
39 }
40
41 [ ! -x /usr/sbin/zoneadm ] && exit 0 # SUNWzoneu not installed
42
43 if [ -z "$SMF_FMRI" ]; then
44 echo "this script can only be invoked by smf(5)"
93 [ "`zoneadm list`" = "global" ] && exit 0 # no zones running
94
95 SVC_TIMEOUT=`svcprop -p stop/timeout_seconds $SMF_FMRI`
96
97 #
98 # First, try shutting down any running zones for which an "init 0" may
99 # work.
100 #
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
103
104 zonelist=`shutdown_zones`
105
106 if [ -n "$zonelist" ]; then
107 SHUTDOWN=0
108 echo "Shutting down running zones (for up to $MAXSHUT" \
109 "seconds):\c"
110
111 for zone in $zonelist; do
112 echo " $zone\c"
113 zoneadm -z $zone shutdown &
114 SHUTDOWN=1
115 done
116
117 [ $SHUTDOWN -eq 1 ] && echo "."
118
119 # Allow time for zones to shutdown cleanly
120
121 while [ $MAXSHUT -gt 0 -a "`shutdown_zones`" != "" ]; do
122 MAXSHUT=`expr $MAXSHUT - 1`
123 sleep 1 # wait a bit longer
124 done
125 fi
126
127 #
128 # Second, try halting any non-global zones still running
129 #
130 WAITPIDS=""
131 for zone in `zoneadm list`; do
132 if [ "$zone" != "global" ]; then
133 [ -z "$WAITPIDS" ] &&
|