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