1 karl 1.149 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.32 //
|
3 karl 1.141 // 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 karl 1.121 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.141 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.149 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.32 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.58 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.32 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
|
18 david.dillard 1.165 //
|
19 kumpf 1.58 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.32 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.58 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.32 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Brasher (mbrasher@bmc.com)
31 //
|
32 david.dillard 1.165 // Modified By: Mike Day (mdday@us.ibm.com)
33 // Karl Schopmeyer (k.schopmeyer@opengroup.org)
34 // Nag Boranna (nagaraja_boranna@hp.com)
35 // Jenny Yu (jenny_yu@hp.com)
36 // Sushma Fernandes (sushma_fernandes@hp.com)
|
37 kumpf 1.72 // Carol Ann Krug Graves, Hewlett-Packard Company
|
38 david.dillard 1.165 // (carolann_graves@hp.com)
39 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
40 // Dave Rosckes (rosckes@us.ibm.com)
41 // Humberto Rivero (hurivero@us.ibm.com)
42 // Steve Hills (steve.hills@ncr.com)
|
43 gs.keenan 1.150 // Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
|
44 david.dillard 1.165 // Amit K Arora, IBM (amitarora@in.ibm.com) - pep 167
45 // Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2555
46 // Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2032
47 // Heather Sterling, IBM (hsterl@us.ibm.com) - PEP#222
48 // Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#3452
49 // David Dillard, VERITAS Software Corp.
50 // (david.dillard@veritas.com)
|
51 joyce.j 1.160 //
|
52 mike 1.32 //%/////////////////////////////////////////////////////////////////////////////
53
54
55 //////////////////////////////////////////////////////////////////////
56 //
57 // Notes on deamon operation (Unix) and service operation (Win 32):
58 //
|
59 david.dillard 1.165 // To run pegasus as a daemon on Unix platforms:
|
60 mike 1.32 //
|
61 kumpf 1.60 // cimserver
|
62 mike 1.32 //
|
63 kumpf 1.60 // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
64 // property to false:
65 //
66 // cimserver daemon=false
67 //
|
68 david.dillard 1.165 // The daemon config property has no effect on windows operation.
|
69 mike 1.32 //
|
70 mike 1.35 // To shutdown pegasus, use the -s option:
|
71 david.dillard 1.165 //
72 // cimserver -s
|
73 mike 1.35 //
|
74 mike 1.32 // To run pegasus as an NT service, there are FOUR different possibilities:
75 //
|
76 david.dillard 1.165 // To INSTALL the Pegasus service,
|
77 mike 1.32 //
78 // cimserver -install
79 //
|
80 david.dillard 1.165 // To REMOVE the Pegasus service,
|
81 mike 1.32 //
82 // cimserver -remove
83 //
|
84 david.dillard 1.165 // To START the Pegasus service,
|
85 mike 1.32 //
86 // net start cimserver
|
87 s.hills 1.117 // or
88 // cimserver -start
|
89 mike 1.32 //
|
90 david.dillard 1.165 // To STOP the Pegasus service,
|
91 mike 1.32 //
92 // net stop cimserver
|
93 s.hills 1.117 // or
94 // cimserver -stop
|
95 mike 1.32 //
|
96 david.dillard 1.165 // Alternatively, you can use the windows service manager. Pegasus shows up
|
97 mike 1.32 // in the service database as "Pegasus CIM Object Manager"
98 //
99 // Mike Day, mdday@us.ibm.com
|
100 david.dillard 1.165 //
|
101 mike 1.32 //////////////////////////////////////////////////////////////////////
102
103
|
104 mike 1.35 #include <Pegasus/Common/Config.h>
|
105 kumpf 1.59 #include <Pegasus/Common/Constants.h>
|
106 mike 1.35 #include <cassert>
|
107 mike 1.32 #include <cstdlib>
108 #include <Pegasus/Common/FileSystem.h>
|
109 mike 1.35 #include <Pegasus/Common/Monitor.h>
|
110 mike 1.32 #include <Pegasus/Common/PegasusVersion.h>
111 #include <Pegasus/Common/Logger.h>
112 #include <Pegasus/Common/System.h>
|
113 mike 1.35 #include <Pegasus/Common/Tracer.h>
114 #include <Pegasus/Config/ConfigManager.h>
115 #include <Pegasus/Client/CIMClient.h>
116 #include <Pegasus/Server/ShutdownService.h>
|
117 h.sterling 1.153 #include <Pegasus/Server/CIMServer.h>
118 #include <Service/ServerProcess.h>
|
119 mike 1.32
|
120 chuck 1.155 #if defined(PEGASUS_OS_OS400)
121 # include "vfyptrs.cinc"
122 # include "OS400ConvertChar.h"
123 #endif
124
|
125 kumpf 1.119 PEGASUS_USING_PEGASUS;
126 PEGASUS_USING_STD;
127
|
128 h.sterling 1.153 #define PEGASUS_PROCESS_NAME "cimserver";
|
129 mike 1.32
|
130 h.sterling 1.153 //Windows service variables are not defined elsewhere in the product
131 //enable ability to override these
132 #ifndef PEGASUS_SERVICE_NAME
133 #define PEGASUS_SERVICE_NAME "Pegasus CIM Object Manager";
|
134 chuck 1.66 #endif
|
135 h.sterling 1.153 #ifndef PEGASUS_SERVICE_DESCRIPTION
136 #define PEGASUS_SERVICE_DESCRIPTION "Pegasus CIM Object Manager Service";
|
137 mike 1.32 #endif
138
|
139 h.sterling 1.153 class CIMServerProcess : public ServerProcess
140 {
141 public:
142
143 CIMServerProcess(void)
144 {
145 cimserver_set_process(this);
146 }
147
148 virtual ~CIMServerProcess(void)
149 {
150 }
151
152 //defined in PegasusVersion.h
153 virtual const char* getProductName() const
154 {
155 return PEGASUS_PRODUCT_NAME;
156 }
157
158 virtual const char* getExtendedName() const
159 {
160 h.sterling 1.153 return PEGASUS_SERVICE_NAME;
161 }
162
163 virtual const char* getDescription() const
164 {
165 return PEGASUS_SERVICE_DESCRIPTION;
166 }
|
167 david.dillard 1.165
|
168 h.sterling 1.153 //defined in PegasusVersion.h
169 virtual const char* getVersion() const
170 {
171 return PEGASUS_PRODUCT_VERSION;
172 }
173
174 virtual const char* getProcessName() const
175 {
176 return PEGASUS_PROCESS_NAME;
177 }
178
179 //defined in ConfigFileDir.h
180 virtual const char* getPIDFileName() const
181 {
182 return CIMSERVER_START_FILE;
183 }
184
185 int cimserver_run(int argc, char** argv, bool shutdownOption);
186
187 void cimserver_stop(void);
188 };
189 h.sterling 1.153
190 AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
191 static CIMServer* _cimServer = 0;
|
192 konrad.r 1.163 static Monitor* _monitor = 0;
|
193 konrad.r 1.166 static Thread* dummyInitialThread = 0;
|
194 mike 1.35 //
195 // The command name.
196 //
197 static const char COMMAND_NAME [] = "cimserver";
198
199 //
200 // The constant defining usage string.
201 //
202 static const char USAGE [] = "Usage: ";
203
204 /**
205 Constants representing the command line options.
206 */
207 static const char OPTION_VERSION = 'v';
208
209 static const char OPTION_HELP = 'h';
210
211 static const char OPTION_HOME = 'D';
212
213 static const char OPTION_SHUTDOWN = 's';
214
|
215 a.arora 1.142 static const char LONG_HELP [] = "help";
216
217 static const char LONG_VERSION [] = "version";
218
|
219 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
220 static const char OPTION_BINDVERBOSE = 'X';
221 #endif
222
|
223 kumpf 1.54 static const String PROPERTY_TIMEOUT = "shutdownTimeout";
|
224 mike 1.35
225 ConfigManager* configManager;
226
|
227 mike 1.32 /** GetOptions function - This function defines the Options Table
|
228 mike 1.35 and sets up the options from that table using the config manager.
|
229 mike 1.32 */
230 void GetOptions(
|
231 mike 1.35 ConfigManager* cm,
|
232 mike 1.32 int& argc,
|
233 s.hills 1.117 char** argv)
|
234 mike 1.32 {
|
235 mike 1.35 try
|
236 mike 1.32 {
|
237 kumpf 1.38 cm->mergeConfigFiles();
|
238 mike 1.33
|
239 mike 1.35 cm->mergeCommandLine(argc, argv);
240 }
|
241 kumpf 1.122 catch (NoSuchFile&)
|
242 mike 1.35 {
|
243 kumpf 1.122 throw;
|
244 mike 1.35 }
|
245 kumpf 1.122 catch (FileNotReadable&)
|
246 mike 1.35 {
|
247 kumpf 1.122 throw;
|
248 mike 1.35 }
|
249 kumpf 1.122 catch (CannotRenameFile&)
|
250 mike 1.35 {
|
251 kumpf 1.122 throw;
|
252 mike 1.35 }
|
253 kumpf 1.122 catch (ConfigFileSyntaxError&)
|
254 mike 1.35 {
|
255 kumpf 1.122 throw;
|
256 mike 1.35 }
|
257 kumpf 1.122 catch(UnrecognizedConfigProperty&)
|
258 mike 1.35 {
|
259 kumpf 1.122 throw;
|
260 mike 1.35 }
|
261 kumpf 1.122 catch(InvalidPropertyValue&)
|
262 mike 1.35 {
|
263 kumpf 1.122 throw;
|
264 mike 1.35 }
|
265 kumpf 1.123 catch (CannotOpenFile&)
266 {
267 throw;
268 }
|
269 mike 1.32 }
270
271 /* PrintHelp - This is temporary until we expand the options manager to allow
272 options help to be defined with the OptionRow entries and presented from
273 those entries.
274 */
275 void PrintHelp(const char* arg0)
276 {
|
277 mike 1.35 String usage = String (USAGE);
278 usage.append (COMMAND_NAME);
279 usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
280 usage.append (" options\n");
|
281 a.arora 1.142 usage.append (" -v, --version - displays CIM Server version number\n");
282 usage.append (" -h, --help - prints this help message\n");
|
283 humberto 1.97 usage.append (" -s - shuts down CIM Server\n");
|
284 kumpf 1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
285 usage.append (" -D [home] - sets pegasus home directory\n");
|
286 humberto 1.97 #endif
287 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
288 joyce.j 1.148 usage.append (" -install [name] - installs pegasus as a Windows Service\n");
|
289 humberto 1.97 usage.append (" [name] is optional and overrides the\n");
290 usage.append (" default CIM Server Service Name\n");
|
291 joyce.j 1.148 usage.append (" -remove [name] - removes pegasus as a Windows Service\n");
|
292 humberto 1.97 usage.append (" [name] is optional and overrides the\n");
293 usage.append (" default CIM Server Service Name\n");
|
294 joyce.j 1.148 usage.append (" -start [name] - starts pegasus as a Windows Service\n");
|
295 humberto 1.97 usage.append (" [name] is optional and overrides the\n");
296 usage.append (" default CIM Server Service Name\n");
|
297 joyce.j 1.148 usage.append (" -stop [name] - stops pegasus as a Windows Service\n");
|
298 humberto 1.97 usage.append (" [name] is optional and overrides the\n");
299 usage.append (" default CIM Server Service Name\n\n");
300 #endif
301 usage.append (" configProperty=value\n");
302 usage.append (" - sets CIM Server configuration property\n");
303
304 cout << endl;
|
305 h.sterling 1.153 cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;
|
306 humberto 1.97 cout << endl;
|
307 david.dillard 1.165
|
308 humberto 1.97 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
309 humberto 1.104 MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
|
310 kumpf 1.152 #elif defined(PEGASUS_USE_RELEASE_DIRS)
|
311 kumpf 1.138 MessageLoaderParms parms("src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);
|
312 humberto 1.97 #else
|
313 kumpf 1.138 MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
|
314 humberto 1.97 #endif
315 cout << MessageLoader::getMessage(parms) << endl;
|
316 mike 1.35 }
317
|
318 h.sterling 1.156 //This needs to be called at various points in the code depending on the platform and error conditions.
319 //We need to delete the _cimServer reference on exit in order for the destructors to get called.
320 void deleteCIMServer()
321 {
322 if (_cimServer)
323 {
324 delete _cimServer;
325 _cimServer = 0;
326 }
|
327 konrad.r 1.163 if (_monitor)
328 {
329 delete _monitor;
330 }
|
331 konrad.r 1.166 if (dummyInitialThread)
332 {
333 Thread::clearLanguages();
334 delete dummyInitialThread;
335 }
|
336 h.sterling 1.156 }
337
|
338 chuck 1.96 // l10n
339 //
340 // Dummy function for the Thread object associated with the initial thread.
341 // Since the initial thread is used to process CIM requests, this is
342 // needed to localize the exceptions thrown during CIM request processing.
|
343 david.dillard 1.165 // Note: This function should never be called!
344 //
|
345 chuck 1.96 PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
346 {
|
347 david.dillard 1.165 return((PEGASUS_THREAD_RETURN)0);
|
348 chuck 1.96 }
349
|
350 kumpf 1.52 void shutdownCIMOM(Uint32 timeoutValue)
|
351 mike 1.35 {
352 //
353 // Create CIMClient object
354 //
|
355 kumpf 1.42 CIMClient client;
|
356 mike 1.35
357 //
|
358 kumpf 1.53 // Get local host name
|
359 mike 1.35 //
360 String hostStr = System::getHostName();
361
362 //
|
363 david.dillard 1.165 // open connection to CIMOM
|
364 mike 1.35 //
365 try
366 {
|
367 kumpf 1.43 client.connectLocal();
|
368 kumpf 1.52
369 //
|
370 kumpf 1.63 // set client timeout to 2 seconds
|
371 kumpf 1.52 //
|
372 kumpf 1.71 client.setTimeout(2000);
|
373 mike 1.35 }
|
374 s.hills 1.117 catch(Exception&)
|
375 mike 1.35 {
|
376 david 1.85 #ifdef PEGASUS_OS_OS400
|
377 h.sterling 1.153 //l10n
378 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
379 //"Unable to connect to CIM Server. CIM Server may not be running." );
380 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
381 "src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
382 "Unable to connect to CIM Server. CIM Server may not be running." );
383 // The server job may still be active but not responding.
384 // Kill the job if it exists.
385 if(_cimServerProcess->cimserver_kill(0) == -1)
386 _cimServerProcess->cimserver_exitRC(2);
387 _cimServerProcess->cimserver_exitRC(1);
|
388 david 1.85 #else
|
389 humberto 1.97 //l10n
390 //PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
391 //PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
392 MessageLoaderParms parms("src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
|
393 kumpf 1.105 "Unable to connect to CIM Server.\nCIM Server may not be running.\n");
|
394 humberto 1.97 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
|
395 s.hills 1.117 exit(1);
|
396 chuck 1.66 #endif
|
397 mike 1.35 }
398
399 try
400 {
401 //
|
402 kumpf 1.52 // construct CIMObjectPath
|
403 mike 1.35 //
404 String referenceStr = "//";
405 referenceStr.append(hostStr);
|
406 david.dillard 1.165 referenceStr.append("/");
|
407 kumpf 1.72 referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
|
408 kumpf 1.53 referenceStr.append(":");
|
409 kumpf 1.72 referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
|
410 kumpf 1.50 CIMObjectPath reference(referenceStr);
|
411 mike 1.35
412 //
413 // issue the invokeMethod request on the shutdown method
414 //
415 Array<CIMParamValue> inParams;
416 Array<CIMParamValue> outParams;
417
|
418 kumpf 1.52 // set force option to true for now
|
419 kumpf 1.40 inParams.append(CIMParamValue("force",
|
420 kumpf 1.52 CIMValue(Boolean(true))));
|
421 mike 1.35
|
422 kumpf 1.40 inParams.append(CIMParamValue("timeout",
|
423 kumpf 1.39 CIMValue(Uint32(timeoutValue))));
|
424 mike 1.35
425 CIMValue retValue = client.invokeMethod(
|
426 kumpf 1.59 PEGASUS_NAMESPACENAME_SHUTDOWN,
|
427 mike 1.35 reference,
428 "shutdown",
429 inParams,
430 outParams);
|
431 kumpf 1.43 }
|
432 kumpf 1.65 catch(CIMException& e)
|
433 kumpf 1.46 {
|
434 david 1.85 #ifdef PEGASUS_OS_OS400
435
|
436 h.sterling 1.153 if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
437 {
438 //l10n
439 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
440 //"Failed to shutdown server: $0", "The repository may be empty.");
441 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
442 "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
443 "Error in server shutdown: The repository may be empty.");
444 }
445 else
446 {
447 //l10n
448 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
449 //"Failed to shutdown server: $0", e.getMessage());
450 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
451 "src.Server.cimserver.SHUTDOWN_FAILED",
452 "Error in server shutdown: $0", e.getMessage());
453 }
454 // Kill the server job.
455 if(_cimServerProcess->cimserver_kill(0) == -1)
456 _cimServerProcess->cimserver_exitRC(2);
|
457 david 1.85 #else
|
458 kumpf 1.105 //l10n - TODO
|
459 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.SHUTDOWN_FAILED",
|
460 kumpf 1.105 "Error in server shutdown: ");
|
461 humberto 1.97 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
|
462 kumpf 1.63 if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
463 {
|
464 kumpf 1.105 //
|
465 david.dillard 1.165 // Repository may be empty.
|
466 kumpf 1.105 //
467 //l10n - TODO
468 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
469 "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
470 "Error in server shutdown: The repository may be empty.");
|
471 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.REPOSITORY_EMPTY",
|
472 kumpf 1.105 "The repository may be empty.");
473 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
|
474 kumpf 1.63 }
475 else
476 {
|
477 kumpf 1.105 //l10n - TODO
478 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
479 "src.Server.cimserver.SHUTDOWN_FAILED",
480 "Error in server shutdown: $0", e.getMessage());
|
481 kumpf 1.63 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
482 }
|
483 kumpf 1.105
|
484 david.dillard 1.165 // Kill the cimserver process
|
485 h.sterling 1.153 if (_cimServerProcess->cimserver_kill(0) == 0)
|
486 kumpf 1.105 {
487 //l10n - TODO
488 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
489 "src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
|
490 h.sterling 1.153 "Forced shutdown initiated.");
|
491 kumpf 1.105 MessageLoaderParms parms("src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
492 "Forced shutdown initiated.");
493 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
494 }
|
495 s.hills 1.117 exit(1);
|
496 chuck 1.66 #endif
|
497 kumpf 1.46 }
|
498 s.hills 1.117 catch(Exception&)
|
499 kumpf 1.45 {
500 //
|
501 kumpf 1.91 // This may mean that the CIM Server has terminated, causing this
502 // client to get a "Empty HTTP response message" exception. It may
|
503 david.dillard 1.165 // also mean that the CIM Server is taking longer than 2 seconds
504 // (client timeout value) to terminate, causing this client to
|
505 kumpf 1.91 // timeout with a "connection timeout" exception.
|
506 kumpf 1.45 //
|
507 kumpf 1.91 // Check to see if CIM Server is still running. If CIM Server
|
508 kumpf 1.63 // is still running and the shutdown timeout has not expired,
|
509 kumpf 1.91 // loop and wait one second until either the CIM Server is
510 // terminated or timeout expires. If timeout expires and
511 // the CIM Server is still running, kill the CIMServer process.
|
512 david.dillard 1.165 //
|
513 kumpf 1.63 Uint32 maxWaitTime = timeoutValue - 2;
|
514 h.sterling 1.153 Boolean running = _cimServerProcess->isCIMServerRunning();
|
515 kumpf 1.63 while ( running && maxWaitTime > 0 )
516 {
517 System::sleep(1);
|
518 h.sterling 1.153 running = _cimServerProcess->isCIMServerRunning();
|
519 kumpf 1.63 maxWaitTime = maxWaitTime - 1;
520 }
521
522 if (running)
523 {
|
524 h.sterling 1.153 int kill_rc = _cimServerProcess->cimserver_kill(0);
|
525 david.dillard 1.165
|
526 humberto 1.90 #ifdef PEGASUS_OS_OS400
|
527 h.sterling 1.153 if(kill_rc == -1)
528 _cimServerProcess->cimserver_exitRC(2);
529 _cimServerProcess->cimserver_exitRC(1);
|
530 humberto 1.90 #endif
|
531 kumpf 1.91
|
532 gs.keenan 1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
|
533 jim.wunderlich 1.169 || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_SOLARIS) \
|
534 gs.keenan 1.150 || defined (PEGASUS_OS_VMS)
|
535 h.sterling 1.153 if (kill_rc != -1)
|
536 kumpf 1.91 {
|
537 kumpf 1.105 //l10n - TODO
538 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
539 "src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
540 "Shutdown timeout expired. Forced shutdown initiated.");
|
541 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
|
542 kumpf 1.105 "Shutdown timeout expired. Forced shutdown initiated.");
|
543 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
544 kumpf 1.91 exit(0);
545 }
546 #endif
|
547 kumpf 1.63 }
|
548 kumpf 1.43 }
|
549 mike 1.35
|
550 kumpf 1.168 // Make sure the cimserver has time to actually shut down
551 Uint32 maxWaitTime = timeoutValue;
552 while ((maxWaitTime-- > 0) && _cimServerProcess->isCIMServerRunning())
553 {
554 System::sleep(1);
555 }
556
|
557 mike 1.35 return;
|
558 mike 1.32 }
559
|
560 mike 1.35
|
561 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
562 mike 1.32 // MAIN
563 //////////////////////////////////////////////////////////////////////////
564 int main(int argc, char** argv)
565 {
|
566 mike 1.35 String pegasusHome = String::EMPTY;
567 Boolean shutdownOption = false;
|
568 mday 1.47
|
569 humberto 1.97 //l10n
570 // Set Message loading to process locale
|
571 david.dillard 1.165 MessageLoader::_useProcessLocale = true;
|
572 humberto 1.97 //l10n
573
|
574 kv.le 1.140 //l10n
575 #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
576 setlocale(LC_ALL, "");
577 #endif
578
|
579 chuck 1.66 #ifdef PEGASUS_OS_OS400
|
580 david 1.120
581 VFYPTRS_INCDCL; // VFYPTRS local variables
582
583 // verify pointers
584 #pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\
585 0,_C2_MH_ESCAPE)
586 for( int arg_index = 1; arg_index < argc; arg_index++ ){
|
587 h.sterling 1.153 VFYPTRS(VERIFY_SPP_NULL(argv[arg_index]));
|
588 david 1.120 }
589 #pragma disable_handler
590
|
591 david 1.100 // Convert the args to ASCII
592 for(Uint32 i = 0;i< argc;++i)
593 {
|
594 h.sterling 1.153 EtoA(argv[i]);
|
595 david 1.100 }
596
|
597 chuck 1.66 // Initialize Pegasus home to the shipped OS/400 directory.
598 pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
599 #endif
600
|
601 kv.le 1.134
|
602 tony 1.82 #ifndef PEGASUS_OS_TYPE_WINDOWS
|
603 kumpf 1.38 //
604 // Get environment variables:
605 //
|
606 david 1.100 #ifdef PEGASUS_OS_OS400
607 #pragma convert(37)
608 const char* tmp = getenv("PEGASUS_HOME");
609 #pragma convert(0)
610 char home[256] = {0};
611 if (tmp && strlen(tmp) < 256)
612 {
|
613 h.sterling 1.153 strcpy(home, tmp);
614 EtoA(home);
615 pegasusHome = home;
|
616 david 1.100 }
617 #else
|
618 kv.le 1.134 #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
619 pegasusHome = AIX_RELEASE_PEGASUS_HOME;
|
620 kumpf 1.138 #elif !defined(PEGASUS_USE_RELEASE_DIRS)
|
621 kumpf 1.38 const char* tmp = getenv("PEGASUS_HOME");
622
623 if (tmp)
624 {
625 pegasusHome = tmp;
626 }
|
627 kv.le 1.134 #endif
|
628 david 1.100 #endif
|
629 kumpf 1.38
630 FileSystem::translateSlashes(pegasusHome);
|
631 tony 1.82 #else
|
632 kumpf 1.38
|
633 tony 1.82 // windows only
|
634 h.sterling 1.153 //setHome(pegasusHome);
635 pegasusHome = _cimServerProcess->getHome();
|
636 tony 1.82 #endif
|
637 mike 1.32
|
638 kumpf 1.60 // Get help, version, and shutdown options
|
639 mike 1.35
640 for (int i = 1; i < argc; )
641 {
642 const char* arg = argv[i];
|
643 a.arora 1.142 if(String::equal(arg,"--help"))
644 {
645 PrintHelp(argv[0]);
646 exit(0);
647 }
648 else if(String::equal(arg,"--version"))
649 {
|
650 h.sterling 1.153 cout << _cimServerProcess->getVersion() << endl;
|
651 a.arora 1.142 exit(0);
652 }
|
653 mike 1.35 // Check for -option
|
654 a.arora 1.142 else if (*arg == '-')
|
655 mike 1.35 {
656 // Get the option
657 const char* option = arg + 1;
658
659 //
660 // Check to see if user asked for the version (-v option):
661 //
|
662 tony 1.83 if (*option == OPTION_VERSION &&
663 strlen(option) == 1)
|
664 mike 1.35 {
|
665 h.sterling 1.153 cout << _cimServerProcess->getVersion() << endl;
|
666 mike 1.35 exit(0);
667 }
668 //
669 // Check to see if user asked for help (-h option):
670 //
|
671 tony 1.83 else if (*option == OPTION_HELP &&
672 (strlen(option) == 1))
|
673 mike 1.35 {
674 PrintHelp(argv[0]);
675 exit(0);
676 }
|
677 kumpf 1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
|
678 tony 1.83 else if (*option == OPTION_HOME &&
679 (strlen(option) == 1))
|
680 mike 1.35 {
|
681 kumpf 1.60 if (i + 1 < argc)
|
682 mike 1.35 {
683 pegasusHome.assign(argv[i + 1]);
684 }
685 else
686 {
|
687 humberto 1.97 //l10n
688 //cout << "Missing argument for option -" << option << endl;
|
689 humberto 1.99 String opt(option);
|
690 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
|
691 h.sterling 1.153 "Missing argument for option -$0",
692 opt);
693 cout << MessageLoader::getMessage(parms) << endl;
|
694 mike 1.35 exit(0);
695 }
696
697 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
698 argc -= 2;
699 }
|
700 kumpf 1.63 #endif
|
701 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
702 //
|
703 kumpf 1.49 // Check to see if user asked for the version (-X option):
|
704 kumpf 1.48 //
|
705 tony 1.83 if (*option == OPTION_BINDVERBOSE &&
706 (strlen(option) == 1))
|
707 kumpf 1.48 {
|
708 h.sterling 1.153 System::bindVerbose = true;
|
709 humberto 1.97 //l10n
|
710 david.dillard 1.165 //cout << "Unsupported debug option, BIND_VERBOSE, enabled."
|
711 humberto 1.97 //<< endl;
712 MessageLoaderParms parms("src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
|
713 h.sterling 1.153 "Unsupported debug option, BIND_VERBOSE, enabled.");
714 cout << MessageLoader::getMessage(parms) << endl;
|
715 kumpf 1.48 // remove the option from the command line
716 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
|
717 david.dillard 1.165 argc--;
|
718 kumpf 1.48 }
719 #endif
|
720 mike 1.35 //
721 // Check to see if user asked for shutdown (-s option):
722 //
|
723 tony 1.82 else if (*option == OPTION_SHUTDOWN &&
724 (strlen(option) == 1))
|
725 mike 1.35 {
726 //
|
727 kumpf 1.52 // Check to see if shutdown has already been specified:
|
728 mike 1.35 //
|
729 kumpf 1.52 if (shutdownOption)
|
730 mike 1.35 {
|
731 humberto 1.97 //l10n
732 //cout << "Duplicate shutdown option specified." << endl;
733 MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
|
734 h.sterling 1.153 "Duplicate shutdown option specified.");
|
735 david.dillard 1.165
|
736 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
737 mike 1.35 exit(0);
738 }
739
|
740 kumpf 1.52 shutdownOption = true;
|
741 david.dillard 1.165
|
742 mike 1.35 // remove the option from the command line
743 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
|
744 david.dillard 1.165 argc--;
|
745 mike 1.35 }
746 else
747 i++;
748 }
749 else
750 i++;
|
751 mike 1.32 }
|
752 mike 1.35
|
753 kumpf 1.38 //
754 // Set the value for pegasusHome property
755 //
756 ConfigManager::setPegasusHome(pegasusHome);
|
757 mike 1.32
|
758 mike 1.35 //
|
759 s.hills 1.117 // Do the plaform specific run
760 //
761
|
762 h.sterling 1.153 return _cimServerProcess->platform_run( argc, argv, shutdownOption );
|
763 s.hills 1.117 }
764
|
765 h.sterling 1.153 void CIMServerProcess::cimserver_stop()
766 {
767 _cimServer->shutdownSignal();
768 }
|
769 s.hills 1.117
770 //
771 // The main, common, running code
772 //
|
773 david.dillard 1.165 // NOTE: Do NOT call exit(). Use return(), otherwise some platforms
|
774 s.hills 1.117 // will fail to shutdown properly/cleanly.
775 //
|
776 david.dillard 1.165 // TODO: Current change minimal for platform "service" shutdown bug fixes.
777 // Perhpas further extract out common stuff and put into main(), put
778 // daemon stuff into platform specific platform_run(), etc.
779 // Note: make sure to not put error handling stuff that platform
|
780 s.hills 1.117 // specific runs may need to deal with bettter (instead of exit(), etc).
781 //
782
|
783 h.sterling 1.153 int CIMServerProcess::cimserver_run( int argc, char** argv, Boolean shutdownOption )
|
784 s.hills 1.117 {
785 String logsDirectory = String::EMPTY;
786 Boolean daemonOption = false;
787
788 //
|
789 mike 1.35 // Get an instance of the Config Manager.
790 //
791 configManager = ConfigManager::getInstance();
|
792 kumpf 1.136 configManager->useConfigFiles = true;
|
793 mike 1.35
|
794 lucier 1.130 #ifdef PEGASUS_OS_OS400
795 // In a special startup case for IBM OS400, when the server is
796 // automatically started when the machine starts up the config
797 // file cannot be read because of access restrictions for the
798 // user starting the server. In this case, we need to skip
799 // reading the config options and therefore any use of the config
800 // manager also. To make this determinations we will check to see
801 // if the daemon flag is set to true. If so, then there will be a
802 // series of checks to bracket all the calls to the configManager
803 // which would otherwise fail. All this will only be done for
804 // IBM OS400.
805
806 Boolean os400StartupOption = false;
807 // loop through args to check for daemon=true
808 for (int i=1; i < argc; i++)
809 if (strcmp(argv[i], "daemon=true") == 0)
810 {
811 os400StartupOption = true;
812 daemonOption = true;
813 }
|
814 chuck 1.164
815 if (!os400StartupOption)
816 {
817 // If this is the server job, then set the job
818 // to save the job log.
819 system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
820 }
|
821 david.dillard 1.165 #endif
|
822 lucier 1.130
|
823 mike 1.35 //
|
824 mike 1.32 // Get options (from command line and from configuration file); this
|
825 mike 1.35 // removes corresponding options and their arguments from the command
|
826 mike 1.32 // line.
|
827 mike 1.35 //
|
828 mike 1.32 try
829 {
|
830 lucier 1.130 #ifdef PEGASUS_OS_OS400
831 if (os400StartupOption == false)
|
832 david.dillard 1.165 #endif
|
833 s.hills 1.117 GetOptions(configManager, argc, argv);
|
834 mike 1.32 }
835 catch (Exception& e)
836 {
|
837 kumpf 1.127 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
838 "src.Server.cimserver.SERVER_NOT_STARTED",
839 "cimserver not started: $0", e.getMessage());
840
841 #if !defined(PEGASUS_OS_OS400)
842 MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
843 "cimserver not started: $0", e.getMessage());
844
845 PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
846 << PEGASUS_STD(endl);
|
847 david 1.85 #endif
|
848 kumpf 1.127
|
849 s.hills 1.117 return(1);
|
850 mike 1.32 }
851
|
852 chuck 1.94 // l10n
|
853 h.sterling 1.153 // Set the home directory, msg sub-dir, into the MessageLoader.
|
854 david.dillard 1.165 // This will be the default directory where the resource bundles
855 // are found.
|
856 h.sterling 1.153 MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
|
857 david.dillard 1.165 ConfigManager::getInstance()->getCurrentValue("messageDir")));
|
858 chuck 1.94
|
859 lucier 1.130 #ifdef PEGASUS_OS_OS400
860 // Still need to declare and set the connection variables.
861 // Will initialize to false since they are fixed at false for OS400.
862
863 // NOTE: OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down
864 // the test will not be compiled in. If OS400 ever turns off that
865 // define, then we will need to change this code path to insure that
|
866 david.dillard 1.165 // one of the variables is true.
|
867 lucier 1.130 Boolean enableHttpConnection = false;
868 Boolean enableHttpsConnection = false;
|
869 kumpf 1.135 Boolean enableSSLExportClientVerification = false;
|
870 lucier 1.130
871 if (os400StartupOption == false)
872 {
873 enableHttpConnection = String::equal(
874 configManager->getCurrentValue("enableHttpConnection"), "true");
875 enableHttpsConnection = String::equal(
876 configManager->getCurrentValue("enableHttpsConnection"), "true");
|
877 kumpf 1.135 enableSSLExportClientVerification = String::equal(
878 configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
|
879 lucier 1.130 }
880 #else
|
881 kumpf 1.87 Boolean enableHttpConnection = String::equal(
882 configManager->getCurrentValue("enableHttpConnection"), "true");
883 Boolean enableHttpsConnection = String::equal(
884 configManager->getCurrentValue("enableHttpsConnection"), "true");
|
885 kumpf 1.135 Boolean enableSSLExportClientVerification = String::equal(
886 configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
|
887 lucier 1.130 #endif
|
888 kumpf 1.86
889 // Make sure at least one connection is enabled
|
890 h.sterling 1.159 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
|
891 kumpf 1.86 if (!enableHttpConnection && !enableHttpsConnection)
892 {
|
893 humberto 1.97 //l10n
894 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
895 //"Neither HTTP nor HTTPS connection is enabled. "
896 //"CIMServer will not be started.");
897 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
|
898 h.sterling 1.153 "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
|
899 humberto 1.97 "Neither HTTP nor HTTPS connection is enabled. CIMServer will not be started.");
900 //cerr << "Neither HTTP nor HTTPS connection is enabled. "
901 //"CIMServer will not be started." << endl;
902 MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
|
903 h.sterling 1.153 "Neither HTTP nor HTTPS connection is enabled. CIMServer will not be started.");
|
904 humberto 1.97 cerr << MessageLoader::getMessage(parms) << endl;
|
905 s.hills 1.117 return(1);
|
906 kumpf 1.86 }
907 #endif
908
|
909 mike 1.35 try
|
910 mike 1.32 {
|
911 mike 1.35 //
912 // Check to see if we should Pegasus as a daemon
913 //
914
915 if (String::equal(configManager->getCurrentValue("daemon"), "true"))
916 {
917 daemonOption = true;
918 }
|
919 david.dillard 1.165
|
920 lucier 1.130 #ifdef PEGASUS_OS_OS400
921 if (os400StartupOption == false)
922 {
|
923 david.dillard 1.165 #endif
|
924 kumpf 1.36 // Get the log file directory definition.
925 // We put String into Cstring because
926 // Directory functions only handle Cstring.
927 // ATTN-KS: create String based directory functions.
|
928 konrad.r 1.161 #if !defined(PEGASUS_USE_SYSLOGS)
929 // When using syslog facility. No files anymore.
|
930 kumpf 1.36 logsDirectory = configManager->getCurrentValue("logdir");
|
931 david.dillard 1.165 logsDirectory =
|
932 h.sterling 1.153 ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
|
933 konrad.r 1.161 #endif
|
934 lucier 1.130 #ifdef PEGASUS_OS_OS400
935 } // end if (os400StartupOption == false)
936 #endif
|
937 kumpf 1.36
938 // Set up the Logger. This does not open the logs
939 // Might be more logical to clean before set.
940 // ATTN: Need tool to completely disable logging.
941
|
942 david 1.85 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
|
943 konrad.r 1.161 !defined(PEGASUS_OS_OS400) && !defined(PEGASUS_USE_SYSLOGS)
|
944 kumpf 1.36 Logger::setHomeDirectory(logsDirectory);
|
945 kumpf 1.57 #endif
|
946 kumpf 1.36
947 //
|
948 david.dillard 1.165 // Check to see if we need to shutdown CIMOM
|
949 mike 1.35 //
950 if (shutdownOption)
951 {
|
952 david.dillard 1.165 String configTimeout =
|
953 kumpf 1.60 configManager->getCurrentValue("shutdownTimeout");
|
954 s.hills 1.117 Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
|
955 david.dillard 1.165
|
956 kumpf 1.52 shutdownCIMOM(timeoutValue);
|
957 kumpf 1.45
|
958 david 1.85 #ifdef PEGASUS_OS_OS400
|
959 h.sterling 1.153 //l10n
960 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
|
961 david.dillard 1.165 //"CIM Server stopped.");
|
962 h.sterling 1.153 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
963 "src.Server.cimserver.SERVER_STOPPED",
964 "CIM Server stopped.");
|
965 s.hills 1.117 cimserver_exitRC(0);
|
966 david 1.85 #else
|
967 h.sterling 1.153 //l10n
|
968 humberto 1.97 //cout << "CIM Server stopped." << endl;
969 MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",
|
970 h.sterling 1.153 "CIM Server stopped.");
|
971 humberto 1.106
|
972 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
973 s.hills 1.117 return(0);
|
974 diane 1.81 #endif
|
975 mike 1.35 }
|
976 mike 1.32
|
977 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
978 kumpf 1.36 // Leave this in until people get familiar with the logs.
|
979 humberto 1.97 //l10n
980 //cout << "Logs Directory = " << logsDirectory << endl;
|
981 konrad.r 1.161 #if !defined(PEGASUS_USE_SYSLOGS)
|
982 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
|
983 h.sterling 1.153 "Logs Directory = ");
|
984 humberto 1.97 cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
|
985 kumpf 1.57 #endif
|
986 konrad.r 1.161 #endif
|
987 mike 1.32 }
|
988 kumpf 1.122 catch (UnrecognizedConfigProperty& e)
|
989 mike 1.32 {
|
990 david 1.85
991 #ifdef PEGASUS_OS_OS400
|
992 h.sterling 1.153 //l10n
993 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
|
994 david.dillard 1.165 //"Error: $0",e.getMessage());
|
995 h.sterling 1.153 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
996 "src.Server.cimserver.ERROR",
|
997 david.dillard 1.165 "Error: $0",e.getMessage());
|
998 david 1.85 #else
|
999 h.sterling 1.153 //l10n
1000 //cout << "Error: " << e.getMessage() << endl;
1001 MessageLoaderParms parms("src.Server.cimserver.ERROR",
1002 "Error: $0",
1003 e.getMessage());
1004 cout << MessageLoader::getMessage(parms) << endl;
|
1005 david 1.85 #endif
|
1006 mike 1.32 }
1007
|
1008 h.sterling 1.158 // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.
1009 // 1) If the user explicitly specified a port, use it.
1010 // 2) If the user did not specify a port, get the port from the services file.
1011 // 3) If no value is specified in the services file, use the IANA WBEM default port.
1012 // Note that 2 and 3 are done within the System::lookupPort method
1013 // An empty string from the ConfigManager implies that the user did not specify a port.
1014
|
1015 w.otsuka 1.147 Uint32 portNumberHttps=0;
1016 Uint32 portNumberHttp=0;
1017 Uint32 portNumberExportHttps=0;
|
1018 kumpf 1.53
|
1019 kumpf 1.86 if (enableHttpsConnection)
|
1020 kumpf 1.53 {
|
1021 kumpf 1.86 String httpsPort = configManager->getCurrentValue("httpsPort");
|
1022 h.sterling 1.158 if (httpsPort == String::EMPTY)
|
1023 joyce.j 1.144 {
|
1024 h.sterling 1.158 //
1025 // Look up the WBEM-HTTPS port number
1026 //
1027 portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
1028
1029 } else
|
1030 david.dillard 1.165 {
|
1031 h.sterling 1.158 //
1032 // user-specified
1033 //
1034 CString portString = httpsPort.getCString();
1035 char* end = 0;
1036 portNumberHttps = strtol(portString, &end, 10);
1037 if(!(end != 0 && *end == '\0'))
1038 {
|
1039 joyce.j 1.160 InvalidPropertyValue e("httpsPort", httpsPort);
1040 cerr << e.getMessage() << endl;
|
1041 h.sterling 1.158 exit(1);
1042 }
|
1043 joyce.j 1.144 }
|
1044 kumpf 1.53 }
|
1045 kumpf 1.86
1046 if (enableHttpConnection)
|
1047 kumpf 1.53 {
|
1048 kumpf 1.86 String httpPort = configManager->getCurrentValue("httpPort");
|
1049 h.sterling 1.158 if (httpPort == String::EMPTY)
|
1050 joyce.j 1.144 {
|
1051 h.sterling 1.158 //
1052 // Look up the WBEM-HTTP port number
1053 //
1054 portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
1055
1056 } else
1057 {
1058 //
1059 // user-specified
1060 //
1061 CString portString = httpPort.getCString();
1062 char* end = 0;
1063 portNumberHttp = strtol(portString, &end, 10);
1064 if(!(end != 0 && *end == '\0'))
1065 {
|
1066 joyce.j 1.160 InvalidPropertyValue e("httpPort", httpPort);
1067 cerr << e.getMessage() << endl;
|
1068 h.sterling 1.158 exit(1);
1069 }
|
1070 joyce.j 1.144 }
|
1071 kumpf 1.53 }
|
1072 mike 1.32
|
1073 h.sterling 1.158
|
1074 kumpf 1.135 if (enableSSLExportClientVerification)
1075 {
1076 //
1077 // No config property is looked up to get the default port number.
1078 // Lookup the port defined in /etc/services for the service name
1079 // wbem-exp-https and bind to that port. If the service is not defined
1080 // then log a warning message and do not start the cimserver.
1081 //
1082 Uint32 port = 0;
1083
1084 portNumberExportHttps = System::lookupPort(WBEM_EXPORT_HTTPS_SERVICE_NAME, port);
1085
1086 if (portNumberExportHttps == 0)
1087 {
1088 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1089 "src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
1090 "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
1091
1092 MessageLoaderParms parms("src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
1093 "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
1094
1095 kumpf 1.135 cerr << MessageLoader::getMessage(parms) << endl;
1096
1097 return(1);
1098 }
1099 }
|
1100 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
1101 mike 1.32 // Put out startup up message.
|
1102 h.sterling 1.153 cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;
|
1103 humberto 1.97 //l10n
1104 //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
1105 //cout <<"Starting..."
1106 MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
|
1107 h.sterling 1.153 "Built $0 $1\nStarting...",
1108 __DATE__,
1109 __TIME__);
|
1110 humberto 1.97 #endif
1111
1112 //l10n
1113 // reset message loading to NON-process locale
|
1114 david.dillard 1.165 MessageLoader::_useProcessLocale = false;
|
1115 humberto 1.97 //l10n
|
1116 mike 1.32
|
1117 kumpf 1.137 // Get the parent's PID before forking
|
1118 h.sterling 1.154 _cimServerProcess->set_parent_pid(System::getPID());
|
1119 david.dillard 1.165
|
1120 kumpf 1.63 // do we need to run as a daemon ?
1121 if (daemonOption)
1122 {
|
1123 h.sterling 1.153 if(-1 == _cimServerProcess->cimserver_fork())
|
1124 diane 1.81 #ifndef PEGASUS_OS_OS400
|
1125 h.sterling 1.153 {
1126 return(-1);
1127 }
|
1128 diane 1.81 #else
|
1129 h.sterling 1.153 {
|
1130 david 1.85 return(-1);
|
1131 h.sterling 1.153 }
1132 else
1133 {
1134 return(0);
1135 }
|
1136 diane 1.81 #endif
|
1137 david.dillard 1.165
|
1138 kumpf 1.63 }
|
1139 chuck 1.66
|
1140 chuck 1.96 // l10n
1141 // Now we are after the fork...
1142 // Create a dummy Thread object that can be used to store the
1143 // AcceptLanguages object for CIM requests that are serviced
1144 // by this thread (initial thread of server). Need to do this
1145 // because this thread is not in a ThreadPool, but is used
1146 // to service CIM requests.
1147 // The run function for the dummy Thread should never be called,
|
1148 konrad.r 1.166 dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
|
1149 david.dillard 1.165 Thread::setCurrent(dummyInitialThread);
|
1150 humberto 1.108 AcceptLanguages default_al;
1151 try{
|
1152 david.dillard 1.165 default_al = AcceptLanguages::getDefaultAcceptLanguages();
|
1153 h.sterling 1.153 Thread::setLanguages(new AcceptLanguages(default_al));
|
1154 kumpf 1.122 }catch(InvalidAcceptLanguageHeader& e){
|
1155 h.sterling 1.153 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1156 "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
|
1157 david.dillard 1.165 "Could not convert the system process locale into a valid AcceptLanguage format.");
|
1158 h.sterling 1.153 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
|
1159 david.dillard 1.165 e.getMessage());
|
1160 humberto 1.108 }
|
1161 david.dillard 1.165
1162
|
1163 chuck 1.96
|
1164 chuck 1.66 #ifdef PEGASUS_OS_OS400
1165 // Special server initialization code for OS/400.
1166 if (cimserver_initialize() != 0)
1167 {
|
1168 h.sterling 1.153 // do some logging here!
1169 //l10n
1170 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
|
1171 david.dillard 1.165 //"CIM Server failed to initialize");
|
1172 h.sterling 1.153 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1173 "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE",
|
1174 david.dillard 1.165 "CIM Server failed to initialize");
|
1175 h.sterling 1.153 return(-1);
|
1176 david.dillard 1.165 }
|
1177 chuck 1.66 #endif
|
1178 chuck 1.96
|
1179 kumpf 1.167 #ifndef PEGASUS_OS_TYPE_WINDOWS
1180 umask(S_IRWXG|S_IRWXO);
1181 #endif
|
1182 mday 1.62
|
1183 gs.keenan 1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1184 || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
|
1185 jim.wunderlich 1.169 || defined(PEGASUS_OS_SOLARIS) || defined (PEGASUS_OS_VMS)
|
1186 kumpf 1.79
1187 //
1188 // check if CIMServer is already running
|
1189 david.dillard 1.165 // if CIMServer is already running, print message and
|
1190 kumpf 1.79 // notify parent process (if there is a parent process) to terminate
1191 //
|
1192 h.sterling 1.153 if(_cimServerProcess->isCIMServerRunning())
|
1193 kumpf 1.79 {
|
1194 h.sterling 1.153 //l10n
1195 //cout << "Unable to start CIMServer." << endl;
1196 //cout << "CIMServer is already running." << endl;
1197 MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
1198 "Unable to start CIMServer.\nCIMServer is already running.");
1199 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
|
1200 kumpf 1.79
|
1201 h.sterling 1.153 //
|
1202 kumpf 1.79 // notify parent process (if there is a parent process) to terminate
1203 //
1204 if (daemonOption)
|
1205 h.sterling 1.153 _cimServerProcess->notify_parent(1);
|
1206 kumpf 1.79
|
1207 s.hills 1.117 return(1);
|
1208 kumpf 1.79 }
|
1209 david.dillard 1.165
|
1210 kumpf 1.63 #endif
|
1211 kumpf 1.51
|
1212 mike 1.32 // try loop to bind the address, and run the server
1213 try
1214 {
|
1215 mday 1.116
|
1216 konrad.r 1.163 _monitor = new Monitor();
|
1217 h.sterling 1.153 //PEP#222
1218 //CIMServer server(&monitor);
1219 //CimserverHolder cimserverHolder( &server );
|
1220 konrad.r 1.163 _cimServer = new CIMServer(_monitor);
|
1221 mday 1.111
|
1222 kumpf 1.41
|
1223 kumpf 1.86 if (enableHttpConnection)
1224 {
|
1225 h.sterling 1.153 _cimServer->addAcceptor(false, portNumberHttp, false, false);
|
1226 humberto 1.97 //l10n
1227 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1228 //"Listening on HTTP port $0.", portNumberHttp);
|
1229 david.dillard 1.165
|
1230 humberto 1.97 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
1231 h.sterling 1.153 "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1232 "Listening on HTTP port $0.", portNumberHttp);
|
1233 kumpf 1.86 }
1234 if (enableHttpsConnection)
1235 {
|
1236 h.sterling 1.153 _cimServer->addAcceptor(false, portNumberHttps, true, false);
|
1237 humberto 1.97 //l10n
1238 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1239 //"Listening on HTTPS port $0.", portNumberHttps);
1240 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
1241 h.sterling 1.153 "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1242 "Listening on HTTPS port $0.", portNumberHttps);
|
1243 kumpf 1.86 }
|
1244 kumpf 1.135 if (enableSSLExportClientVerification)
1245 {
|
1246 h.sterling 1.153 _cimServer->addAcceptor(false, portNumberExportHttps, true, true);
|
1247 kumpf 1.135
1248 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1249 "src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1250 "Listening on Export HTTPS port $0.", portNumberExportHttps);
1251 }
1252
|
1253 h.sterling 1.159 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
|
1254 h.sterling 1.153 _cimServer->addAcceptor(true, 0, false, false);
|
1255 humberto 1.97 //l10n
1256 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1257 //"Listening on local connection socket.");
1258 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
1259 h.sterling 1.153 "src.Server.cimserver.LISTENING_ON_LOCAL",
1260 "Listening on local connection socket.");
|
1261 kumpf 1.41 #endif
|
1262 kumpf 1.86
|
1263 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
1264 kumpf 1.86 if (enableHttpConnection)
1265 {
|
1266 humberto 1.97 //l10n
1267 //cout << "Listening on HTTP port " << portNumberHttp << endl;
|
1268 h.sterling 1.153 MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1269 "Listening on HTTP port $0.", portNumberHttp);
1270 cout << MessageLoader::getMessage(parms) << endl;
|
1271 kumpf 1.86 }
1272 if (enableHttpsConnection)
1273 {
|
1274 humberto 1.97 //l10n
1275 //cout << "Listening on HTTPS port " << portNumberHttps << endl;
|
1276 humberto 1.103 MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
|
1277 h.sterling 1.153 "Listening on HTTPS port $0.", portNumberHttps);
1278 cout << MessageLoader::getMessage(parms) << endl;
|
1279 kumpf 1.86 }
|
1280 kumpf 1.135 if (enableSSLExportClientVerification)
1281 {
1282 MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1283 "Listening on Export HTTPS port $0.", portNumberExportHttps);
1284
1285 cout << MessageLoader::getMessage(parms) << endl;
1286 }
1287
|
1288 h.sterling 1.159 # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
|
1289 humberto 1.97 //l10n
1290 //cout << "Listening on local connection socket" << endl;
1291 MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",
|
1292 h.sterling 1.153 "Listening on local connection socket.");
|
1293 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
1294 kumpf 1.86 # endif
|
1295 david 1.85 #endif
|
1296 mike 1.35
|
1297 kumpf 1.86 // bind throws an exception if the bind fails
|
1298 david.dillard 1.165 try {
|
1299 konrad.r 1.163 _cimServer->bind();
1300 } catch (const BindFailedException &e)
1301 {
1302 #ifdef PEGASUS_DEBUG
1303 MessageLoaderParms parms("src.Server.cimserver.BIND_FAILED",
1304 "Could not bind: $0.", e.getMessage());
1305 cout << MessageLoader::getMessage(parms) << endl;
1306 #endif
1307 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1308 "src.Server.cimserver.BIND.FAILED",
1309 "Could not bind: $0", e.getMessage());
|
1310 kumpf 1.73
|
1311 konrad.r 1.163 deleteCIMServer();
1312 return 1;
1313 }
|
1314 david.dillard 1.165 // notify parent process (if there is a parent process) to terminate
|
1315 konrad.r 1.95 // so user knows that there is cimserver ready to serve CIM requests.
|
1316 h.sterling 1.153 if (daemonOption)
1317 _cimServerProcess->notify_parent(0);
|
1318 mike 1.32
|
1319 h.sterling 1.153 time_t last = 0;
|
1320 mike 1.35
|
1321 gs.keenan 1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \
|
1322 jim.wunderlich 1.169 || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_SOLARIS) \
|
1323 gs.keenan 1.150 || defined(PEGASUS_OS_VMS)
|
1324 kumpf 1.45 //
|
1325 kumpf 1.56 // create a file to indicate that the cimserver has started and
1326 // save the process id of the cimserver process in the file
|
1327 kumpf 1.45 //
|
1328 kumpf 1.56 // remove the old file if it exists
|
1329 h.sterling 1.153 System::removeFile(_cimServerProcess->getPIDFileName());
|
1330 kumpf 1.56
1331 // open the file
|
1332 h.sterling 1.153 FILE *pid_file = fopen(_cimServerProcess->getPIDFileName(), "w");
|
1333 kumpf 1.91
|
1334 kumpf 1.56 if (pid_file)
|
1335 kumpf 1.45 {
|
1336 kumpf 1.56 // save the pid in the file
|
1337 h.sterling 1.153 fprintf(pid_file, "%ld\n", _cimServerProcess->get_server_pid());
|
1338 kumpf 1.56 fclose(pid_file);
|
1339 kumpf 1.45 }
1340 #endif
|
1341 kumpf 1.91
|
1342 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
1343 h.sterling 1.153 cout << "Started. " << endl;
|
1344 kumpf 1.63 #endif
|
1345 david.dillard 1.165
|
1346 kumpf 1.54 // Put server started message to the logger
|
1347 kumpf 1.143 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1348 Logger::INFORMATION,
1349 "src.Server.cimserver.STARTED_VERSION",
1350 "Started $0 version $1.",
|
1351 h.sterling 1.153 _cimServerProcess->getProductName(), _cimServerProcess->getVersion());
|
1352 kumpf 1.45
|
1353 mike 1.35 //
1354 // Loop to call CIMServer's runForever() method until CIMServer
1355 // has been shutdown
1356 //
|
1357 h.sterling 1.153 while( !_cimServer->terminated() )
1358 {
|
1359 mday 1.116
|
1360 h.sterling 1.153 _cimServer->runForever();
|
1361 mday 1.112
|
1362 h.sterling 1.153 }
|
1363 carson.hovey 1.157
|
1364 kumpf 1.45 //
1365 // normal termination
|
1366 carson.hovey 1.157 //
|
1367 kumpf 1.143
|
1368 kumpf 1.54 // Put server shutdown message to the logger
|
1369 kumpf 1.143 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1370 Logger::INFORMATION, "src.Server.cimserver.STOPPED",
|
1371 h.sterling 1.153 "$0 stopped.", _cimServerProcess->getProductName());
|
1372 kumpf 1.45
|
1373 gs.keenan 1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1374 || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
|
1375 jim.wunderlich 1.169 || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS)
|
1376 kumpf 1.45 //
|
1377 david.dillard 1.165 // close the file created at startup time to indicate that the
|
1378 kumpf 1.56 // cimserver has terminated normally.
|
1379 kumpf 1.45 //
|
1380 h.sterling 1.153 FileSystem::removeFile(_cimServerProcess->getPIDFileName());
|
1381 kumpf 1.45 #endif
|
1382 mike 1.32 }
1383 catch(Exception& e)
1384 {
|
1385 david 1.100
|
1386 h.sterling 1.153 //l10n
1387 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
|
1388 david.dillard 1.165 //"Error: $0", e.getMessage());
|
1389 h.sterling 1.153 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1390 "src.Server.cimserver.ERROR",
|
1391 david.dillard 1.165 "Error: $0", e.getMessage());
|
1392 konrad.r 1.95
1393 #ifndef PEGASUS_OS_OS400
|
1394 h.sterling 1.153 //l10n
1395 //PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1396 MessageLoaderParms parms("src.Server.cimserver.ERROR",
1397 "Error: $0", e.getMessage());
1398 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
|
1399 david 1.100
|
1400 david 1.85 #endif
|
1401 kumpf 1.77
|
1402 h.sterling 1.153 //
|
1403 kumpf 1.77 // notify parent process (if there is a parent process) to terminate
1404 //
1405 if (daemonOption)
|
1406 h.sterling 1.153 _cimServerProcess->notify_parent(1);
|
1407 kumpf 1.77
|
1408 h.sterling 1.156 deleteCIMServer();
|
1409 kumpf 1.54 return 1;
|
1410 mike 1.32 }
1411
|
1412 h.sterling 1.156 deleteCIMServer();
|
1413 mike 1.32 return 0;
1414 }
|
1415 tony 1.128
1416
1417
1418
|