1 karl 1.179 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.32 //
|
3 karl 1.141 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.121 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.141 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.149 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.179 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.32 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 kumpf 1.58 // 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 mike 1.32 // 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 karl 1.179 //
|
21 kumpf 1.58 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
22 mike 1.32 // 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 kumpf 1.58 // 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 mike 1.32 // 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
35 //////////////////////////////////////////////////////////////////////
36 //
|
37 carolann.graves 1.171 // Notes on daemon operation (Unix) and service operation (Win 32):
|
38 mike 1.32 //
|
39 david.dillard 1.165 // To run pegasus as a daemon on Unix platforms:
|
40 mike 1.32 //
|
41 kumpf 1.60 // cimserver
|
42 mike 1.32 //
|
43 kumpf 1.60 // 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 david.dillard 1.165 // The daemon config property has no effect on windows operation.
|
49 mike 1.32 //
|
50 mike 1.35 // To shutdown pegasus, use the -s option:
|
51 david.dillard 1.165 //
52 // cimserver -s
|
53 mike 1.35 //
|
54 mike 1.32 // To run pegasus as an NT service, there are FOUR different possibilities:
55 //
|
56 david.dillard 1.165 // To INSTALL the Pegasus service,
|
57 mike 1.32 //
58 // cimserver -install
59 //
|
60 david.dillard 1.165 // To REMOVE the Pegasus service,
|
61 mike 1.32 //
62 // cimserver -remove
63 //
|
64 david.dillard 1.165 // To START the Pegasus service,
|
65 mike 1.32 //
66 // net start cimserver
|
67 s.hills 1.117 // or
68 // cimserver -start
|
69 mike 1.32 //
|
70 david.dillard 1.165 // To STOP the Pegasus service,
|
71 mike 1.32 //
72 // net stop cimserver
|
73 s.hills 1.117 // or
74 // cimserver -stop
|
75 mike 1.32 //
|
76 david.dillard 1.165 // Alternatively, you can use the windows service manager. Pegasus shows up
|
77 mike 1.32 // in the service database as "Pegasus CIM Object Manager"
78 //
79 //////////////////////////////////////////////////////////////////////
80
81
|
82 mike 1.35 #include <Pegasus/Common/Config.h>
|
83 kumpf 1.59 #include <Pegasus/Common/Constants.h>
|
84 jim.wunderlich 1.172 #include <Pegasus/Common/PegasusAssert.h>
|
85 mike 1.32 #include <Pegasus/Common/FileSystem.h>
86 #include <Pegasus/Common/PegasusVersion.h>
87 #include <Pegasus/Common/Logger.h>
88 #include <Pegasus/Common/System.h>
|
89 mike 1.35 #include <Pegasus/Common/Tracer.h>
|
90 kumpf 1.174 #include <Pegasus/Common/LanguageParser.h>
|
91 mike 1.35 #include <Pegasus/Config/ConfigManager.h>
92 #include <Pegasus/Client/CIMClient.h>
|
93 h.sterling 1.153 #include <Pegasus/Server/CIMServer.h>
94 #include <Service/ServerProcess.h>
|
95 kumpf 1.198 #include <Service/ServerShutdownClient.h>
96 #include <Service/ServerRunStatus.h>
|
97 mike 1.32
|
98 kumpf 1.202 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
99 thilo.boehm 1.185 #include <Service/ARM_zOS.h>
|
100 marek 1.186 # ifdef PEGASUS_ZOS_SECURITY
101 // This include file will not be provided in the OpenGroup CVS for now.
102 // Do NOT try to include it in your compile
103 # include <Pegasus/Common/safCheckzOS_inline.h>
104 # endif
|
105 thilo.boehm 1.185 #endif
106
|
107 kumpf 1.178 #if defined(PEGASUS_OS_TYPE_UNIX)
|
108 ouyang.jian 1.200 # include <unistd.h>
|
109 kumpf 1.178 # include <sys/types.h>
110 # include <sys/stat.h>
111 # include <fcntl.h>
|
112 mateus.baur 1.175 #endif
113
|
114 kumpf 1.199 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
115 # define PEGASUS_PROCESS_NAME "cimservermain"
116 #else
117 # define PEGASUS_PROCESS_NAME "cimserver"
118 #endif
119
120 #include <Pegasus/Common/Executor.h>
121
|
122 kumpf 1.119 PEGASUS_USING_PEGASUS;
123 PEGASUS_USING_STD;
124
|
125 h.sterling 1.153 //Windows service variables are not defined elsewhere in the product
126 //enable ability to override these
127 #ifndef PEGASUS_SERVICE_NAME
128 #define PEGASUS_SERVICE_NAME "Pegasus CIM Object Manager";
|
129 chuck 1.66 #endif
|
130 h.sterling 1.153 #ifndef PEGASUS_SERVICE_DESCRIPTION
131 #define PEGASUS_SERVICE_DESCRIPTION "Pegasus CIM Object Manager Service";
|
132 mike 1.32 #endif
133
|
134 h.sterling 1.153 class CIMServerProcess : public ServerProcess
135 {
136 public:
137
|
138 kumpf 1.203 CIMServerProcess()
|
139 h.sterling 1.153 {
140 cimserver_set_process(this);
141 }
142
|
143 kumpf 1.203 virtual ~CIMServerProcess()
|
144 h.sterling 1.153 {
145 }
146
147 //defined in PegasusVersion.h
148 virtual const char* getProductName() const
149 {
150 return PEGASUS_PRODUCT_NAME;
151 }
152
153 virtual const char* getExtendedName() const
154 {
155 return PEGASUS_SERVICE_NAME;
156 }
157
158 virtual const char* getDescription() const
159 {
160 return PEGASUS_SERVICE_DESCRIPTION;
161 }
|
162 david.dillard 1.165
|
163 h.sterling 1.153 //defined in PegasusVersion.h
|
164 jim.wunderlich 1.180 virtual const char* getCompleteVersion() const
165 {
|
166 jim.wunderlich 1.181 if (*PEGASUS_PRODUCT_STATUS == '\0' )
|
167 kumpf 1.199 return PEGASUS_PRODUCT_VERSION;
|
168 jim.wunderlich 1.180 else
|
169 kumpf 1.202 return PEGASUS_PRODUCT_VERSION " " PEGASUS_PRODUCT_STATUS;
|
170 jim.wunderlich 1.180 }
171
172 //defined in PegasusVersion.h
|
173 h.sterling 1.153 virtual const char* getVersion() const
174 {
175 return PEGASUS_PRODUCT_VERSION;
176 }
177
178 virtual const char* getProcessName() const
179 {
180 return PEGASUS_PROCESS_NAME;
181 }
182
|
183 kumpf 1.178 int cimserver_run(
184 int argc,
185 char** argv,
186 Boolean shutdownOption,
187 Boolean debugOutputOption);
|
188 h.sterling 1.153
|
189 kumpf 1.203 void cimserver_stop();
|
190 h.sterling 1.153 };
191
|
192 kumpf 1.198 ServerRunStatus _serverRunStatus(
193 PEGASUS_PROCESS_NAME, PEGASUS_CIMSERVER_START_FILE);
|
194 h.sterling 1.153 AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
195 static CIMServer* _cimServer = 0;
|
196 konrad.r 1.166 static Thread* dummyInitialThread = 0;
|
197 kumpf 1.203
|
198 mike 1.35 //
199 // The command name.
200 //
201 static const char COMMAND_NAME [] = "cimserver";
202
203 //
204 // The constant defining usage string.
205 //
206 static const char USAGE [] = "Usage: ";
207
208 /**
209 Constants representing the command line options.
210 */
211 static const char OPTION_VERSION = 'v';
212
213 static const char OPTION_HELP = 'h';
214
215 static const char OPTION_HOME = 'D';
216
217 static const char OPTION_SHUTDOWN = 's';
218
|
219 kumpf 1.203 static const char LONG_HELP[] = "help";
|
220 a.arora 1.142
|
221 kumpf 1.203 static const char LONG_VERSION[] = "version";
|
222 a.arora 1.142
|
223 kumpf 1.178 static const char OPTION_DEBUGOUTPUT = 'X';
|
224 kumpf 1.48
|
225 mike 1.32 /** GetOptions function - This function defines the Options Table
|
226 mike 1.35 and sets up the options from that table using the config manager.
|
227 kumpf 1.198
228 Some possible exceptions: NoSuchFile, FileNotReadable, CannotRenameFile,
229 ConfigFileSyntaxError, UnrecognizedConfigProperty, InvalidPropertyValue,
230 CannotOpenFile.
|
231 mike 1.32 */
232 void GetOptions(
|
233 mike 1.35 ConfigManager* cm,
|
234 mike 1.32 int& argc,
|
235 mateus.baur 1.193 char** argv,
|
236 kumpf 1.198 Boolean shutdownOption)
|
237 mike 1.32 {
|
238 kumpf 1.198 if (shutdownOption)
239 {
240 cm->loadConfigFiles();
241 }
242 else
|
243 mike 1.32 {
|
244 kumpf 1.198 cm->mergeConfigFiles();
245 }
|
246 mateus.baur 1.193
|
247 kumpf 1.198 // Temporarily disable updates to the current configuration
248 // file if shutdownOption is true
249 cm->useConfigFiles = (shutdownOption==false);
|
250 mike 1.33
|
251 kumpf 1.198 cm->mergeCommandLine(argc, argv);
|
252 mateus.baur 1.193
|
253 kumpf 1.198 // Enable updates again
254 cm->useConfigFiles = true;
|
255 mike 1.32 }
256
257 /* PrintHelp - This is temporary until we expand the options manager to allow
258 options help to be defined with the OptionRow entries and presented from
259 those entries.
260 */
261 void PrintHelp(const char* arg0)
262 {
|
263 mike 1.35 String usage = String (USAGE);
|
264 kumpf 1.202 usage.append(COMMAND_NAME);
265 usage.append(" [ [ options ] | [ configProperty=value, ... ] ]\n");
266 usage.append(" options\n");
267 usage.append(" -v, --version - displays CIM Server version number\n");
268 usage.append(" -h, --help - prints this help message\n");
269 usage.append(" -s - shuts down CIM Server\n");
|
270 kumpf 1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
|
271 kumpf 1.202 usage.append(" -D [home] - sets pegasus home directory\n");
|
272 humberto 1.97 #endif
273 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
274 kumpf 1.202 usage.append(" -install [name] - installs pegasus as a Windows "
275 "Service\n");
276 usage.append(" [name] is optional and overrides "
277 "the\n");
278 usage.append(" default CIM Server Service Name\n");
279 usage.append(" by appending [name]\n");
280 usage.append(" -remove [name] - removes pegasus as a Windows "
281 "Service\n");
282 usage.append(" [name] is optional and overrides "
283 "the\n");
284 usage.append(" default CIM Server Service Name\n");
285 usage.append(" by appending [name]\n");
286 usage.append(" -start [name] - starts pegasus as a Windows Service\n");
287 usage.append(" [name] is optional and overrides "
288 "the\n");
289 usage.append(" default CIM Server Service Name\n");
290 usage.append(" by appending [name]\n");
291 usage.append(" -stop [name] - stops pegasus as a Windows Service\n");
292 usage.append(" [name] is optional and overrides "
293 "the\n");
294 usage.append(" default CIM Server Service Name\n");
295 kumpf 1.202 usage.append(" by appending [name]\n\n");
296 #endif
297 usage.append(" configProperty=value\n");
298 usage.append(" - sets CIM Server configuration "
299 "property\n");
|
300 humberto 1.97
301 cout << endl;
|
302 kumpf 1.202 cout << _cimServerProcess->getProductName() << " " <<
303 _cimServerProcess->getCompleteVersion() << endl;
|
304 humberto 1.97 cout << endl;
|
305 david.dillard 1.165
|
306 humberto 1.97 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
307 humberto 1.104 MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
|
308 kumpf 1.152 #elif defined(PEGASUS_USE_RELEASE_DIRS)
|
309 kumpf 1.202 MessageLoaderParms parms(
310 "src.Server.cimserver.MENU.HPUXLINUXIA64GNU",
311 usage);
|
312 humberto 1.97 #else
|
313 kumpf 1.138 MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
|
314 humberto 1.97 #endif
315 cout << MessageLoader::getMessage(parms) << endl;
|
316 mike 1.35 }
317
|
318 kumpf 1.202 // This needs to be called at various points in the code depending on the
319 // platform and error conditions.
320 // We need to delete the _cimServer reference on exit in order for the
321 // destructors to get called.
|
322 h.sterling 1.156 void deleteCIMServer()
323 {
|
324 kumpf 1.203 delete _cimServer;
325 _cimServer = 0;
|
326 kumpf 1.202
327 if (dummyInitialThread)
328 {
|
329 kumpf 1.199 Thread::clearLanguages();
330 delete dummyInitialThread;
|
331 kumpf 1.202 }
|
332 h.sterling 1.156 }
333
|
334 chuck 1.96 //
335 // Dummy function for the Thread object associated with the initial thread.
336 // Since the initial thread is used to process CIM requests, this is
337 // needed to localize the exceptions thrown during CIM request processing.
|
338 david.dillard 1.165 // Note: This function should never be called!
339 //
|
340 kumpf 1.202 ThreadReturnType PEGASUS_THREAD_CDECL dummyThreadFunc(void* parm)
|
341 chuck 1.96 {
|
342 kumpf 1.202 return (ThreadReturnType)0;
|
343 chuck 1.96 }
344
|
345 kumpf 1.199 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
346
347 static int _extractExecutorSockOpt(int& argc, char**& argv)
348 {
349 // Extract the "--executor-socket <sock>" option if any. This indicates
350 // that the e[x]ecutor is running. The option argument is the socket used
351 // to communicate with the executor. Remove the option from the
352 // argv list and decrease argc by two.
353
354 int sock = -1;
355 const char OPT[] = "--executor-socket";
356
357 for (int i = 1; i < argc; i++)
358 {
359 if (strcmp(argv[i], OPT) == 0)
360 {
361 // Check for missing option argument.
362
363 if (i + 1 == argc)
364 {
365 MessageLoaderParms parms(
366 kumpf 1.199 "src.Server.cimserver.MISSING_OPTION_ARGUMENT",
367 "Missing argument for $0 option.",
368 OPT);
369 cerr << argv[0] << ": " << MessageLoader::getMessage(parms) <<
370 endl;
371 exit(1);
372 }
373
374 // Convert argument to positive integer.
375
376 char* end;
377 unsigned long x = strtoul(argv[i+1], &end, 10);
378
379 // Check whether option argument will fit in a signed integer.
380
381 if (*end != '\0' || x > 2147483647)
382 {
383 MessageLoaderParms parms(
384 "src.Server.cimserver.BAD_OPTION_ARGUMENT",
385 "Bad $0 option argument: $1.",
386 OPT,
387 kumpf 1.199 argv[i+1]);
388 cerr << argv[0] << ": " << MessageLoader::getMessage(parms) <<
389 endl;
390 exit(1);
391 }
392
393 sock = int(x);
394
395 // Remove "-x <sock>" from argv-argc.
396
397 memmove(argv + i, argv + i + 2, sizeof(char*) * (argc - i - 1));
398 argc -= 2;
399 break;
400 }
401 }
402
403 if (sock == -1)
404 {
405 MessageLoaderParms parms(
406 "src.Server.cimserver.MISSING_OPTION",
407 "Missing $0 option.",
408 kumpf 1.199 OPT);
409 cerr << argv[0] << ": " << MessageLoader::getMessage(parms) << endl;
410 exit(1);
411 }
412
413 return sock;
414 }
415
416 #endif /* PEGASUS_ENABLE_PRIVILEGE_SEPARATION */
|
417 mike 1.35
|
418 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
419 mike 1.32 // MAIN
420 //////////////////////////////////////////////////////////////////////////
|
421 kumpf 1.199
|
422 mike 1.32 int main(int argc, char** argv)
423 {
|
424 kumpf 1.196 String pegasusHome;
|
425 mike 1.35 Boolean shutdownOption = false;
|
426 kumpf 1.178 Boolean debugOutputOption = false;
|
427 mday 1.47
|
428 kumpf 1.202 // Set Message loading to process locale
429 MessageLoader::_useProcessLocale = true;
|
430 humberto 1.97
|
431 kv.le 1.140 #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
|
432 kumpf 1.202 setlocale(LC_ALL, "");
|
433 kv.le 1.140 #endif
434
|
435 tony 1.82 #ifndef PEGASUS_OS_TYPE_WINDOWS
|
436 kumpf 1.38 //
437 // Get environment variables:
438 //
|
439 kumpf 1.202 # if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
|
440 kv.le 1.134 pegasusHome = AIX_RELEASE_PEGASUS_HOME;
|
441 kumpf 1.202 # elif !defined(PEGASUS_USE_RELEASE_DIRS) || \
442 defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
443 kumpf 1.38 const char* tmp = getenv("PEGASUS_HOME");
444
445 if (tmp)
446 {
447 pegasusHome = tmp;
448 }
|
449 kumpf 1.202 # endif
|
450 kumpf 1.38
451 FileSystem::translateSlashes(pegasusHome);
|
452 tony 1.82 #else
|
453 kumpf 1.38
|
454 kumpf 1.202 // windows only
455 //setHome(pegasusHome);
456 pegasusHome = _cimServerProcess->getHome();
|
457 tony 1.82 #endif
|
458 mike 1.32
|
459 kumpf 1.199 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
460
461 // If invoked with "--executor-socket <socket>" option, then use executor.
462
463 Executor::setSock(_extractExecutorSockOpt(argc, argv));
464
465 // Ping executor to verify the specified socket is valid.
466
467 if (Executor::ping() != 0)
468 {
469 MessageLoaderParms parms("src.Server.cimserver.EXECUTOR_PING_FAILED",
470 "Failed to ping the executor on the specified socket.");
471 cerr << argv[0] << ": " << MessageLoader::getMessage(parms) << endl;
472 exit(1);
473 }
474
475 #endif /* !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) */
476
|
477 kumpf 1.60 // Get help, version, and shutdown options
|
478 mike 1.35
479 for (int i = 1; i < argc; )
480 {
481 const char* arg = argv[i];
|
482 kumpf 1.202 if (String::equal(arg,"--help"))
|
483 a.arora 1.142 {
484 PrintHelp(argv[0]);
485 exit(0);
486 }
|
487 kumpf 1.202 else if (String::equal(arg,"--version"))
|
488 a.arora 1.142 {
|
489 jim.wunderlich 1.180 cout << _cimServerProcess->getCompleteVersion() << endl;
|
490 a.arora 1.142 exit(0);
491 }
|
492 mike 1.35 // Check for -option
|
493 a.arora 1.142 else if (*arg == '-')
|
494 mike 1.35 {
495 // Get the option
496 const char* option = arg + 1;
497
498 //
499 // Check to see if user asked for the version (-v option):
500 //
|
501 tony 1.83 if (*option == OPTION_VERSION &&
502 strlen(option) == 1)
|
503 mike 1.35 {
|
504 jim.wunderlich 1.180 cout << _cimServerProcess->getCompleteVersion() << endl;
|
505 mike 1.35 exit(0);
506 }
507 //
508 // Check to see if user asked for help (-h option):
509 //
|
510 tony 1.83 else if (*option == OPTION_HELP &&
511 (strlen(option) == 1))
|
512 mike 1.35 {
513 PrintHelp(argv[0]);
514 exit(0);
515 }
|
516 kumpf 1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
|
517 tony 1.83 else if (*option == OPTION_HOME &&
518 (strlen(option) == 1))
|
519 mike 1.35 {
|
520 kumpf 1.60 if (i + 1 < argc)
|
521 mike 1.35 {
522 pegasusHome.assign(argv[i + 1]);
523 }
524 else
525 {
|
526 humberto 1.99 String opt(option);
|
527 kumpf 1.202 MessageLoaderParms parms(
528 "src.Server.cimserver.MISSING_ARGUMENT",
529 "Missing argument for option -$0",
530 opt);
|
531 h.sterling 1.153 cout << MessageLoader::getMessage(parms) << endl;
|
532 mike 1.35 exit(0);
533 }
534
535 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
536 argc -= 2;
537 }
|
538 kumpf 1.63 #endif
|
539 kumpf 1.48 //
|
540 kumpf 1.178 // Check to see if user asked for debug output (-X option):
|
541 kumpf 1.48 //
|
542 kumpf 1.178 else if (*option == OPTION_DEBUGOUTPUT &&
|
543 tony 1.83 (strlen(option) == 1))
|
544 kumpf 1.48 {
|
545 kumpf 1.178 MessageLoaderParms parms(
546 "src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
547 "Unsupported debug output option is enabled.");
|
548 h.sterling 1.153 cout << MessageLoader::getMessage(parms) << endl;
|
549 kumpf 1.178
550 debugOutputOption = true;
551
552 #if defined(PEGASUS_OS_HPUX)
553 System::bindVerbose = true;
554 #endif
555
|
556 kumpf 1.48 // remove the option from the command line
557 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
|
558 david.dillard 1.165 argc--;
|
559 kumpf 1.48 }
|
560 mike 1.35 //
561 // Check to see if user asked for shutdown (-s option):
562 //
|
563 tony 1.82 else if (*option == OPTION_SHUTDOWN &&
564 (strlen(option) == 1))
|
565 mike 1.35 {
566 //
|
567 kumpf 1.52 // Check to see if shutdown has already been specified:
|
568 mike 1.35 //
|
569 kumpf 1.52 if (shutdownOption)
|
570 mike 1.35 {
|
571 kumpf 1.202 MessageLoaderParms parms(
572 "src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
573 "Duplicate shutdown option specified.");
|
574 david.dillard 1.165
|
575 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
576 mike 1.35 exit(0);
577 }
578
|
579 kumpf 1.52 shutdownOption = true;
|
580 david.dillard 1.165
|
581 mike 1.35 // remove the option from the command line
582 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
|
583 david.dillard 1.165 argc--;
|
584 mike 1.35 }
585 else
586 i++;
587 }
588 else
589 i++;
|
590 mike 1.32 }
|
591 mike 1.35
|
592 kumpf 1.38 //
593 // Set the value for pegasusHome property
594 //
595 ConfigManager::setPegasusHome(pegasusHome);
|
596 mike 1.32
|
597 mike 1.35 //
|
598 carolann.graves 1.171 // Do the platform specific run
|
599 s.hills 1.117 //
600
|
601 kumpf 1.178 return _cimServerProcess->platform_run(
602 argc, argv, shutdownOption, debugOutputOption);
|
603 s.hills 1.117 }
604
|
605 h.sterling 1.153 void CIMServerProcess::cimserver_stop()
606 {
607 _cimServer->shutdownSignal();
608 }
|
609 s.hills 1.117
610 //
611 // The main, common, running code
612 //
|
613 david.dillard 1.165 // NOTE: Do NOT call exit(). Use return(), otherwise some platforms
|
614 s.hills 1.117 // will fail to shutdown properly/cleanly.
615 //
|
616 david.dillard 1.165 // TODO: Current change minimal for platform "service" shutdown bug fixes.
|
617 carolann.graves 1.171 // Perhaps further extract out common stuff and put into main(), put
|
618 david.dillard 1.165 // daemon stuff into platform specific platform_run(), etc.
619 // Note: make sure to not put error handling stuff that platform
|
620 carolann.graves 1.171 // specific runs may need to deal with better (instead of exit(), etc).
|
621 s.hills 1.117 //
622
|
623 kumpf 1.178 int CIMServerProcess::cimserver_run(
624 int argc,
625 char** argv,
626 Boolean shutdownOption,
627 Boolean debugOutputOption)
|
628 s.hills 1.117 {
629 Boolean daemonOption = false;
630
631 //
|
632 mike 1.35 // Get an instance of the Config Manager.
633 //
|
634 kumpf 1.203 ConfigManager* configManager = ConfigManager::getInstance();
|
635 kumpf 1.136 configManager->useConfigFiles = true;
|
636 mike 1.35
|
637 mike 1.32 try
638 {
|
639 kumpf 1.203 //
640 // Get options (from command line and from configuration file); this
641 // removes corresponding options and their arguments from the command
642 // line. NOTE: If shutdownOption=true, the contents of current config
643 // file are not overwritten by the planned config file.
644 //
|
645 mateus.baur 1.193 GetOptions(configManager, argc, argv, shutdownOption);
|
646 kumpf 1.127
|
647 kumpf 1.203 //
648 // Initialize the message home directory in the MessageLoader.
649 // This is the default directory where the resource bundles are found.
650 //
651 MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
652 ConfigManager::getInstance()->getCurrentValue("messageDir")));
|
653 kumpf 1.86
|
654 mike 1.35 //
|
655 kumpf 1.187 // Check to see if we should start Pegasus as a daemon
|
656 mike 1.35 //
|
657 kumpf 1.187 daemonOption = ConfigManager::parseBooleanValue(
658 configManager->getCurrentValue("daemon"));
|
659 david.dillard 1.165
|
660 konrad.r 1.161 #if !defined(PEGASUS_USE_SYSLOGS)
|
661 kumpf 1.203 String logsDirectory = ConfigManager::getHomedPath(
662 configManager->getCurrentValue("logdir"));
|
663 kumpf 1.36
|
664 kumpf 1.203 // Set up the Logger. This does not open the logs.
|
665 kumpf 1.36 // Might be more logical to clean before set.
666 Logger::setHomeDirectory(logsDirectory);
|
667 kumpf 1.57 #endif
|
668 kumpf 1.36
669 //
|
670 david.dillard 1.165 // Check to see if we need to shutdown CIMOM
|
671 mike 1.35 //
672 if (shutdownOption)
673 {
|
674 david.dillard 1.165 String configTimeout =
|
675 kumpf 1.60 configManager->getCurrentValue("shutdownTimeout");
|
676 kumpf 1.202 Uint32 timeoutValue =
677 strtol(configTimeout.getCString(), (char **)0, 10);
|
678 dave.sudlik 1.191 #ifdef PEGASUS_SLP_REG_TIMEOUT
|
679 kumpf 1.202 // To deregister Pegasus with SLP
|
680 dave.sudlik 1.191 unregisterPegasusFromSLP();
681 #endif
|
682 david.dillard 1.165
|
683 kumpf 1.198 ServerShutdownClient serverShutdownClient(&_serverRunStatus);
684 serverShutdownClient.shutdown(timeoutValue);
|
685 kumpf 1.45
|
686 kumpf 1.198 MessageLoaderParms parms(
687 "src.Server.cimserver.SERVER_STOPPED",
688 "CIM Server stopped.");
|
689 humberto 1.106
|
690 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
691 kumpf 1.202 return 0;
|
692 mike 1.35 }
|
693 mike 1.32
|
694 kumpf 1.198 #if defined(PEGASUS_DEBUG) && !defined(PEGASUS_USE_SYSLOGS)
|
695 kumpf 1.36 // Leave this in until people get familiar with the logs.
|
696 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
|
697 h.sterling 1.153 "Logs Directory = ");
|
698 humberto 1.97 cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
|
699 kumpf 1.57 #endif
|
700 mike 1.32 }
|
701 kumpf 1.203 catch (Exception& e)
|
702 mike 1.32 {
|
703 kumpf 1.203 MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
704 "cimserver not started: $0", e.getMessage());
705 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
706 MessageLoader::getMessage(parms));
707 cerr << MessageLoader::getMessage(parms) << endl;
708
709 return 1;
|
710 marek 1.186 }
|
711 david 1.85
|
712 marek 1.186 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && defined(PEGASUS_ZOS_SECURITY)
713 startupCheckBPXServer(true);
714 startupCheckProfileCIMSERVclassWBEM();
715 startupEnableMSC();
|
716 david 1.85 #endif
|
717 mike 1.32
|
718 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
719 mike 1.32 // Put out startup up message.
|
720 kumpf 1.202 cout << _cimServerProcess->getProductName() << " " <<
721 _cimServerProcess->getCompleteVersion() << endl;
|
722 humberto 1.97 #endif
723
|
724 kumpf 1.202 // reset message loading to NON-process locale
725 MessageLoader::_useProcessLocale = false;
|
726 mike 1.32
|
727 kumpf 1.137 // Get the parent's PID before forking
|
728 kumpf 1.198 _serverRunStatus.setParentPid(System::getPID());
|
729 david.dillard 1.165
|
730 kumpf 1.202 // Do not fork when using privilege separation (executor will daemonize
731 // itself later).
|
732 kumpf 1.63 if (daemonOption)
733 {
|
734 kumpf 1.202 if (-1 == _cimServerProcess->cimserver_fork())
735 return -1;
|
736 kumpf 1.63 }
|
737 chuck 1.66
|
738 chuck 1.96 // Now we are after the fork...
739 // Create a dummy Thread object that can be used to store the
|
740 kumpf 1.176 // AcceptLanguageList object for CIM requests that are serviced
|
741 chuck 1.96 // by this thread (initial thread of server). Need to do this
742 // because this thread is not in a ThreadPool, but is used
743 // to service CIM requests.
744 // The run function for the dummy Thread should never be called,
|
745 konrad.r 1.166 dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
|
746 david.dillard 1.165 Thread::setCurrent(dummyInitialThread);
|
747 kumpf 1.176 AcceptLanguageList default_al;
|
748 kumpf 1.202 try
749 {
|
750 kumpf 1.203 default_al = LanguageParser::getDefaultAcceptLanguages();
751 Thread::setLanguages(new AcceptLanguageList(default_al));
|
752 kumpf 1.202 }
753 catch (InvalidAcceptLanguageHeader& e)
754 {
|
755 kumpf 1.203 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
756 "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
757 "Could not convert the system process locale into a valid "
758 "AcceptLanguage format.");
759 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
760 e.getMessage());
|
761 humberto 1.108 }
|
762 david.dillard 1.165
|
763 kumpf 1.167 #ifndef PEGASUS_OS_TYPE_WINDOWS
764 umask(S_IRWXG|S_IRWXO);
765 #endif
|
766 mday 1.62
|
767 kumpf 1.203 // Start up the CIM Server
|
768 mateus.baur 1.175
|
769 kumpf 1.203 try
770 {
|
771 mateus.baur 1.175 #if defined(PEGASUS_OS_TYPE_UNIX)
|
772 kumpf 1.203 //
773 // Lock the CIMSERVER_LOCK_FILE during CIM Server start-up to prevent
774 // concurrent writes to this file by multiple cimserver processes
775 // starting at the same time.
776 //
777 CString startupLockFileName = ConfigManager::getHomedPath(
|
778 kumpf 1.204 PEGASUS_CIMSERVER_START_LOCK_FILE).getCString();
|
779 kumpf 1.203
780 // Make sure the start-up lock file exists
781 FILE* startupLockFile;
782 if ((startupLockFile = fopen(startupLockFileName, "w")) != 0)
783 {
784 fclose(startupLockFile);
785 }
|
786 kumpf 1.202
|
787 kumpf 1.203 AutoFileLock fileLock(startupLockFileName);
788 #endif
|
789 kumpf 1.202
|
790 kumpf 1.203 #if defined(PEGASUS_OS_TYPE_UNIX) || defined(PEGASUS_OS_VMS)
791 //
792 // Check if a CIM Server is already running. If so, print an error
793 // message and notify the parent process (if there is one) to terminate
794 //
795 if (_serverRunStatus.isServerRunning())
796 {
797 MessageLoaderParms parms(
798 "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
799 "Unable to start CIMServer. CIMServer is already running.");
800 Logger::put(
801 Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
802 MessageLoader::getMessage(parms));
803 cerr << MessageLoader::getMessage(parms) << endl;
|
804 mateus.baur 1.175
|
805 kumpf 1.203 if (daemonOption)
806 {
807 _cimServerProcess->notify_parent(1);
808 }
|
809 kumpf 1.79
|
810 kumpf 1.203 return 1;
811 }
|
812 kumpf 1.79
|
813 kumpf 1.198 //
|
814 kumpf 1.203 // Declare ourselves as the running CIM Server process, and write our
815 // PID to the PID file.
|
816 kumpf 1.79 //
|
817 kumpf 1.203 _serverRunStatus.setServerRunning();
818 #endif
819
820 // Create and initialize the CIMServer object
821
822 _cimServer = new CIMServer();
823
824 Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
825 configManager->getCurrentValue("enableHttpConnection"));
826 Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
827 configManager->getCurrentValue("enableHttpsConnection"));
828
829 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
830 // Make sure at least one connection is enabled
831 if (!enableHttpConnection && !enableHttpsConnection)
|
832 kumpf 1.198 {
|
833 kumpf 1.203 MessageLoaderParms parms(
834 "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
835 "Neither HTTP nor HTTPS connection is enabled.");
836 throw Exception(parms);
|
837 kumpf 1.198 }
|
838 kumpf 1.63 #endif
|
839 kumpf 1.51
|
840 kumpf 1.203 // The server HTTP and HTTPS ports are determined via this algorithm:
841 // 1) If the user explicitly specified a port, use it.
842 // 2) If the user did not specify a port, get the port from the
843 // services file.
844 // 3) If no value is specified in the services file, use the IANA WBEM
845 // default port.
846 // Note that 2 and 3 are done within the System::lookupPort method
847 // An empty string from the ConfigManager implies that the user did not
848 // specify a port.
|
849 kumpf 1.41
|
850 kumpf 1.86 if (enableHttpConnection)
851 {
|
852 kumpf 1.203 Uint32 portNumberHttp = 0;
853 String httpPort = configManager->getCurrentValue("httpPort");
854 if (httpPort == String::EMPTY)
855 {
856 //
857 // Look up the WBEM-HTTP port number
858 //
859 portNumberHttp = System::lookupPort(
860 WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
861 }
862 else
863 {
864 //
865 // user-specified
866 //
867 CString portString = httpPort.getCString();
868 char* end = 0;
869 portNumberHttp = strtol(portString, &end, 10);
870 if (!(end != 0 && *end == '\0'))
871 {
872 throw InvalidPropertyValue("httpPort", httpPort);
873 kumpf 1.203 }
874 }
875
|
876 sushma.fernandes 1.189 _cimServer->addAcceptor(false, portNumberHttp, false);
|
877 kumpf 1.198
|
878 kumpf 1.203 MessageLoaderParms parms(
|
879 kumpf 1.198 "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
880 "Listening on HTTP port $0.", portNumberHttp);
|
881 kumpf 1.203 Logger::put(
882 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
883 MessageLoader::getMessage(parms));
884 #if defined(PEGASUS_DEBUG)
885 cout << MessageLoader::getMessage(parms) << endl;
886 #endif
|
887 kumpf 1.86 }
|
888 kumpf 1.198
|
889 kumpf 1.86 if (enableHttpsConnection)
890 {
|
891 kumpf 1.203 Uint32 portNumberHttps = 0;
892 String httpsPort = configManager->getCurrentValue("httpsPort");
893 if (httpsPort == String::EMPTY)
894 {
895 //
896 // Look up the WBEM-HTTPS port number
897 //
898 portNumberHttps = System::lookupPort(
899 WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
900 }
901 else
902 {
903 //
904 // user-specified
905 //
906 CString portString = httpsPort.getCString();
907 char* end = 0;
908 portNumberHttps = strtol(portString, &end, 10);
909 if (!(end != 0 && *end == '\0'))
910 {
911 throw InvalidPropertyValue("httpsPort", httpsPort);
912 kumpf 1.203 }
913 }
914
|
915 sushma.fernandes 1.189 _cimServer->addAcceptor(false, portNumberHttps, true);
|
916 kumpf 1.198
|
917 kumpf 1.203 MessageLoaderParms parms(
|
918 kumpf 1.198 "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
919 "Listening on HTTPS port $0.", portNumberHttps);
|
920 kumpf 1.203 Logger::put(
921 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
922 MessageLoader::getMessage(parms));
923 #if defined(PEGASUS_DEBUG)
924 cout << MessageLoader::getMessage(parms) << endl;
925 #endif
|
926 kumpf 1.86 }
|
927 kumpf 1.135
|
928 h.sterling 1.159 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
|
929 kumpf 1.203 {
930 _cimServer->addAcceptor(true, 0, false);
|
931 kumpf 1.86
|
932 kumpf 1.198 MessageLoaderParms parms(
|
933 kumpf 1.203 "src.Server.cimserver.LISTENING_ON_LOCAL",
934 "Listening on local connection socket.");
935 Logger::put(
936 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
937 MessageLoader::getMessage(parms));
938 # if defined(PEGASUS_DEBUG)
|
939 h.sterling 1.153 cout << MessageLoader::getMessage(parms) << endl;
|
940 kumpf 1.203 # endif
|
941 kumpf 1.86 }
|
942 david 1.85 #endif
|
943 mike 1.35
|
944 kumpf 1.198 _cimServer->bind();
|
945 kumpf 1.199
|
946 kumpf 1.198 // notify parent process (if there is a parent process) to terminate
|
947 konrad.r 1.95 // so user knows that there is cimserver ready to serve CIM requests.
|
948 kumpf 1.198 if (daemonOption)
949 {
|
950 kumpf 1.199 #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION)
951 Executor::daemonizeExecutor();
952 #else
|
953 kumpf 1.198 _cimServerProcess->notify_parent(0);
|
954 kumpf 1.199 #endif
|
955 kumpf 1.198 }
|
956 mike 1.35
|
957 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
958 kumpf 1.202 cout << "Started. " << endl;
|
959 kumpf 1.63 #endif
|
960 david.dillard 1.165
|
961 kumpf 1.54 // Put server started message to the logger
|
962 kumpf 1.143 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
963 Logger::INFORMATION,
964 "src.Server.cimserver.STARTED_VERSION",
965 "Started $0 version $1.",
|
966 kumpf 1.199 _cimServerProcess->getProductName(),
967 _cimServerProcess->getCompleteVersion());
|
968 kumpf 1.45
|
969 marek 1.190 #if defined(PEGASUS_OS_TYPE_UNIX) && !defined(PEGASUS_OS_ZOS)
|
970 kumpf 1.178 if (daemonOption && !debugOutputOption)
|
971 kumpf 1.202 {
|
972 kumpf 1.178 // Direct standard input, output, and error to /dev/null,
973 // since we are running as a daemon.
974 close(0);
975 open("/dev/null", O_RDONLY);
976 close(1);
977 open("/dev/null", O_RDWR);
978 close(2);
979 open("/dev/null", O_RDWR);
980 }
981 #endif
|
982 kumpf 1.203 }
983 catch (Exception& e)
984 {
985 MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
986 "cimserver not started: $0", e.getMessage());
987 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
988 MessageLoader::getMessage(parms));
989 cerr << MessageLoader::getMessage(parms) << endl;
|
990 kumpf 1.178
|
991 kumpf 1.203 //
992 // notify parent process (if there is a parent process) to terminate
993 //
994 if (daemonOption)
995 _cimServerProcess->notify_parent(1);
996
997 deleteCIMServer();
998 return 1;
999 }
1000
1001 // Run the main CIM Server loop
1002
1003 try
1004 {
|
1005 thilo.boehm 1.185 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1006
|
1007 kumpf 1.202 // ARM is a z/OS internal restart facility.
1008 // This is a z/OS specific change.
|
1009 thilo.boehm 1.185
1010 // Instatiating the automatic restart manager for zOS
1011 ARM_zOS automaticRestartManager;
1012
1013 // register to zOS ARM
1014 automaticRestartManager.Register();
1015
1016 #endif
1017
|
1018 mike 1.35 //
1019 // Loop to call CIMServer's runForever() method until CIMServer
1020 // has been shutdown
1021 //
|
1022 kumpf 1.202 while (!_cimServer->terminated())
1023 {
1024 _cimServer->runForever();
1025 }
|
1026 carson.hovey 1.157
|
1027 kumpf 1.45 //
1028 // normal termination
|
1029 carson.hovey 1.157 //
|
1030 kumpf 1.203
|
1031 thilo.boehm 1.185 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1032
|
1033 kumpf 1.202 // ARM is a z/OS internal restart facility.
1034 // This is a z/OS specific change.
|
1035 thilo.boehm 1.185
1036 // register to zOS ARM
1037 automaticRestartManager.DeRegister();
1038
1039 #endif
|
1040 kumpf 1.143
|
1041 kumpf 1.54 // Put server shutdown message to the logger
|
1042 kumpf 1.143 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1043 Logger::INFORMATION, "src.Server.cimserver.STOPPED",
|
1044 h.sterling 1.153 "$0 stopped.", _cimServerProcess->getProductName());
|
1045 mike 1.32 }
|
1046 kumpf 1.202 catch (Exception& e)
|
1047 marek 1.195 {
|
1048 kumpf 1.202 MessageLoaderParms parms(
|
1049 marek 1.195 "src.Server.cimserver.ERROR",
|
1050 kumpf 1.202 "Error: $0",
1051 e.getMessage());
|
1052 kumpf 1.203 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1053 MessageLoader::getMessage(parms));
1054 cerr << MessageLoader::getMessage(parms) << endl;
|
1055 marek 1.195
1056 deleteCIMServer();
1057 return 1;
1058 }
|
1059 mike 1.32
|
1060 h.sterling 1.156 deleteCIMServer();
|
1061 mike 1.32 return 0;
1062 }
|