Print this page
6805730 some simple changes would make 'init 5' much faster
6809492 startd shouldn't let hung subprocesses impede shutdown
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/initpkg/shutdown.sh
+++ new/usr/src/cmd/initpkg/shutdown.sh
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 -# Common Development and Distribution License, Version 1.0 only
7 -# (the "License"). You may not use this file except in compliance
8 -# with the License.
6 +# Common Development and Distribution License (the "License").
7 +# You may not use this file except in compliance with the License.
9 8 #
10 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 10 # or http://www.opensolaris.org/os/licensing.
12 11 # See the License for the specific language governing permissions
13 12 # and limitations under the License.
14 13 #
15 14 # When distributing Covered Code, include this CDDL HEADER in each
16 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 16 # If applicable, add the following below this CDDL HEADER, with the
18 17 # fields enclosed by brackets "[]" replaced with your own identifying
19 18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 19 #
21 20 # CDDL HEADER END
22 21 #
23 -# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
22 +# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 23 # Use is subject to license terms.
25 24 #
26 25 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
27 26 # All Rights Reserved
28 27
29 28
30 29
31 -#ident "%Z%%M% %I% %E% SMI"
32 -
33 30 # Sequence performed to change the init state of a machine. Only allows
34 31 # transitions to states 0,1,5,6,s,S (i.e.: down or administrative states).
35 32
36 33 # This procedure checks to see if you are permitted and allows an
37 34 # interactive shutdown. The actual change of state, killing of
38 35 # processes and such are performed by the new init state, say 0,
39 36 # and its /sbin/rc0.
40 37
41 38 usage() {
42 39 echo "Usage: $0 [ -y ] [ -g<grace> ] [ -i<initstate> ] [ message ]"
43 40 exit 1
44 41 }
45 42
46 43 notify() {
47 44 /usr/sbin/wall -a <<-!
48 45 $*
49 46 !
50 47 if [ -x /usr/sbin/showmount -a -x /usr/sbin/rwall ]
51 48 then
52 49 remotes=`/usr/sbin/showmount`
53 50 if [ "X${remotes}" != "X" ]
54 51 then
55 52 /usr/sbin/rwall -q ${remotes} <<-!
56 53 $*
57 54 !
58 55 fi
59 56 fi
60 57 }
61 58
62 59 nologin=/etc/nologin
63 60
64 61 # Set the PATH so that to guarentee behavior of shell built in commands
65 62 # (such as echo).
66 63
67 64 PATH=/usr/sbin:/usr/bin:/sbin
68 65
69 66 # Initial sanity checks:
70 67 # Make sure /usr is mounted
71 68 # Check the user id (only root can run shutdown)
72 69
73 70 if [ ! -d /usr/bin ]
74 71 then
75 72 echo "$0: /usr is not mounted. Mount /usr or use init to shutdown."
76 73 exit 1
77 74 fi
78 75
79 76 if [ -x /usr/bin/id ]
80 77 then
81 78 eval `/usr/bin/id | /usr/bin/sed 's/[^a-z0-9=].*//'`
82 79 if [ "${uid:=0}" -ne 0 ]
83 80 then
84 81 echo "$0: Only root can run $0"
85 82 exit 2
86 83 fi
87 84 else
88 85 echo "$0: can't check user id."
89 86 exit 2
90 87 fi
91 88
92 89 # Get options (defaults immediately below):
93 90
94 91 grace=60
95 92 askconfirmation=yes
96 93 initstate=s
97 94
98 95 while getopts g:i:y? c
99 96 do
100 97 case $c in
101 98 g)
102 99 case $OPTARG in
103 100 *[!0-9]* )
104 101 echo "$0: -g requires a numeric option"
105 102 usage
106 103 ;;
107 104 [0-9]* )
108 105 grace=$OPTARG
109 106 ;;
110 107 esac
111 108 ;;
112 109 i)
113 110 case $OPTARG in
114 111 [Ss0156])
115 112 initstate=$OPTARG
116 113 ;;
117 114 [234abcqQ])
118 115 echo "$0: Initstate $OPTARG is not for system shutdown"
119 116 exit 1
120 117 ;;
121 118 *)
122 119 echo "$0: $OPTARG is not a valid initstate"
123 120 usage
124 121 ;;
125 122 esac
126 123 ;;
127 124 y)
128 125 askconfirmation=
129 126 ;;
130 127 \?) usage
131 128 ;;
|
↓ open down ↓ |
89 lines elided |
↑ open up ↑ |
132 129 esac
133 130 done
134 131 shift `expr $OPTIND - 1`
135 132
136 133 echo '\nShutdown started. \c'
137 134 /usr/bin/date
138 135 echo
139 136
140 137 NODENAME=`uname -n`
141 138
142 -/sbin/sync
143 139 cd /
144 140
145 141 trap "rm $nologin >/dev/null 2>&1 ;exit 1" 1 2 15
146 142
147 143 # If other users are on the system (and any grace period is given), warn them.
148 144
149 145 for i in 7200 3600 1800 1200 600 300 120 60 30 10; do
150 146 if [ ${grace} -gt $i ]
151 147 then
152 148 hours=`/usr/bin/expr ${grace} / 3600`
153 149 minutes=`/usr/bin/expr ${grace} % 3600 / 60`
154 150 seconds=`/usr/bin/expr ${grace} % 60`
155 151 time=""
156 152 if [ ${hours} -gt 1 ]
157 153 then
158 154 time="${hours} hours "
159 155 elif [ ${hours} -eq 1 ]
160 156 then
161 157 time="1 hour "
162 158 fi
163 159 if [ ${minutes} -gt 1 ]
164 160 then
165 161 time="${time}${minutes} minutes "
166 162 elif [ ${minutes} -eq 1 ]
167 163 then
168 164 time="${time}1 minute "
169 165 fi
170 166 if [ ${hours} -eq 0 -a ${seconds} -gt 0 ]
171 167 then
172 168 if [ ${seconds} -eq 1 ]
173 169 then
174 170 time="${time}${seconds} second"
175 171 else
176 172 time="${time}${seconds} seconds"
177 173 fi
178 174 fi
179 175
180 176 (notify \
181 177 "The system ${NODENAME} will be shut down in ${time}
182 178 $*") &
183 179
184 180 pid1=$!
185 181
186 182 rm $nologin >/dev/null 2>&1
187 183 cat > $nologin <<-!
188 184
189 185 NO LOGINS: System going down in ${time}
190 186 $*
191 187
192 188 !
193 189
194 190 /usr/bin/sleep `/usr/bin/expr ${grace} - $i`
195 191 grace=$i
196 192 fi
197 193 done
198 194
199 195 # Confirm that we really want to shutdown.
200 196
201 197 if [ ${askconfirmation} ]
202 198 then
203 199 echo "Do you want to continue? (y or n): \c"
204 200 read b
205 201 if [ "$b" != "y" ]
206 202 then
207 203 notify "False Alarm: The system ${NODENAME} will not be brought down."
208 204 echo 'Shutdown aborted.'
209 205 rm $nologin >/dev/null 2>&1
210 206 exit 1
211 207 fi
212 208 fi
213 209
214 210 # Final shutdown message, and sleep away the final 10 seconds (or less).
215 211
216 212 (notify \
217 213 "THE SYSTEM ${NODENAME} IS BEING SHUT DOWN NOW ! ! !
218 214 Log off now or risk your files being damaged
219 215 $*") &
220 216
221 217 pid2=$!
222 218
223 219 if [ ${grace} -gt 0 ]
224 220 then
225 221 /usr/bin/sleep ${grace}
226 222 fi
227 223
228 224 # Go to the requested initstate.
229 225
230 226
231 227 echo "Changing to init state $initstate - please wait"
232 228
233 229 if [ "$pid1" ] || [ "$pid2" ]
234 230 then
235 231 /usr/bin/kill $pid1 $pid2 > /dev/null 2>&1
236 232 fi
237 233
238 234 /sbin/init ${initstate}
|
↓ open down ↓ |
86 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX