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