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