Print this page
Bring back LX zones.
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/zoneadm/svc-zones
+++ new/usr/src/cmd/zoneadm/svc-zones
1 1 #!/sbin/sh
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 #
23 23 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
24 24
25 25 . /lib/svc/share/smf_include.sh
26 26
27 27 #
28 28 # Return a list of running, non-global zones for which a shutdown via
29 29 # "/sbin/init 0" may work (typically only Solaris zones.)
30 30 #
31 31 shutdown_zones()
32 32 {
33 33 zoneadm list -p | nawk -F: '{
34 - if ($2 != "global") {
34 + if (($5 != "lx") && ($2 != "global")) {
35 35 print $2
36 36 }
37 37 }'
38 38 }
39 39
40 40 [ ! -x /usr/sbin/zoneadm ] && exit 0 # SUNWzoneu not installed
41 41
42 42 if [ -z "$SMF_FMRI" ]; then
43 43 echo "this script can only be invoked by smf(5)"
44 44 exit $SMF_EXIT_ERR_NOSMF
45 45 fi
46 46
47 47 # Make sure working directory is / to prevent unmounting problems.
48 48 cd /
49 49 PATH=/usr/sbin:/usr/bin; export PATH
50 50
51 51 case "$1" in
52 52 'start')
53 53 egrep -vs '^#|^global:' /etc/zones/index || exit 0 # no local zones
54 54
55 55 #
56 56 # Boot the installed zones for which the "autoboot" zone property is
57 57 # set and invoke the sysboot hook for all other installed zones.
58 58 #
59 59 ZONES=""
60 60 for zone in `zoneadm list -pi | nawk -F: '{
61 61 if ($3 == "installed") {
62 62 print $2
63 63 }
64 64 }'`; do
65 65 zonecfg -z $zone info autoboot | grep "true" >/dev/null 2>&1
66 66 if [ $? -eq 0 ]; then
67 67 [ -z "$ZONES" ] && echo "Booting zones:\c"
68 68 ZONES=yes
69 69 echo " $zone\c"
70 70 #
71 71 # zoneadmd puts itself into its own contract so
72 72 # this service will lose sight of it. We don't
73 73 # support restart so it is OK for zoneadmd to
74 74 # to be in an orphaned contract.
75 75 #
76 76 zoneadm -z $zone boot &
77 77 else
78 78 zoneadm -z $zone sysboot &
79 79 fi
80 80 done
81 81
82 82 #
83 83 # Wait for all zoneadm processes to finish before allowing the
84 84 # start method to exit.
85 85 #
86 86 wait
87 87 [ -n "$ZONES" ] && echo .
88 88 ;;
89 89
90 90 'stop')
91 91 egrep -vs '^#|^global:' /etc/zones/index || exit 0 # no local zones
92 92 [ "`zoneadm list`" = "global" ] && exit 0 # no zones running
93 93
94 94 SVC_TIMEOUT=`svcprop -p stop/timeout_seconds $SMF_FMRI`
95 95
96 96 #
97 97 # First, try shutting down any running zones for which an "init 0" may
98 98 # work.
99 99 #
100 100 MAXSHUT=`expr 3 \* $SVC_TIMEOUT \/ 4` # 3/4 of time to zone shutdown
101 101 MAXHALT=`expr $SVC_TIMEOUT \/ 4` # rest of time goes to halt
102 102
103 103 zonelist=`shutdown_zones`
104 104
105 105 if [ -n "$zonelist" ]; then
106 106 SHUTDOWN=0
107 107 echo "Shutting down running zones (for up to $MAXSHUT" \
108 108 "seconds):\c"
109 109
110 110 for zone in $zonelist; do
111 111 echo " $zone\c"
112 112 zlogin -S $zone /sbin/init 0 < /dev/null >&0 2>&0 &
113 113 SHUTDOWN=1
114 114 done
115 115
116 116 [ $SHUTDOWN -eq 1 ] && echo "."
117 117
118 118 # Allow time for zones to shutdown cleanly
119 119
120 120 while [ $MAXSHUT -gt 0 -a "`shutdown_zones`" != "" ]; do
121 121 MAXSHUT=`expr $MAXSHUT - 1`
122 122 sleep 1 # wait a bit longer
123 123 done
124 124 fi
125 125
126 126 #
127 127 # Second, try halting any non-global zones still running
128 128 #
129 129 WAITPIDS=""
130 130 for zone in `zoneadm list`; do
131 131 if [ "$zone" != "global" ]; then
132 132 [ -z "$WAITPIDS" ] &&
133 133 echo "Zones failed to shutdown; trying to halt " \
134 134 "(for up to $MAXHALT seconds):\c"
135 135 echo " $zone\c"
136 136 zoneadm -z $zone halt &
137 137 WAITPIDS="$WAITPIDS $!"
138 138 fi
139 139 done
140 140 [ ! -z "$WAITPIDS" ] && echo .
141 141
142 142 # Wait for the 'zoneadm halt' commands to complete. We will let this
143 143 # run forever, since the restart daemon will eventually kill us off
144 144 # anyway if the halts do not complete after a certain period of time.
145 145 wait $WAITPIDS
146 146
147 147 # If the halts complete but a zone is still not shutdown, it might
148 148 # be in a state like 'shutting_down' or 'down'. So we give it some
149 149 # time to come all the way down.
150 150
151 151 while [ $MAXHALT -gt 0 -a "`zoneadm list`" != "global" ]; do
152 152 MAXHALT=`expr $MAXHALT - 1`
153 153 sleep 1 # wait a bit longer
154 154 done
155 155
156 156 # If there are any remaining file systems in zones, try to unmount them.
157 157 umountall -Z
158 158
159 159 #
160 160 # Report on zones which failed to shutdown.
161 161 #
162 162 for zone in `zoneadm list`; do
163 163 if [ "$zone" != "global" ]; then
164 164 echo "Zone '$zone' failed to halt."
165 165 fi
166 166 done
167 167 [ "`zoneadm list`" != "global" ] && exit 1 # zones still running
168 168 ;;
169 169
170 170 *)
171 171 echo "Usage: $0 { start | stop }"
172 172 exit 1
173 173 ;;
174 174 esac
175 175 exit 0
↓ open down ↓ |
131 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX