Print this page
7928 Add support for SMF_EXIT_TEMP_TRANSIENT
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/svc/shell/smf_include.sh
+++ new/usr/src/cmd/svc/shell/smf_include.sh
1 1 #!/bin/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.
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
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 2009 Sun Microsystems, Inc. All rights reserved.
24 24 # Use is subject to license terms.
25 25 # Copyright 2015 Nexenta Systems, Inc. All rights reserved.
26 +# Copyright 2017 RackTop Systems.
26 27 #
27 28
28 29 smf_present () {
29 30 [ -r /etc/svc/volatile/repository_door ] && \
30 31 [ ! -f /etc/svc/volatile/repository_door ]
31 32 }
32 33
33 34 smf_clear_env () {
34 35 unset \
35 36 SMF_FMRI \
36 37 SMF_METHOD \
37 38 SMF_RESTARTER \
38 39 SMF_ZONENAME
39 40 }
40 41
41 42 # smf_console
42 43 #
43 44 # Use as "echo message 2>&1 | smf_console". If SMF_MSGLOG_REDIRECT is
44 45 # unset, message will be displayed to console. SMF_MSGLOG_REDIRECT is
45 46 # reserved for future use.
46 47 #
47 48 smf_console () {
48 49 /usr/bin/tee ${SMF_MSGLOG_REDIRECT:-/dev/msglog}
49 50 }
50 51
51 52 # smf_zonename
52 53 #
53 54 # Prints the name of this zone.
54 55
55 56 smf_zonename() {
56 57 echo "${SMF_ZONENAME:=`/sbin/zonename`}"
57 58 }
58 59
59 60 # smf_is_globalzone
60 61 #
61 62 # Returns zero (success) if this is the global zone. 1 otherwise.
62 63 #
63 64 smf_is_globalzone() {
64 65 [ "${SMF_ZONENAME:=`/sbin/zonename`}" = "global" ] && return 0
65 66 return 1
66 67 }
67 68
68 69 # smf_is_nonglobalzone
69 70 #
70 71 # Returns zero (success) if this is not the global zone. 1 otherwise.
71 72 #
72 73 smf_is_nonglobalzone() {
73 74 [ "${SMF_ZONENAME:=`/sbin/zonename`}" != "global" ] && return 0
74 75 return 1
75 76 }
76 77
77 78 # smf_configure_ip
78 79 #
79 80 # Returns zero (success) if this zone needs IP to be configured i.e.
80 81 # the global zone or has an exclusive stack. 1 otherwise.
81 82 #
82 83 smf_configure_ip() {
83 84 [ "${SMF_ZONENAME:=`/sbin/zonename`}" = "global" -o \
84 85 `/sbin/zonename -t` = exclusive ] && return 0
85 86 return 1
86 87 }
87 88
88 89 # smf_dont_configure_ip
89 90 #
90 91 # Inverse of smf_configure_ip
91 92 #
92 93 smf_dont_configure_ip() {
93 94 [ "${SMF_ZONENAME:=`/sbin/zonename`}" != "global" -a \
94 95 `/sbin/zonename -t` = shared ] && return 0
95 96 return 1
96 97 }
97 98
98 99 # smf_dont_configure_vt
99 100 #
100 101 # Returns zero (success) if vt functionality is not to be configured,
101 102 # 1 otherwise.
102 103 #
103 104 smf_dont_configure_vt() {
104 105 [ "${SMF_ZONENAME:=`/sbin/zonename`}" != "global" ] && return 0
105 106 /usr/lib/vtinfo > /dev/null 2>&1
106 107 return $?
107 108 }
108 109
109 110 # smf_is_system_labeled
110 111 #
111 112 # Returns zero (success) if system is labeled (aka Trusted Extensions).
112 113 # 1 otherwise.
113 114 #
114 115 smf_is_system_labeled() {
115 116 [ ! -x /bin/plabel ] && return 1
116 117 /bin/plabel > /dev/null 2>&1
117 118 return $?
118 119 }
119 120
120 121 # smf_netstrategy
121 122 # -> (_INIT_NET_IF, _INIT_NET_STRATEGY)
122 123 #
123 124 # Sets _INIT_NET_IF to the name for the network-booted
124 125 # interface if we are booting from the network. _INIT_NET_STRATEGY is
125 126 # assigned the value of the current network configuration strategy.
126 127 # Valid values for _INIT_NET_STRATEGY are "none", "dhcp", and "rarp".
127 128 #
128 129 # The network boot strategy for a zone is always "none".
129 130 #
130 131 smf_netstrategy () {
131 132 if smf_is_nonglobalzone; then
132 133 _INIT_NET_STRATEGY="none" export _INIT_NET_STRATEGY
133 134 return 0
134 135 fi
135 136
136 137 set -- `/sbin/netstrategy`
137 138 if [ $? -eq 0 ]; then
138 139 [ "$1" = "nfs" ] && \
139 140 _INIT_NET_IF="$2" export _INIT_NET_IF
140 141 _INIT_NET_STRATEGY="$3" export _INIT_NET_STRATEGY
141 142 else
142 143 return 1
143 144 fi
144 145 }
145 146
146 147 #
147 148 # smf_kill_contract CONTRACT SIGNAL WAIT TIMEOUT
148 149 #
149 150 # To be called from stop methods of non-transient services.
150 151 # Sends SIGNAL to the service contract CONTRACT. If the
151 152 # WAIT argument is non-zero, smf_kill_contract will wait
152 153 # until the contract is empty before returning, or until
153 154 # TIMEOUT expires.
154 155 #
155 156 # Example, send SIGTERM to contract 200:
156 157 #
157 158 # smf_kill_contract 200 TERM
158 159 #
159 160 # Since killing a contract with pkill(1) is not atomic,
160 161 # smf_kill_contract will continue to send SIGNAL to CONTRACT
161 162 # every second until the contract is empty. This will catch
162 163 # races between fork(2) and pkill(1).
163 164 #
164 165 # Note that time in this routine is tracked (after being input
165 166 # via TIMEOUT) in 10ths of a second. This is because we want
166 167 # to sleep for short periods of time, and expr(1) is too dumb
167 168 # to do non-integer math.
168 169 #
169 170 # Returns 1 if the contract is invalid.
170 171 # Returns 2 if WAIT is "1", TIMEOUT is > 0, and TIMEOUT expires.
171 172 # Returns 0 on success.
172 173 #
173 174 smf_kill_contract() {
174 175
175 176 time_waited=0
176 177 time_to_wait=$4
177 178
178 179 [ -z "$time_to_wait" ] && time_to_wait=0
179 180
180 181 # convert to 10ths.
181 182 time_to_wait=`/usr/bin/expr $time_to_wait '*' 10`
182 183
183 184 # Verify contract id is valid using pgrep
184 185 /usr/bin/pgrep -c $1 > /dev/null 2>&1
185 186 ret=$?
186 187 if [ $ret -gt 1 ] ; then
187 188 echo "Error, invalid contract \"$1\"" >&2
188 189 return 1
189 190 fi
190 191
191 192 # Return if contract is already empty.
192 193 [ $ret -eq 1 ] && return 0
193 194
194 195 # Kill contract.
195 196 /usr/bin/pkill -$2 -c $1
196 197 if [ $? -gt 1 ] ; then
197 198 echo "Error, could not kill contract \"$1\"" >&2
198 199 return 1
199 200 fi
200 201
201 202 # Return if WAIT is not set or is "0"
202 203 [ -z "$3" ] && return 0
203 204 [ "$3" -eq 0 ] && return 0
204 205
205 206 # If contract does not empty, keep killing the contract to catch
206 207 # any child processes missed because they were forking
207 208 /usr/bin/pgrep -c $1 > /dev/null 2>&1
208 209 while [ $? -eq 0 ] ; do
209 210 # Return 2 if TIMEOUT was passed, and it has expired
210 211 [ "$time_to_wait" -gt 0 -a $time_waited -ge $time_to_wait ] && \
211 212 return 2
212 213
213 214 #
214 215 # At five second intervals, issue the kill again. Note that
215 216 # the sleep time constant (in tenths) must be a factor of 50
216 217 # for the remainder trick to work. i.e. sleeping 2 tenths is
217 218 # fine, but 27 tenths is not.
218 219 #
219 220 remainder=`/usr/bin/expr $time_waited % 50`
220 221 if [ $time_waited -gt 0 -a $remainder -eq 0 ]; then
221 222 /usr/bin/pkill -$2 -c $1
222 223 fi
223 224
224 225 # Wait two tenths, and go again.
225 226 /usr/bin/sleep 0.2
226 227 time_waited=`/usr/bin/expr $time_waited + 2`
227 228 /usr/bin/pgrep -c $1 > /dev/null 2>&1
228 229 done
229 230
230 231 return 0
231 232 }
232 233
233 234 #
234 235 # smf(5) method and monitor exit status definitions
↓ open down ↓ |
199 lines elided |
↑ open up ↑ |
235 236 # SMF_EXIT_ERR_OTHER, although not defined, encompasses all non-zero
236 237 # exit status values.
237 238 #
238 239 SMF_EXIT_OK=0
239 240 SMF_EXIT_ERR_FATAL=95
240 241 SMF_EXIT_ERR_CONFIG=96
241 242 SMF_EXIT_MON_DEGRADE=97
242 243 SMF_EXIT_MON_OFFLINE=98
243 244 SMF_EXIT_ERR_NOSMF=99
244 245 SMF_EXIT_ERR_PERM=100
246 +SMF_EXIT_TEMP_TRANSIENT=101
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX