1 karl 1.23 //%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 karl 1.23 // 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 //%/////////////////////////////////////////////////////////////////////////////
33
34 kumpf 1.1
35 //////////////////////////////////////////////////////////////////////
36 //
37 // Notes on deamon operation (Unix) and service operation (Win 32):
38 //
39 // To run pegasus as a daemon on Unix platforms:
40 //
41 // cimserver
42 //
43 // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
44 // property to false:
45 //
46 // cimserver daemon=false
47 //
48 // The daemon config property has no effect on windows operation.
49 //
50 // To shutdown pegasus, use the -s option:
51 //
52 // cimserver -s
53 //
54 // To run pegasus as an NT service, there are FOUR different possibilities:
55 kumpf 1.1 //
56 // To INSTALL the Pegasus service,
57 //
58 // cimserver -install
59 //
60 // To REMOVE the Pegasus service,
61 //
62 // cimserver -remove
63 //
64 // To START the Pegasus service,
65 //
66 // net start cimserver
|
67 mateus.baur 1.17 // or
68 // cimserver -start
|
69 kumpf 1.1 //
70 // To STOP the Pegasus service,
71 //
72 // net stop cimserver
|
73 mateus.baur 1.17 // or
74 // cimserver -stop
|
75 kumpf 1.1 //
76 // Alternatively, you can use the windows service manager. Pegasus shows up
77 // in the service database as "Pegasus CIM Object Manager"
78 //
79 //////////////////////////////////////////////////////////////////////
80
81
82 #include <Pegasus/Common/Config.h>
83 #include <Pegasus/Common/Constants.h>
84 #include <iostream>
|
85 jim.wunderlich 1.20 #include <Pegasus/Common/PegasusAssert.h>
|
86 kumpf 1.1 #include <fstream>
87 #include <Pegasus/Common/FileSystem.h>
88 #include <Pegasus/Common/Monitor.h>
89 #include <Pegasus/Common/PegasusVersion.h>
90 #include <Pegasus/Common/Logger.h>
91 #include <Pegasus/Common/System.h>
92 #include <Pegasus/Common/Tracer.h>
|
93 kumpf 1.21 #include <Pegasus/Common/LanguageParser.h>
|
94 kumpf 1.1 #include <Pegasus/Config/ConfigManager.h>
95 #include <Pegasus/Client/CIMClient.h>
|
96 mateus.baur 1.17 #include <Pegasus/Server/CIMServer.h>
97 #include <Service/ServerProcess.h>
|
98 kumpf 1.30 #include <Service/ServerShutdownClient.h>
99 #include <Service/ServerRunStatus.h>
|
100 mateus.baur 1.17
101 PEGASUS_USING_PEGASUS;
102 PEGASUS_USING_STD;
|
103 kumpf 1.1
|
104 kumpf 1.30 #define PEGASUS_PROCESS_NAME "WMI Mapper"
|
105 kumpf 1.3
|
106 mateus.baur 1.17 //Windows service variables are not defined elsewhere in the product
107 //enable ability to override these
108 #ifndef PEGASUS_SERVICE_NAME
109 #define PEGASUS_SERVICE_NAME "Pegasus WMI Mapper";
|
110 kumpf 1.1 #endif
|
111 mateus.baur 1.17 #ifndef PEGASUS_SERVICE_DESCRIPTION
112 #define PEGASUS_SERVICE_DESCRIPTION "Pegasus WMI Mapper Service";
|
113 kumpf 1.1 #endif
114
|
115 mateus.baur 1.17 class CIMServerProcess : public ServerProcess
116 {
117 public:
118
119 CIMServerProcess(void)
120 {
121 cimserver_set_process(this);
122 }
123
124 virtual ~CIMServerProcess(void)
125 {
126 }
127
128 //defined in PegasusVersion.h
129 virtual const char* getProductName() const
130 {
131 return PEGASUS_PRODUCT_NAME;
132 }
133
134 virtual const char* getExtendedName() const
135 {
136 mateus.baur 1.17 return PEGASUS_SERVICE_NAME;
137 }
138
139 virtual const char* getDescription() const
140 {
141 return PEGASUS_SERVICE_DESCRIPTION;
142 }
143
144 //defined in PegasusVersion.h
145 virtual const char* getVersion() const
146 {
147 return PEGASUS_PRODUCT_VERSION;
148 }
149
150 virtual const char* getProcessName() const
151 {
152 return PEGASUS_PROCESS_NAME;
153 }
154
|
155 kumpf 1.24 //defined in Constants.h
|
156 mateus.baur 1.17 virtual const char* getPIDFileName() const
157 {
|
158 kumpf 1.24 return PEGASUS_CIMSERVER_START_FILE;
|
159 mateus.baur 1.17 }
160
|
161 mateus.baur 1.32 int cimserver_run(
162 int argc,
163 char** argv,
164 Boolean shutdownOption,
165 Boolean debugOutputOption);
|
166 mateus.baur 1.17
167 void cimserver_stop(void);
168 };
169
|
170 kumpf 1.30 ServerRunStatus _serverRunStatus(
171 PEGASUS_PROCESS_NAME, PEGASUS_CIMSERVER_START_FILE);
|
172 mateus.baur 1.17 AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
173 static CIMServer* _cimServer = 0;
|
174 mateus.baur 1.18 static Monitor* _monitor = 0;
|
175 kumpf 1.1
176 //
177 // The command name.
178 //
179 static const char COMMAND_NAME [] = "cimserver";
180
181 //
182 // The constant defining usage string.
183 //
184 static const char USAGE [] = "Usage: ";
185
186 /**
187 Constants representing the command line options.
188 */
189 static const char OPTION_VERSION = 'v';
190
191 static const char OPTION_HELP = 'h';
192
193 static const char OPTION_HOME = 'D';
194
195 static const char OPTION_SHUTDOWN = 's';
196 kumpf 1.1
|
197 mateus.baur 1.17 static const char LONG_HELP [] = "help";
|
198 kumpf 1.3
|
199 mateus.baur 1.17 static const char LONG_VERSION [] = "version";
|
200 kumpf 1.3
|
201 kumpf 1.1 #if defined(PEGASUS_OS_HPUX)
202 static const char OPTION_BINDVERBOSE = 'X';
203 #endif
204
205 static const String PROPERTY_TIMEOUT = "shutdownTimeout";
206
207 ConfigManager* configManager;
208
209 /** GetOptions function - This function defines the Options Table
210 and sets up the options from that table using the config manager.
|
211 kumpf 1.30
212 Some possible exceptions: NoSuchFile, FileNotReadable, CannotRenameFile,
213 ConfigFileSyntaxError, UnrecognizedConfigProperty, InvalidPropertyValue,
214 CannotOpenFile.
|
215 kumpf 1.1 */
216 void GetOptions(
217 ConfigManager* cm,
218 int& argc,
|
219 mateus.baur 1.17 char** argv)
|
220 kumpf 1.1 {
|
221 kumpf 1.30 cm->mergeConfigFiles();
222 cm->mergeCommandLine(argc, argv);
|
223 kumpf 1.1 }
224
225 /* PrintHelp - This is temporary until we expand the options manager to allow
226 options help to be defined with the OptionRow entries and presented from
227 those entries.
228 */
229 void PrintHelp(const char* arg0)
230 {
231 String usage = String (USAGE);
232 usage.append (COMMAND_NAME);
233 usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
234 usage.append (" options\n");
|
235 mateus.baur 1.17 usage.append (" -v, --version - displays CIM Server version number\n");
236 usage.append (" -h, --help - prints this help message\n");
|
237 kumpf 1.3 usage.append (" -s - shuts down CIM Server\n");
|
238 mateus.baur 1.17 #if !defined(PEGASUS_USE_RELEASE_DIRS)
|
239 kumpf 1.3 usage.append (" -D [home] - sets pegasus home directory\n");
|
240 kumpf 1.1 #endif
241 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
242 mateus.baur 1.17 usage.append (" -install [name] - installs pegasus as a Windows Service\n");
|
243 kumpf 1.3 usage.append (" [name] is optional and overrides the\n");
244 usage.append (" default CIM Server Service Name\n");
|
245 mateus.baur 1.17 usage.append (" -remove [name] - removes pegasus as a Windows Service\n");
|
246 kumpf 1.3 usage.append (" [name] is optional and overrides the\n");
247 usage.append (" default CIM Server Service Name\n");
|
248 mateus.baur 1.17 usage.append (" -start [name] - starts pegasus as a Windows Service\n");
|
249 kumpf 1.3 usage.append (" [name] is optional and overrides the\n");
250 usage.append (" default CIM Server Service Name\n");
|
251 mateus.baur 1.17 usage.append (" -stop [name] - stops pegasus as a Windows Service\n");
|
252 kumpf 1.3 usage.append (" [name] is optional and overrides the\n");
253 usage.append (" default CIM Server Service Name\n\n");
|
254 kumpf 1.1 #endif
255 usage.append (" configProperty=value\n");
|
256 kumpf 1.3 usage.append (" - sets CIM Server configuration property\n");
|
257 kumpf 1.1
258 cout << endl;
|
259 mateus.baur 1.17 cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;
|
260 kumpf 1.1 cout << endl;
|
261 mateus.baur 1.17
262 #if defined(PEGASUS_OS_TYPE_WINDOWS)
263 MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
264 #elif defined(PEGASUS_USE_RELEASE_DIRS)
265 MessageLoaderParms parms("src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);
266 #else
267 MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
268 #endif
269 cout << MessageLoader::getMessage(parms) << endl;
270 }
271
272 //This needs to be called at various points in the code depending on the platform and error conditions.
273 //We need to delete the _cimServer reference on exit in order for the destructors to get called.
274 void deleteCIMServer()
275 {
276 if (_cimServer)
277 {
278 delete _cimServer;
279 _cimServer = 0;
280 }
|
281 mateus.baur 1.18
282 if (_monitor)
283 {
284 delete _monitor;
285 }
|
286 kumpf 1.1 }
287
|
288 mateus.baur 1.17 // l10n
|
289 kumpf 1.3 //
|
290 mateus.baur 1.17 // Dummy function for the Thread object associated with the initial thread.
291 // Since the initial thread is used to process CIM requests, this is
292 // needed to localize the exceptions thrown during CIM request processing.
293 // Note: This function should never be called!
294 //
|
295 mike 1.26 ThreadReturnType PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
|
296 mateus.baur 1.17 {
|
297 mike 1.26 return((ThreadReturnType)0);
|
298 kumpf 1.3 }
299
|
300 kumpf 1.1
301 /////////////////////////////////////////////////////////////////////////
302 // MAIN
303 //////////////////////////////////////////////////////////////////////////
304 int main(int argc, char** argv)
305 {
|
306 kumpf 1.28 String pegasusHome;
|
307 kumpf 1.1 Boolean shutdownOption = false;
|
308 mateus.baur 1.32 Boolean debugOutputOption = false;
|
309 mateus.baur 1.17
310 //l10n
311 // Set Message loading to process locale
312 MessageLoader::_useProcessLocale = true;
313 //l10n
314
315 //l10n
316 #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
317 setlocale(LC_ALL, "");
318 #endif
|
319 kumpf 1.1
|
320 kumpf 1.3 #ifndef PEGASUS_OS_TYPE_WINDOWS
|
321 kumpf 1.1 //
322 // Get environment variables:
323 //
|
324 mateus.baur 1.17 #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
325 pegasusHome = AIX_RELEASE_PEGASUS_HOME;
326 #elif !defined(PEGASUS_USE_RELEASE_DIRS)
|
327 kumpf 1.1 const char* tmp = getenv("PEGASUS_HOME");
328
329 if (tmp)
330 {
331 pegasusHome = tmp;
332 }
|
333 mateus.baur 1.17 #endif
|
334 kumpf 1.1
335 FileSystem::translateSlashes(pegasusHome);
|
336 kumpf 1.3 #else
|
337 kumpf 1.1
|
338 kumpf 1.3 // windows only
|
339 mateus.baur 1.17 //setHome(pegasusHome);
340 pegasusHome = _cimServerProcess->getHome();
|
341 kumpf 1.3 #endif
|
342 kumpf 1.1
343 // Get help, version, and shutdown options
|
344 kumpf 1.3
|
345 kumpf 1.1 for (int i = 1; i < argc; )
346 {
347 const char* arg = argv[i];
|
348 mateus.baur 1.17 if(String::equal(arg,"--help"))
349 {
350 PrintHelp(argv[0]);
351 exit(0);
352 }
353 else if(String::equal(arg,"--version"))
354 {
355 cout << _cimServerProcess->getVersion() << endl;
356 exit(0);
357 }
|
358 kumpf 1.1 // Check for -option
|
359 mateus.baur 1.17 else if (*arg == '-')
|
360 kumpf 1.1 {
361 // Get the option
362 const char* option = arg + 1;
363
364 //
365 // Check to see if user asked for the version (-v option):
366 //
|
367 kumpf 1.3 if (*option == OPTION_VERSION &&
368 strlen(option) == 1)
|
369 kumpf 1.1 {
|
370 mateus.baur 1.17 cout << _cimServerProcess->getVersion() << endl;
|
371 kumpf 1.1 exit(0);
372 }
373 //
374 // Check to see if user asked for help (-h option):
375 //
|
376 kumpf 1.3 else if (*option == OPTION_HELP &&
377 (strlen(option) == 1))
|
378 kumpf 1.1 {
379 PrintHelp(argv[0]);
380 exit(0);
381 }
|
382 mateus.baur 1.17 #if !defined(PEGASUS_USE_RELEASE_DIRS)
|
383 kumpf 1.3 else if (*option == OPTION_HOME &&
384 (strlen(option) == 1))
|
385 kumpf 1.1 {
386 if (i + 1 < argc)
387 {
388 pegasusHome.assign(argv[i + 1]);
389 }
390 else
391 {
|
392 mateus.baur 1.17 //l10n
393 //cout << "Missing argument for option -" << option << endl;
394 String opt(option);
395 MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
396 "Missing argument for option -$0",
397 opt);
398 cout << MessageLoader::getMessage(parms) << endl;
|
399 kumpf 1.1 exit(0);
400 }
401
402 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
403 argc -= 2;
404 }
405 #endif
406 #if defined(PEGASUS_OS_HPUX)
407 //
408 // Check to see if user asked for the version (-X option):
409 //
|
410 kumpf 1.3 if (*option == OPTION_BINDVERBOSE &&
411 (strlen(option) == 1))
|
412 kumpf 1.1 {
|
413 h.sterling 1.16 System::bindVerbose = true;
|
414 mateus.baur 1.17 //l10n
415 //cout << "Unsupported debug option, BIND_VERBOSE, enabled."
416 //<< endl;
417 MessageLoaderParms parms("src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
418 "Unsupported debug option, BIND_VERBOSE, enabled.");
419 cout << MessageLoader::getMessage(parms) << endl;
|
420 kumpf 1.1 // remove the option from the command line
421 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
422 argc--;
423 }
424 #endif
425 //
426 // Check to see if user asked for shutdown (-s option):
427 //
|
428 kumpf 1.3 else if (*option == OPTION_SHUTDOWN &&
429 (strlen(option) == 1))
|
430 kumpf 1.1 {
431 //
432 // Check to see if shutdown has already been specified:
433 //
434 if (shutdownOption)
435 {
|
436 mateus.baur 1.17 //l10n
437 //cout << "Duplicate shutdown option specified." << endl;
438 MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
439 "Duplicate shutdown option specified.");
440
441 cout << MessageLoader::getMessage(parms) << endl;
|
442 kumpf 1.1 exit(0);
443 }
444
445 shutdownOption = true;
446
447 // remove the option from the command line
448 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
449 argc--;
450 }
451 else
|
452 kumpf 1.3 i++;
|
453 kumpf 1.1 }
454 else
|
455 kumpf 1.3 i++;
|
456 kumpf 1.1 }
457
458 //
459 // Set the value for pegasusHome property
460 //
461 ConfigManager::setPegasusHome(pegasusHome);
462
463 //
|
464 mateus.baur 1.17 // Do the plaform specific run
465 //
466
|
467 mateus.baur 1.32 return _cimServerProcess->platform_run(
468 argc, argv, shutdownOption, debugOutputOption);
|
469 mateus.baur 1.17 }
470
471 void CIMServerProcess::cimserver_stop()
472 {
473 _cimServer->shutdownSignal();
474 }
475
476 //
477 // The main, common, running code
478 //
479 // NOTE: Do NOT call exit(). Use return(), otherwise some platforms
480 // will fail to shutdown properly/cleanly.
481 //
482 // TODO: Current change minimal for platform "service" shutdown bug fixes.
483 // Perhpas further extract out common stuff and put into main(), put
484 // daemon stuff into platform specific platform_run(), etc.
485 // Note: make sure to not put error handling stuff that platform
486 // specific runs may need to deal with bettter (instead of exit(), etc).
487 //
488
|
489 mateus.baur 1.32 int CIMServerProcess::cimserver_run(
490 int argc,
491 char** argv,
492 Boolean shutdownOption,
493 Boolean debugOutputOption)
|
494 mateus.baur 1.17 {
|
495 kumpf 1.28 String logsDirectory;
|
496 mateus.baur 1.17 Boolean daemonOption = false;
497
498 //
|
499 kumpf 1.1 // Get an instance of the Config Manager.
500 //
501 configManager = ConfigManager::getInstance();
|
502 kumpf 1.10 configManager->useConfigFiles = true;
|
503 kumpf 1.1
504 //
505 // Get options (from command line and from configuration file); this
506 // removes corresponding options and their arguments from the command
507 // line.
508 //
509 try
|
510 ouyang.jian 1.31 {
|
511 mateus.baur 1.17 GetOptions(configManager, argc, argv);
|
512 kumpf 1.1 }
513 catch (Exception& e)
514 {
|
515 mateus.baur 1.17 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
516 "src.Server.cimserver.SERVER_NOT_STARTED",
517 "cimserver not started: $0", e.getMessage());
518
519 MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
520 "cimserver not started: $0", e.getMessage());
521
522 PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
523 << PEGASUS_STD(endl);
524
525 return(1);
|
526 kumpf 1.1 }
527
|
528 kumpf 1.3 // l10n
|
529 h.sterling 1.16 // Set the home directory, msg sub-dir, into the MessageLoader.
530 // This will be the default directory where the resource bundles
|
531 mateus.baur 1.17 // are found.
532 MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
533 ConfigManager::getInstance()->getCurrentValue("messageDir")));
534
|
535 kumpf 1.25 Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
536 configManager->getCurrentValue("enableHttpConnection"));
537 Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
538 configManager->getCurrentValue("enableHttpsConnection"));
|
539 kumpf 1.2
540 // Make sure at least one connection is enabled
|
541 h.sterling 1.16 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
|
542 kumpf 1.2 if (!enableHttpConnection && !enableHttpsConnection)
543 {
|
544 mateus.baur 1.17 //l10n
545 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
546 //"Neither HTTP nor HTTPS connection is enabled. "
547 //"CIMServer will not be started.");
548 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
549 "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
550 "Neither HTTP nor HTTPS connection is enabled. CIMServer will not be started.");
551 //cerr << "Neither HTTP nor HTTPS connection is enabled. "
552 //"CIMServer will not be started." << endl;
553 MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
554 "Neither HTTP nor HTTPS connection is enabled. CIMServer will not be started.");
555 cerr << MessageLoader::getMessage(parms) << endl;
556 return(1);
|
557 kumpf 1.2 }
558 #endif
559
|
560 kumpf 1.1 try
561 {
562 //
563 // Check to see if we should Pegasus as a daemon
564 //
565
|
566 kumpf 1.25 daemonOption = ConfigManager::parseBooleanValue(
567 configManager->getCurrentValue("daemon"));
|
568 ouyang.jian 1.31
|
569 kumpf 1.3 logsDirectory =
|
570 h.sterling 1.16 ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
|
571 kumpf 1.1
572 // Set up the Logger. This does not open the logs
573 // Might be more logical to clean before set.
574 // ATTN: Need tool to completely disable logging.
575
|
576 ouyang.jian 1.31 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
577 kumpf 1.1 Logger::setHomeDirectory(logsDirectory);
578 #endif
579
580 //
581 // Check to see if we need to shutdown CIMOM
582 //
583 if (shutdownOption)
584 {
585 String configTimeout =
586 configManager->getCurrentValue("shutdownTimeout");
|
587 mateus.baur 1.17 Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
|
588 kumpf 1.30
589 ServerShutdownClient serverShutdownClient(&_serverRunStatus);
590 serverShutdownClient.shutdown(timeoutValue);
|
591 kumpf 1.1
|
592 kumpf 1.30 MessageLoaderParms parms(
593 "src.Server.cimserver.SERVER_STOPPED",
594 "CIM Server stopped.");
|
595 mateus.baur 1.17
596 cout << MessageLoader::getMessage(parms) << endl;
597 return(0);
|
598 kumpf 1.1 }
599
|
600 kumpf 1.30 #if defined(PEGASUS_DEBUG) && !defined(PEGASUS_USE_SYSLOGS)
|
601 kumpf 1.1 // Leave this in until people get familiar with the logs.
|
602 mateus.baur 1.17 MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
603 "Logs Directory = ");
604 cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
|
605 kumpf 1.1 #endif
606 }
|
607 kumpf 1.5 catch (UnrecognizedConfigProperty& e)
|
608 kumpf 1.1 {
|
609 mateus.baur 1.17 //l10n
610 //cout << "Error: " << e.getMessage() << endl;
611 MessageLoaderParms parms("src.Server.cimserver.ERROR",
612 "Error: $0",
613 e.getMessage());
614 cout << MessageLoader::getMessage(parms) << endl;
|
615 kumpf 1.1 }
616
|
617 mateus.baur 1.17 // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.
618 // 1) If the user explicitly specified a port, use it.
619 // 2) If the user did not specify a port, get the port from the services file.
620 // 3) If no value is specified in the services file, use the IANA WBEM default port.
621 // Note that 2 and 3 are done within the System::lookupPort method
622 // An empty string from the ConfigManager implies that the user did not specify a port.
623
624 Uint32 portNumberHttps=0;
625 Uint32 portNumberHttp=0;
626 Uint32 portNumberExportHttps=0;
|
627 kumpf 1.1
|
628 kumpf 1.2 if (enableHttpsConnection)
|
629 kumpf 1.1 {
|
630 kumpf 1.2 String httpsPort = configManager->getCurrentValue("httpsPort");
|
631 mateus.baur 1.17 if (httpsPort == String::EMPTY)
632 {
633 //
634 // Look up the WBEM-HTTPS port number
635 //
636 portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
637
638 } else
639 {
640 //
641 // user-specified
642 //
643 CString portString = httpsPort.getCString();
644 char* end = 0;
645 portNumberHttps = strtol(portString, &end, 10);
646 if(!(end != 0 && *end == '\0'))
647 {
|
648 mateus.baur 1.18 InvalidPropertyValue e("httpsPort", httpsPort);
649 cerr << e.getMessage() << endl;
|
650 mateus.baur 1.17 exit(1);
651 }
652 }
|
653 kumpf 1.1 }
|
654 kumpf 1.2
655 if (enableHttpConnection)
|
656 kumpf 1.1 {
|
657 kumpf 1.2 String httpPort = configManager->getCurrentValue("httpPort");
|
658 mateus.baur 1.17 if (httpPort == String::EMPTY)
659 {
660 //
661 // Look up the WBEM-HTTP port number
662 //
663 portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
|
664 kumpf 1.1
|
665 mateus.baur 1.17 } else
666 {
667 //
668 // user-specified
669 //
670 CString portString = httpPort.getCString();
671 char* end = 0;
672 portNumberHttp = strtol(portString, &end, 10);
673 if(!(end != 0 && *end == '\0'))
674 {
|
675 mateus.baur 1.18 InvalidPropertyValue e("httpPort", httpPort);
676 cerr << e.getMessage() << endl;
|
677 mateus.baur 1.17 exit(1);
678 }
679 }
|
680 kumpf 1.1 }
681
|
682 mateus.baur 1.17 #if defined(PEGASUS_DEBUG)
|
683 kumpf 1.1 // Put out startup up message.
|
684 mateus.baur 1.17 cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;
685 //l10n
686 //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
687 //cout <<"Starting..."
688 MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
689 "Built $0 $1\nStarting...",
690 __DATE__,
691 __TIME__);
692 #endif
693
694 //l10n
695 // reset message loading to NON-process locale
696 MessageLoader::_useProcessLocale = false;
697 //l10n
|
698 kumpf 1.3
|
699 mateus.baur 1.17 // Get the parent's PID before forking
|
700 kumpf 1.30 _serverRunStatus.setParentPid(System::getPID());
|
701 mateus.baur 1.17
|
702 kumpf 1.1 // do we need to run as a daemon ?
703 if (daemonOption)
704 {
|
705 mateus.baur 1.17 if(-1 == _cimServerProcess->cimserver_fork())
706 {
707 return(-1);
|
708 h.sterling 1.16 }
|
709 kumpf 1.1 }
710
|
711 mateus.baur 1.17 // l10n
712 // Now we are after the fork...
713 // Create a dummy Thread object that can be used to store the
|
714 kumpf 1.22 // AcceptLanguageList object for CIM requests that are serviced
|
715 mateus.baur 1.17 // by this thread (initial thread of server). Need to do this
716 // because this thread is not in a ThreadPool, but is used
717 // to service CIM requests.
718 // The run function for the dummy Thread should never be called,
719 Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
720 Thread::setCurrent(dummyInitialThread);
|
721 kumpf 1.22 AcceptLanguageList default_al;
|
722 mateus.baur 1.17 try{
|
723 kumpf 1.21 default_al = LanguageParser::getDefaultAcceptLanguages();
|
724 kumpf 1.22 Thread::setLanguages(new AcceptLanguageList(default_al));
|
725 mateus.baur 1.17 }catch(InvalidAcceptLanguageHeader& e){
726 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
727 "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
728 "Could not convert the system process locale into a valid AcceptLanguage format.");
729 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
730 e.getMessage());
731 }
732
733 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
734 || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
|
735 jim.wunderlich 1.19 || defined(PEGASUS_OS_SOLARIS) || defined (PEGASUS_OS_VMS)
|
736 kumpf 1.1 umask(S_IWGRP|S_IWOTH);
|
737 kumpf 1.2
738 //
739 // check if CIMServer is already running
740 // if CIMServer is already running, print message and
741 // notify parent process (if there is a parent process) to terminate
742 //
|
743 kumpf 1.30 if (_serverRunStatus.isServerRunning())
|
744 kumpf 1.2 {
|
745 kumpf 1.30 MessageLoaderParms parms(
746 "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
747 "Unable to start CIMServer.\nCIMServer is already running.");
748 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
749 PEGASUS_STD(endl);
|
750 kumpf 1.2
|
751 kumpf 1.30 //
|
752 kumpf 1.2 // notify parent process (if there is a parent process) to terminate
753 //
754 if (daemonOption)
|
755 kumpf 1.30 {
756 _cimServerProcess->notify_parent(1);
757 }
|
758 kumpf 1.2
|
759 kumpf 1.30 return 1;
|
760 kumpf 1.2 }
761
|
762 kumpf 1.1 #endif
763
764 // try loop to bind the address, and run the server
765 try
766 {
|
767 kumpf 1.30 _monitor = new Monitor();
768 _cimServer = new CIMServer(_monitor);
|
769 mateus.baur 1.17
|
770 kumpf 1.2
771 if (enableHttpConnection)
772 {
|
773 mateus.baur 1.32 _cimServer->addAcceptor(false, portNumberHttp, false);
|
774 kumpf 1.30
775 Logger::put_l(
776 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
777 "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
778 "Listening on HTTP port $0.", portNumberHttp);
|
779 kumpf 1.2 }
|
780 kumpf 1.30
|
781 kumpf 1.2 if (enableHttpsConnection)
782 {
|
783 mateus.baur 1.32 _cimServer->addAcceptor(false, portNumberHttps, true);
|
784 kumpf 1.30
785 Logger::put_l(
786 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
787 "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
788 "Listening on HTTPS port $0.", portNumberHttps);
|
789 mateus.baur 1.17 }
|
790 kumpf 1.9
|
791 h.sterling 1.16 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
|
792 mateus.baur 1.17 _cimServer->addAcceptor(true, 0, false, false);
|
793 kumpf 1.30 Logger::put_l(
794 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
795 "src.Server.cimserver.LISTENING_ON_LOCAL",
796 "Listening on local connection socket.");
|
797 kumpf 1.1 #endif
798
|
799 mateus.baur 1.17 #if defined(PEGASUS_DEBUG)
|
800 kumpf 1.2 if (enableHttpConnection)
801 {
|
802 kumpf 1.30 MessageLoaderParms parms(
803 "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
804 "Listening on HTTP port $0.", portNumberHttp);
|
805 mateus.baur 1.17 cout << MessageLoader::getMessage(parms) << endl;
|
806 kumpf 1.2 }
807 if (enableHttpsConnection)
808 {
|
809 kumpf 1.30 MessageLoaderParms parms(
810 "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
811 "Listening on HTTPS port $0.", portNumberHttps);
|
812 mateus.baur 1.17 cout << MessageLoader::getMessage(parms) << endl;
813 }
|
814 kumpf 1.9
|
815 h.sterling 1.16 # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
|
816 kumpf 1.30 MessageLoaderParms parms(
817 "src.Server.cimserver.LISTENING_ON_LOCAL",
818 "Listening on local connection socket.");
|
819 mateus.baur 1.17 cout << MessageLoader::getMessage(parms) << endl;
|
820 kumpf 1.3 # endif
|
821 kumpf 1.1 #endif
822
|
823 kumpf 1.3 // bind throws an exception if the bind fails
|
824 mateus.baur 1.18 try {
|
825 kumpf 1.30 _cimServer->bind();
826 }
827 catch (const BindFailedException &e)
|
828 mateus.baur 1.18 {
829 #ifdef PEGASUS_DEBUG
830 MessageLoaderParms parms("src.Server.cimserver.BIND_FAILED",
831 "Could not bind: $0.", e.getMessage());
832 cout << MessageLoader::getMessage(parms) << endl;
833 #endif
834 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
835 "src.Server.cimserver.BIND.FAILED",
836 "Could not bind: $0", e.getMessage());
|
837 kumpf 1.1
|
838 mateus.baur 1.18 deleteCIMServer();
839 return 1;
840 }
|
841 kumpf 1.30 // notify parent process (if there is a parent process) to terminate
|
842 kumpf 1.3 // so user knows that there is cimserver ready to serve CIM requests.
|
843 kumpf 1.30 if (daemonOption)
844 {
845 _cimServerProcess->notify_parent(0);
846 }
|
847 kumpf 1.2
|
848 kumpf 1.30 #if defined(PEGASUS_OS_HPUX) || \
849 defined(PEGASUS_OS_LINUX) || \
850 defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || \
851 defined(PEGASUS_OS_AIX) || \
852 defined(PEGASUS_OS_SOLARIS) || \
853 defined(PEGASUS_OS_VMS)
|
854 kumpf 1.1 //
855 // create a file to indicate that the cimserver has started and
856 // save the process id of the cimserver process in the file
857 //
|
858 kumpf 1.30 _serverRunStatus.setServerRunning();
|
859 kumpf 1.1 #endif
|
860 kumpf 1.3
|
861 mateus.baur 1.17 #if defined(PEGASUS_DEBUG)
|
862 h.sterling 1.16 cout << "Started. " << endl;
|
863 kumpf 1.1 #endif
|
864 mateus.baur 1.17
|
865 kumpf 1.1 // Put server started message to the logger
|
866 mateus.baur 1.17 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
867 Logger::INFORMATION,
868 "src.Server.cimserver.STARTED_VERSION",
869 "Started $0 version $1.",
870 _cimServerProcess->getProductName(), _cimServerProcess->getVersion());
|
871 kumpf 1.1
|
872 kumpf 1.3 //
|
873 kumpf 1.1 // Loop to call CIMServer's runForever() method until CIMServer
874 // has been shutdown
875 //
|
876 mateus.baur 1.17 while( !_cimServer->terminated() )
|
877 h.sterling 1.16 {
|
878 mateus.baur 1.17
879 _cimServer->runForever();
880
|
881 h.sterling 1.16 }
|
882 kumpf 1.1
883 //
884 // normal termination
|
885 mateus.baur 1.17 //
|
886 kumpf 1.12
|
887 kumpf 1.1 // Put server shutdown message to the logger
|
888 mateus.baur 1.17 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
889 Logger::INFORMATION, "src.Server.cimserver.STOPPED",
890 "$0 stopped.", _cimServerProcess->getProductName());
891
892 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
893 || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
|
894 jim.wunderlich 1.19 || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS)
|
895 kumpf 1.1 //
896 // close the file created at startup time to indicate that the
897 // cimserver has terminated normally.
898 //
|
899 mateus.baur 1.17 FileSystem::removeFile(_cimServerProcess->getPIDFileName());
|
900 kumpf 1.1 #endif
901 }
902 catch(Exception& e)
903 {
|
904 mateus.baur 1.17
905 //l10n
906 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
907 //"Error: $0", e.getMessage());
908 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
909 "src.Server.cimserver.ERROR",
910 "Error: $0", e.getMessage());
|
911 kumpf 1.2
|
912 mateus.baur 1.17 //l10n
913 //PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
914 MessageLoaderParms parms("src.Server.cimserver.ERROR",
915 "Error: $0", e.getMessage());
916 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
917
|
918 h.sterling 1.16 //
|
919 kumpf 1.3 // notify parent process (if there is a parent process) to terminate
|
920 kumpf 1.2 //
921 if (daemonOption)
|
922 mateus.baur 1.17 _cimServerProcess->notify_parent(1);
|
923 kumpf 1.2
|
924 mateus.baur 1.17 deleteCIMServer();
|
925 kumpf 1.1 return 1;
926 }
927
|
928 mateus.baur 1.17 deleteCIMServer();
|
929 kumpf 1.1 return 0;
930 }
|
931 mateus.baur 1.17
|