1 kumpf 1.1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 kumpf 1.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <Pegasus/Common/Config.h>
35 #include <Pegasus/Common/Constants.h>
36 #include <Pegasus/Common/Logger.h>
37 #include <Pegasus/Common/System.h>
38 #include <Pegasus/Common/Tracer.h>
39 #include <Pegasus/Client/CIMClient.h>
40 #include <Service/ServerShutdownClient.h>
41
42 PEGASUS_USING_STD;
43 kumpf 1.1
44 PEGASUS_NAMESPACE_BEGIN
45
46 ServerShutdownClient::ServerShutdownClient(
47 ServerRunStatus* serverRunStatus)
48 : _serverRunStatus(serverRunStatus)
49 {
50 }
51
52 ServerShutdownClient::~ServerShutdownClient()
53 {
54 }
55
56 //
57 // Waits until either the CIM Server has terminated, or the shutdown timeout
58 // has expired. If the shutdown timeout has expired, and the CIM Server is
59 // still running, kills the cimserver process.
60 //
61 void ServerShutdownClient::_waitForTerminationOrTimeout(Uint32 maxWaitTime)
62 {
63 //
64 kumpf 1.1 // If the CIM Server is still running, and the shutdown timeout has not
65 // expired, loop and wait one second until either the CIM Server has
66 // terminated, or the shutdown timeout has expired
67 //
68 Boolean running = _serverRunStatus->isServerRunning();
69 while (running && (maxWaitTime > 0))
70 {
71 System::sleep(1);
72 running = _serverRunStatus->isServerRunning();
73 maxWaitTime--;
74 }
75
76 //
77 // If the shutdown timeout has expired, and the CIM Server is still
78 // running, kill the cimserver process
79 //
80 if (running)
81 {
82 Boolean wasKilled = _serverRunStatus->kill();
83
84 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
85 kumpf 1.1 || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_SOLARIS) \
86 || defined (PEGASUS_OS_VMS)
87 if (wasKilled)
88 {
|
94 kumpf 1.1 cout << MessageLoader::getMessage(parms) << endl;
95 exit (0);
96 }
97 #endif
98 }
99 }
100
101 void ServerShutdownClient::shutdown(Uint32 timeoutValue)
102 {
103 //
104 // Create CIMClient object
105 //
106 CIMClient client;
107
108 //
109 // Get local host name
110 //
111 String hostStr = System::getHostName();
112
113 //
114 // open connection to CIMOM
115 kumpf 1.1 //
116 try
117 {
118 client.connectLocal();
119
120 //
121 // set client timeout to 2 seconds
122 //
123 client.setTimeout(2000);
124 }
125 catch(Exception&)
126 {
127 MessageLoaderParms parms(
128 "src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
129 "Unable to connect to CIM Server. CIM Server may not be running.");
130 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
131 PEGASUS_STD(endl);
132 exit(1);
133 }
134
135 try
136 kumpf 1.1 {
137 //
138 // construct CIMObjectPath
139 //
140 String referenceStr = "//";
141 referenceStr.append(hostStr);
142 referenceStr.append("/");
143 referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
144 referenceStr.append(":");
145 referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
146 CIMObjectPath reference(referenceStr);
147
148 //
149 // issue the invokeMethod request on the shutdown method
150 //
151 Array<CIMParamValue> inParams;
152 Array<CIMParamValue> outParams;
153
154 // set force option to true for now
155 inParams.append(CIMParamValue("force",
156 CIMValue(Boolean(true))));
157 kumpf 1.1
158 inParams.append(CIMParamValue("timeout",
159 CIMValue(Uint32(timeoutValue))));
160
161 CIMValue retValue = client.invokeMethod(
162 PEGASUS_NAMESPACENAME_SHUTDOWN,
163 reference,
164 "shutdown",
165 inParams,
166 outParams);
167 }
168 catch(CIMException& e)
169 {
170 //l10n - TODO
|
207 kumpf 1.1 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
208 PEGASUS_STD(endl);
209 }
210 exit(1);
211 }
212 catch(Exception&)
213 {
214 //
215 // This may mean that the CIM Server has terminated, causing this
216 // client to get a "Empty HTTP response message" exception. It may
217 // also mean that the CIM Server is taking longer than 2 seconds
218 // (client timeout value) to terminate, causing this client to
219 // timeout with a "connection timeout" exception.
220 //
221 // Wait until either the CIM Server has terminated, or the shutdown
222 // timeout has expired. If the timeout has expired and the CIM Server
223 // is still running, kill the cimserver process.
224 //
225 _waitForTerminationOrTimeout(timeoutValue - 2);
226 return;
227 }
228 kumpf 1.1
229 //
230 // InvokeMethod succeeded.
231 // Wait until either the CIM Server has terminated, or the shutdown
232 // timeout has expired. If the timeout has expired and the CIM Server
233 // is still running, kill the cimserver process.
234 //
235 _waitForTerminationOrTimeout(timeoutValue);
236 }
237
238 PEGASUS_NAMESPACE_END
|