1 #! /usr/bin/ksh -p
2 #
3 # CDDL HEADER START
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 #
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # start __stf_assertion__
30 #
31 # ASSERTION: methods_018
32 # DESCRIPTION:
33 # If one of a service instance's processes in the degraded state
34 # dumps core than svc.startd should attempt to restart the service.
35 # The service has more than one process.
36 #
37 # end __stf_assertion__
38 #
39
40 . ${STF_TOOLS}/include/stf.kshlib
41 . ${STF_SUITE}/include/gltest.kshlib
42 . ${STF_SUITE}/include/svc.startd_config.kshlib
43 . ${STF_SUITE}/tests/include/svc.startd_fileops.kshlib
44 . ${STF_SUITE}/tests/svc.startd/include/svc.startd_common.kshlib
45
46 typeset service_setup=0
47 function cleanup {
48 rm -f $svcadm_errfile $monitor_errfile
49 [[ "$pps" = "disabled" ]] && coreadm -d proc-setid 2>/dev/null
50 common_cleanup
51 return $?
52 }
53
54 trap cleanup 0 1 2 15
55
56 readonly ME=$(whence -p ${0})
57 readonly MYLOC=$(dirname ${ME})
58
59 DATA=$MYLOC
60
61 registration_template=$DATA/service_018.xml
62
63 extract_assertion_info $ME
64
65 # make sure that the svc.startd is running
66 verify_daemon
67 if [ $? -ne 0 ]; then
68 print -- "--DIAG: $assertion: svc.startd is not executing. Cannot "
69 print -- " continue"
70 exit $STF_UNRESOLVED
71 fi
72
73 # Make sure the environment is clean - the test service isn't running
74 print -- "--INFO: Cleanup any old $test_FMRI state"
75 service_cleanup $test_service
76 rm -f $service_state
77 if [ $? -ne 0 ]; then
78 print -- "--DIAG: $assertion: unable to clean up any pre-existing state"
79 exit $STF_UNRESOLVED
80 fi
81
82 pps=$(env LC_ALL=C coreadm | grep 'per-process setid' | awk '{print $NF }')
83
84 if [ -z "$pps" ]; then
85 print -- "--DIAG: could not get state from coreadm"
86 exit $STF_UNRESOLVED
87 fi
88
89 if [ "$pps" = "disabled" ]; then
90 print -- "--INFO: Enabling per-process setid coredumps"
91 coreadm -e proc-setid
92 if [ $? -ne 0 ]; then
93 print -- "--DIAG: Could not enable per-process setid coredumps"
94 exit $STF_UNRESOLVED
95 fi
96 fi
97
98 print -- "--INFO: generating monitor returncode file"
99 echo "returncode $SVC_DEGRADED" >$monitor_errfile
100 if [ $? -ne 0 ]; then
101 print -- "--DIAG: $assertion: unable to write to $monitor_errfile"
102 exit $STF_UNRESOLVED
103 fi
104
105 print -- "--INFO: generating manifest for importation into repository"
106 manifest_generate $registration_template \
107 TEST_SERVICE=$test_service \
108 TEST_INSTANCE=$test_instance \
109 SERVICE_APP=$service_app \
110 LOGFILE=$service_log \
111 STATEFILE=$service_state \
112 MONITOR_FILE=$monitor_errfile \
113 > $registration_file
114
115 print -- "--INFO: Importing service into repository"
116 manifest_purgemd5 $registration_file
117 svccfg -v import $registration_file >$svccfg_errfile 2>&1
118 if [ $? -ne 0 ]; then
119 print -- "--DIAG: $assertion: Unable to import the service $test_FMRI"
120 print -- " error messages from svccfg: \"$(cat $svccfg_errfile)\""
121 exit $STF_UNRESOLVED
122 fi
123 service_setup=1
124
125 print -- "--INFO: enabling $test_FMRI"
126 svcadm enable $test_FMRI
127 if [ $? -ne 0 ]; then
128 print -- "--DIAG: $assertion: enable command of $test_FMRI failed"
129 exit $STF_FAIL
130 fi
131
132 print -- "--INFO: waiting for execution of start method"
133 service_wait_method $test_FMRI start
134 if [ $? -ne 0 ]; then
135 print -- "--DIAG: $assertion: Service $test_FMRI didn't issue start"
136 exit $STF_UNRESOLVED
137 fi
138
139 typeset rc=0
140 print -- "--INFO: setting service to degraded state"
141 svcadm mark degraded $test_FMRI
142 rc=$?
143 if [ $rc -ne 0 ]; then
144 print -- "--DIAG: $assertion: svcadm failed to mark $test_FMRI degraded
145 EXPECTED: 'svcadm mark degraded $test_FMRI' returned 0
146 OBSERVED: 'svcadm mark degraded $test_FMRI' returned $rc"
147 exit $STF_FAIL
148 fi
149
150 print -- "--INFO: Validating service reaches degraded mode"
151 service_wait_state $test_FMRI degraded
152 if [ $? -ne 0 ]; then
153 print -- "--DIAG: $assertion: Service $test_FMRI didn't"
154 print -- " transition to degraded state"
155 print -- " current state: `svcprop -p restarter/state $test_FMRI`"
156 exit $STF_FAIL
157 fi
158
159 print -- "--INFO: get the services to generate core files into log dir"
160 PIDS=`service_getpids -s $test_service -i $test_instance -f $service_state`
161 print -- "--INFO: child pids are: $PIDS"
162 coreadm -p "$RUNDIR/core.%p" $PIDS
163 typeset pid1=
164 typeset pid2=
165
166 echo $PIDS | read pid1 pid2
167
168 if [ -z "$pid2" ]; then
169 print -- "--DIAG: there should have been 2 child processes"
170 exit $STF_FAIL
171 fi
172
173 print -- "--INFO: make the service core dump... use dummy method"
174 $service_app -s $test_service -i $test_instance \
175 -m trigger -r "triggerservicesegv 1"
176
177 print -- "--INFO: removing reason for monitor returning degraded"
178 echo "" > $monitor_errfile
179 if [ $? -ne 0 ]; then
180 print -- "--DIAG: could not remove reason for degraded state"
181 exit $STF_UNRESOLVED
182 fi
183
184 print -- "--INFO: checking for core file from pid $pid2"
185 file_wait_exist $RUNDIR/core.$pid2
186 if [ $? -ne 0 ]; then
187 print -- "--DIAG: core file for service not found"
188 exit $STF_FAIL
189 fi
190 # blow it away... we actually don't care about the contents
191 rm -f $RUNDIR/core.$pid2
192
193 print -- "--INFO: Waiting for service's start method"
194 service_wait_method $test_FMRI start
195 if [ $? -ne 0 ]; then
196 print -- "--DIAG: $assertion: didn't issue start method"
197 exit $STF_FAIL
198 fi
199
200 print -- "--INFO: verifying that pid $pid1 is not executing"
201 kill -0 $pid1 2>/dev/null
202 if [ $? -eq 0 ]; then
203 print -- "--DIAG: $assertion: startd didn't kill other service process"
204 exit $STF_FAIL
205 fi
206
207 print -- "--INFO: Waiting for service to reach online state"
208 service_wait_state $test_FMRI online
209 if [ $? -ne 0 ]; then
210 print -- "--DIAG: $assertion: service $test_FMRI didn't"
211 print -- " come online"
212 exit $STF_FAIL
213 fi
214
215 print -- "--INFO: Cleaning up service"
216 cleanup
217
218 exit $STF_PASS