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