1 mike 1.32 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 kumpf 1.58 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 mike 1.32 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 kumpf 1.58 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10 mike 1.32 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
|
13 kumpf 1.58 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
14 mike 1.32 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
16 kumpf 1.58 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19 mike 1.32 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
26 // Modified By: Mike Day (mdday@us.ibm.com)
|
27 mike 1.33 //
|
28 mike 1.32 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
29 //
|
30 mike 1.35 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
31 //
32 // Modified By: Jenny Yu (jenny_yu@hp.com)
33 //
|
34 kumpf 1.38 // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
|
35 kumpf 1.72 // Carol Ann Krug Graves, Hewlett-Packard Company
36 // (carolann_graves@hp.com)
|
37 kumpf 1.73 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
|
38 kumpf 1.38 //
|
39 mike 1.32 //%/////////////////////////////////////////////////////////////////////////////
40
|
41 mday 1.79.2.3 /*****
|
42 mike 1.32
|
43 mday 1.79.2.3 << Fri Oct 11 15:47:00 2002 mdd >>
|
44 mike 1.32
|
45 mday 1.79.2.3 changed the shutdown option in lines 247-269 to use the local AF_INET interface
46 instead of unix domain sockets
47
48 *****/
|
49 mike 1.32
|
50 mike 1.35 #include <Pegasus/Common/Config.h>
|
51 kumpf 1.59 #include <Pegasus/Common/Constants.h>
|
52 mike 1.32 #include <iostream>
|
53 mike 1.35 #include <cassert>
|
54 mike 1.32 #include <cstdlib>
|
55 kumpf 1.45 #include <fstream>
|
56 mike 1.32 #include <Pegasus/Common/FileSystem.h>
|
57 mike 1.35 #include <Pegasus/Common/Monitor.h>
|
58 mike 1.32 #include <Pegasus/Server/CIMServer.h>
59 #include <Pegasus/Common/PegasusVersion.h>
60 #include <Pegasus/Common/Logger.h>
61 #include <Pegasus/Common/System.h>
|
62 mike 1.35 #include <Pegasus/Common/Tracer.h>
63 #include <Pegasus/Config/ConfigManager.h>
64 #include <Pegasus/Client/CIMClient.h>
65 #include <Pegasus/Server/ShutdownService.h>
|
66 kumpf 1.38 #include <Pegasus/Common/Destroyer.h>
|
67 kumpf 1.74 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
|
68 mike 1.32 #include <slp/slp.h>
|
69 mike 1.35 #endif
|
70 mike 1.32
71
72 #if defined(PEGASUS_OS_TYPE_WINDOWS)
73 # include "cimserver_windows.cpp"
74 #elif defined(PEGASUS_OS_TYPE_UNIX)
|
75 chuck 1.66 # if defined(PEGASUS_OS_OS400)
76 # include "cimserver_os400.cpp"
77 # else
78 # include "cimserver_unix.cpp"
79 #endif
|
80 mike 1.32 #else
81 # error "Unsupported platform"
82 #endif
83
84 PEGASUS_USING_PEGASUS;
85 PEGASUS_USING_STD;
86
|
87 mike 1.35 //
88 // The command name.
89 //
90 static const char COMMAND_NAME [] = "cimserver";
91
92 //
93 // The constant defining usage string.
94 //
95 static const char USAGE [] = "Usage: ";
96
97 /**
98 Constants representing the command line options.
99 */
100 static const char OPTION_VERSION = 'v';
101
102 static const char OPTION_HELP = 'h';
103
104 static const char OPTION_HOME = 'D';
105
106 static const char OPTION_SHUTDOWN = 's';
107
|
108 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
109 static const char OPTION_BINDVERBOSE = 'X';
110 #endif
111
|
112 kumpf 1.54 static const String PROPERTY_TIMEOUT = "shutdownTimeout";
|
113 kumpf 1.63 static const String CIMSERVERSTART_FILE = "/etc/opt/wbem/cimserver_start.conf";
|
114 mike 1.35
|
115 mday 1.79.2.3
|
116 mike 1.35 ConfigManager* configManager;
117
|
118 mike 1.32 /** GetOptions function - This function defines the Options Table
|
119 mike 1.35 and sets up the options from that table using the config manager.
|
120 mike 1.32 */
121 void GetOptions(
|
122 mike 1.35 ConfigManager* cm,
|
123 mike 1.32 int& argc,
124 char** argv,
125 const String& pegasusHome)
126 {
|
127 mike 1.35 try
|
128 mike 1.32 {
|
129 kumpf 1.38 cm->mergeConfigFiles();
|
130 mike 1.33
|
131 mike 1.35 cm->mergeCommandLine(argc, argv);
132 }
133 catch (NoSuchFile nsf)
134 {
135 throw nsf;
136 }
137 catch (FileNotReadable fnr)
138 {
139 throw fnr;
140 }
141 catch (CannotRenameFile ftrf)
142 {
143 throw ftrf;
144 }
145 catch (ConfigFileSyntaxError cfse)
146 {
147 throw cfse;
148 }
149 catch(UnrecognizedConfigProperty ucp)
150 {
151 throw ucp;
152 mike 1.35 }
153 catch(InvalidPropertyValue ipv)
154 {
155 throw ipv;
156 }
|
157 mike 1.32 }
158
159 /* PrintHelp - This is temporary until we expand the options manager to allow
160 options help to be defined with the OptionRow entries and presented from
161 those entries.
162 */
163 void PrintHelp(const char* arg0)
164 {
|
165 mike 1.35 /**
166 Build the usage string for the config command.
167 */
168 String usage = String (USAGE);
169 usage.append (COMMAND_NAME);
170 usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
171 usage.append (" options\n");
|
172 kumpf 1.60 usage.append (" -v - displays CIM Server version number\n");
|
173 mike 1.35 usage.append (" -h - prints this help message\n");
|
174 kumpf 1.60 usage.append (" -s - shuts down CIM Server\n");
175 #ifndef PEGASUS_OS_HPUX
|
176 mike 1.35 usage.append (" -D [home] - sets pegasus home directory\n");
|
177 kumpf 1.60 #endif
178 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
179 mike 1.35 usage.append (" -install - installs pegasus as a Windows NT Service\n");
180 usage.append (" -remove - removes pegasus as a Windows NT Service\n");
|
181 kumpf 1.54 #endif
|
182 mike 1.35 usage.append (" configProperty=value\n");
|
183 kumpf 1.60 usage.append (" - sets CIM Server configuration property\n");
|
184 mike 1.35
185 cout << endl;
|
186 kumpf 1.63 #if defined(PEGASUS_OS_HPUX)
187 cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
188 #else
|
189 mike 1.32 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
|
190 kumpf 1.63 #endif
|
191 mike 1.32 cout << endl;
|
192 mike 1.35 cout << usage << endl;
193 }
194
|
195 kumpf 1.52 void shutdownCIMOM(Uint32 timeoutValue)
|
196 mike 1.35 {
197 //
198 // Create CIMClient object
199 //
|
200 kumpf 1.42 CIMClient client;
|
201 mike 1.35
202 //
|
203 kumpf 1.53 // Get local host name
|
204 mike 1.35 //
205 String hostStr = System::getHostName();
|
206 mday 1.79.2.3 hostStr.append(":");
|
207 mike 1.35
|
208 mday 1.79.2.3 if (String::equal(configManager->getCurrentValue("SSL"), "true"))
209 {
210 hostStr.append(configManager->getCurrentValue("httpsPort"));
211 }
212 else
213 {
214 hostStr.append(configManager->getCurrentValue("httpPort"));
215 }
|
216 mike 1.35 //
217 // open connection to CIMOM
218 //
219 try
220 {
|
221 mday 1.79.2.1 // use the local port only.
222 String addr("127.0.0.1:");
223 if (String::equal(configManager->getCurrentValue("SSL"), "true"))
224 {
225 addr.append(configManager->getCurrentValue("httpsPort"));
226 }
227 else
228 {
229 addr.append(configManager->getCurrentValue("httpPort"));
230 }
231
232 // use localPrivilegedOnly instead
233 client.connect(addr);
|
234 mday 1.79.2.3
235 //
236 // set client timeout to 2 seconds more than the shutdown timeout
237 // so that the command client does not timeout before the cimserver
238 // terminates
239 //
240 client.setTimeout( (timeoutValue+2)*1000 );
|
241 mday 1.79.2.1 }
242 catch(Exception &)
243 {
244 try
245 {
246 client.connectLocal();
247 }
248
249 catch(Exception& e)
250 {
251 PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
252 PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
|
253 chuck 1.66 #ifdef PEGASUS_OS_OS400
|
254 mday 1.79.2.1 // The server job may still be active but not responding.
255 // Kill the job if it exists.
256 cimserver_kill();
|
257 chuck 1.66 #endif
|
258 mday 1.79.2.1 exit(0);
259 }
|
260 mike 1.35 }
261
262 try
263 {
264 //
|
265 kumpf 1.52 // construct CIMObjectPath
|
266 mike 1.35 //
|
267 mday 1.79.2.3 String referenceStr = "//";
|
268 mike 1.35 referenceStr.append(hostStr);
|
269 chuck 1.70 referenceStr.append("/");
|
270 kumpf 1.72 referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
|
271 kumpf 1.53 referenceStr.append(":");
|
272 kumpf 1.72 referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
|
273 kumpf 1.50 CIMObjectPath reference(referenceStr);
|
274 mike 1.35
275 //
276 // issue the invokeMethod request on the shutdown method
277 //
278 Array<CIMParamValue> inParams;
279 Array<CIMParamValue> outParams;
280
|
281 kumpf 1.52 // set force option to true for now
|
282 kumpf 1.40 inParams.append(CIMParamValue("force",
|
283 kumpf 1.52 CIMValue(Boolean(true))));
|
284 mike 1.35
|
285 kumpf 1.40 inParams.append(CIMParamValue("timeout",
|
286 kumpf 1.39 CIMValue(Uint32(timeoutValue))));
|
287 mike 1.35
288 CIMValue retValue = client.invokeMethod(
|
289 kumpf 1.59 PEGASUS_NAMESPACENAME_SHUTDOWN,
|
290 mike 1.35 reference,
291 "shutdown",
292 inParams,
293 outParams);
|
294 kumpf 1.43 }
|
295 kumpf 1.65 catch(CIMException& e)
|
296 kumpf 1.46 {
297 PEGASUS_STD(cerr) << "Failed to shutdown server: ";
|
298 kumpf 1.63 if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
299 {
300 PEGASUS_STD(cerr) << "The repository may be empty.";
301 PEGASUS_STD(cerr) << PEGASUS_STD(endl);
302 }
303 else
304 {
305 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
306 }
|
307 chuck 1.66 #ifdef PEGASUS_OS_OS400
308 // Kill the server job.
309 cimserver_kill();
310 #endif
|
311 kumpf 1.46 exit(1);
312 }
|
313 kumpf 1.65 catch(Exception& e)
|
314 kumpf 1.45 {
|
315 mday 1.79.2.3
|
316 kumpf 1.45 //
|
317 kumpf 1.54 // This may mean the CIM Server has been terminated and returns a
318 // "Empty HTTP response message" HTTP error response. To be sure
319 // CIM Server gets shutdown, if CIM Server is still running at
320 // this time, we will kill the cimserver process.
|
321 kumpf 1.45 //
|
322 kumpf 1.56 // give CIM Server some time to finish up
323 //
|
324 mday 1.79.2.3 System::sleep(1);
325 cimserver_kill();
|
326 kumpf 1.63
327 //
328 // Check to see if CIMServer is still running. If CIMServer
329 // is still running and the shutdown timeout has not expired,
330 // loop and wait one second until either CIM Server is
331 // terminated or until timeout expires. If timeout expires
332 // and CIMServer is still running, kill the CIMServer
333 // process.
334 //
335 Uint32 maxWaitTime = timeoutValue - 2;
336 Boolean running = isCIMServerRunning();
337 while ( running && maxWaitTime > 0 )
338 {
339 System::sleep(1);
340 running = isCIMServerRunning();
341 maxWaitTime = maxWaitTime - 1;
342 }
343
344 if (running)
345 {
346 cimserver_kill();
347 kumpf 1.63 }
|
348 kumpf 1.43 }
|
349 mike 1.35 return;
|
350 mike 1.32 }
351
|
352 mike 1.35
|
353 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
354 mike 1.32 // MAIN
355 //////////////////////////////////////////////////////////////////////////
356 int main(int argc, char** argv)
357 {
|
358 mike 1.35 String pegasusHome = String::EMPTY;
359 Boolean pegasusIOLog = false;
|
360 kumpf 1.53 String httpPort = String::EMPTY;
361 String httpsPort = String::EMPTY;
|
362 mike 1.35 String logsDirectory = String::EMPTY;
363 Boolean useSLP = false;
364 Boolean useSSL = false;
365 Boolean daemonOption = false;
366 Boolean shutdownOption = false;
|
367 kumpf 1.60 Uint32 timeoutValue = 0;
|
368 mday 1.47
|
369 chuck 1.66 #ifdef PEGASUS_OS_OS400
370 // Initialize Pegasus home to the shipped OS/400 directory.
371 pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
372 #endif
373
|
374 kumpf 1.38 //
375 // Get environment variables:
376 //
377 const char* tmp = getenv("PEGASUS_HOME");
378
379 if (tmp)
380 {
381 pegasusHome = tmp;
382 }
383
384 FileSystem::translateSlashes(pegasusHome);
385
|
386 mike 1.32 // on Windows NT if there are no command-line options, run as a service
387
388 if (argc == 1 )
|
389 mike 1.35 {
390 cim_server_service(argc, argv);
391 }
392 else
393 {
|
394 kumpf 1.60 // Get help, version, and shutdown options
|
395 mike 1.35
396 for (int i = 1; i < argc; )
397 {
398 const char* arg = argv[i];
399
400 // Check for -option
401 if (*arg == '-')
402 {
403 // Get the option
404 const char* option = arg + 1;
405
406 //
407 // Check to see if user asked for the version (-v option):
408 //
409 if (*option == OPTION_VERSION)
410 {
|
411 kumpf 1.63 #if defined(PEGASUS_OS_HPUX)
412 cout << PLATFORM_PRODUCT_VERSION << endl;
413 #else
|
414 mike 1.35 cout << PEGASUS_VERSION << endl;
|
415 kumpf 1.63 #endif
|
416 mike 1.35 exit(0);
417 }
418 //
419 // Check to see if user asked for help (-h option):
420 //
421 else if (*option == OPTION_HELP)
422 {
423 PrintHelp(argv[0]);
424 exit(0);
425 }
|
426 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
|
427 mike 1.35 else if (*option == OPTION_HOME)
428 {
|
429 kumpf 1.60 if (i + 1 < argc)
|
430 mike 1.35 {
431 pegasusHome.assign(argv[i + 1]);
432 }
433 else
434 {
435 cout << "Missing argument for option -" << option << endl;
436 exit(0);
437 }
438
439 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
440 argc -= 2;
441 }
|
442 kumpf 1.63 #endif
|
443 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
444 //
|
445 kumpf 1.49 // Check to see if user asked for the version (-X option):
|
446 kumpf 1.48 //
447 if (*option == OPTION_BINDVERBOSE)
448 {
449 System::bindVerbose = true;
450 cout << "Unsupported debug option, BIND_VERBOSE, enabled."
451 << endl;
452 // remove the option from the command line
453 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
454 argc--;
455 }
456 #endif
|
457 mike 1.35 //
458 // Check to see if user asked for shutdown (-s option):
459 //
460 else if (*option == OPTION_SHUTDOWN)
461 {
462 //
|
463 kumpf 1.52 // check to see if user is root
|
464 mike 1.35 //
|
465 chuck 1.70 #ifndef PEGASUS_OS_OS400
|
466 kumpf 1.55 if (!System::isPrivilegedUser(System::getEffectiveUserName()))
|
467 mike 1.35 {
|
468 kumpf 1.52 cout << "You must have superuser privilege to run ";
469 cout << "cimserver." << endl;
|
470 mike 1.35 exit(0);
471 }
|
472 chuck 1.70 #endif
|
473 mike 1.35
474 //
|
475 kumpf 1.52 // Check to see if shutdown has already been specified:
|
476 mike 1.35 //
|
477 kumpf 1.52 if (shutdownOption)
|
478 mike 1.35 {
|
479 kumpf 1.52 cout << "Duplicate shutdown option specified." << endl;
|
480 mike 1.35 exit(0);
481 }
482
|
483 kumpf 1.52 shutdownOption = true;
|
484 mike 1.35
485 // remove the option from the command line
486 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
487 argc--;
488 }
489 else
490 i++;
491 }
492 else
493 i++;
|
494 mike 1.32 }
495 }
|
496 mike 1.35
|
497 kumpf 1.38 //
498 // Set the value for pegasusHome property
499 //
500 ConfigManager::setPegasusHome(pegasusHome);
|
501 mike 1.32
|
502 mike 1.35 //
503 // Get an instance of the Config Manager.
504 //
505 configManager = ConfigManager::getInstance();
506
507 //
|
508 mike 1.32 // Get options (from command line and from configuration file); this
|
509 mike 1.35 // removes corresponding options and their arguments from the command
|
510 mike 1.32 // line.
|
511 mike 1.35 //
|
512 mike 1.32 try
513 {
|
514 mike 1.35 GetOptions(configManager, argc, argv, pegasusHome);
|
515 mike 1.32 }
516 catch (Exception& e)
517 {
|
518 mike 1.35 cerr << argv[0] << ": " << e.getMessage() << endl;
519 exit(1);
|
520 mike 1.32 }
521
|
522 mike 1.35 try
|
523 mike 1.32 {
|
524 mike 1.35 //
525 // Check to see if we should (can) install as a NT service
526 //
527
528 if (String::equal(configManager->getCurrentValue("install"), "true"))
529 {
530 if( 0 != cimserver_install_nt_service( pegasusHome ))
531 {
532 cout << "\nPegasus installed as NT Service";
533 exit(0);
534 }
535 }
|
536 mike 1.32
|
537 mike 1.35 //
538 // Check to see if we should (can) remove Pegasus as an NT service
539 //
540
541 if (String::equal(configManager->getCurrentValue("remove"), "true"))
542 {
543 if( 0 != cimserver_remove_nt_service() )
544 {
545 cout << "\nPegasus removed as NT Service";
546 exit(0);
547 }
548 }
|
549 mike 1.32
|
550 mike 1.35 //
551 // Check to see if we should Pegasus as a daemon
552 //
553
554 if (String::equal(configManager->getCurrentValue("daemon"), "true"))
555 {
556 daemonOption = true;
557 }
|
558 mday 1.62
|
559 mike 1.35 //
|
560 kumpf 1.36 // Check the log trace options and set global variable
561 //
562
563 if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
564 {
565 pegasusIOLog = true;
566 }
567
568 // Get the log file directory definition.
569 // We put String into Cstring because
570 // Directory functions only handle Cstring.
571 // ATTN-KS: create String based directory functions.
572
573 logsDirectory = configManager->getCurrentValue("logdir");
|
574 kumpf 1.38 logsDirectory =
575 ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
|
576 kumpf 1.36
577 // Set up the Logger. This does not open the logs
578 // Might be more logical to clean before set.
579 // ATTN: Need tool to completely disable logging.
580
|
581 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
|
582 kumpf 1.36 Logger::setHomeDirectory(logsDirectory);
|
583 kumpf 1.57 #endif
|
584 kumpf 1.36
585 //
|
586 mike 1.35 // Check to see if we need to shutdown CIMOM
587 //
588 if (shutdownOption)
589 {
|
590 kumpf 1.60 String configTimeout =
591 configManager->getCurrentValue("shutdownTimeout");
|
592 kumpf 1.69 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
|
593 kumpf 1.60
|
594 kumpf 1.52 shutdownCIMOM(timeoutValue);
|
595 kumpf 1.45
|
596 kumpf 1.60 cout << "CIM Server stopped." << endl;
|
597 mike 1.35 exit(0);
598 }
|
599 mike 1.32
|
600 mike 1.35 //
|
601 kumpf 1.53 // Get the port numbers
|
602 mike 1.35 //
603
|
604 kumpf 1.53 httpPort = configManager->getCurrentValue("httpPort");
605
606 httpsPort = configManager->getCurrentValue("httpsPort");
|
607 mike 1.35
|
608 kumpf 1.36 // Leave this in until people get familiar with the logs.
|
609 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
|
610 kumpf 1.36 cout << "Logs Directory = " << logsDirectory << endl;
|
611 kumpf 1.57 #endif
|
612 mike 1.35
613 if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
614 {
615 Logger::clean(logsDirectory);;
616 }
|
617 mike 1.32
|
618 mike 1.35 if (String::equal(configManager->getCurrentValue("slp"), "true"))
619 {
620 useSLP = true;
621 }
|
622 mike 1.32
|
623 kumpf 1.78 #if defined(PEGASUS_USE_RELEASE_CONFIG_OPTIONS)
624 Boolean enableHttpConnection = String::equal(
625 configManager->getCurrentValue("enableHttpConnection"), "true");
626 Boolean enableHttpsConnection = String::equal(
627 configManager->getCurrentValue("enableHttpsConnection"), "true");
628
629 if (enableHttpConnection && enableHttpsConnection)
630 {
631 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
632 "Enabling both HTTP and HTTPS connections is unsupported. "
633 "Only the HTTPS connection is enabled.");
634 cerr << "Enabling both HTTP and HTTPS connections is unsupported. "
635 "Only the HTTPS connection is enabled." << endl;
636 }
637 else if (!enableHttpConnection && !enableHttpsConnection)
638 {
639 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
640 "Neither HTTP nor HTTPS connection is enabled. "
641 "CIMServer will not be started.");
642 cerr << "Neither HTTP nor HTTPS connection is enabled. "
643 "CIMServer will not be started." << endl;
644 kumpf 1.78 exit(1);
645 }
646
647 useSSL = enableHttpsConnection;
648
649 #else
|
650 mike 1.35 if (String::equal(configManager->getCurrentValue("SSL"), "true"))
651 {
652 useSSL = true;
653 }
|
654 kumpf 1.78 #endif
|
655 mike 1.32 }
|
656 mike 1.35 catch (UnrecognizedConfigProperty e)
|
657 mike 1.32 {
|
658 mike 1.35 cout << "Error: " << e.getMessage() << endl;
|
659 mike 1.32 }
660
|
661 kumpf 1.53 Uint32 portNumber;
662
663 char address[32];
664
665 if (useSSL)
666 {
667 char* end = 0;
|
668 kumpf 1.69 CString portString = httpsPort.getCString();
669 Uint32 port = strtol(portString, &end, 10);
|
670 kumpf 1.53 assert(end != 0 && *end == '\0');
671
672 //
673 // Look up the WBEM-HTTPS port number
674 //
675 portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
676 sprintf(address, "%u", portNumber);
677 }
678 else
679 {
680 char* end = 0;
|
681 kumpf 1.69 CString portString = httpPort.getCString();
682 Uint32 port = strtol(portString, &end, 10);
|
683 kumpf 1.53 assert(end != 0 && *end == '\0');
684
685 //
686 // Look up the WBEM-HTTP port number
687 //
688 portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
689 sprintf(address, "%u", portNumber);
690 }
|
691 mike 1.32
692 // Put out startup up message.
|
693 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
|
694 mike 1.32 cout << PEGASUS_NAME << PEGASUS_VERSION <<
695 " on port " << address << endl;
696 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
|
697 kumpf 1.54 cout <<"Starting..."
|
698 mike 1.32 << (pegasusIOLog ? " Tracing to Log ": " ")
699 << (useSLP ? " SLP reg. " : " No SLP ")
|
700 mike 1.35 << (useSSL ? " Use SSL " : " No SSL ")
|
701 mike 1.32 << endl;
|
702 kumpf 1.63 #endif
|
703 mike 1.32
|
704 kumpf 1.63 // do we need to run as a daemon ?
705 if (daemonOption)
706 {
707 if(-1 == cimserver_fork())
708 exit(-1);
709 }
|
710 chuck 1.66
711 #ifdef PEGASUS_OS_OS400
712 // Special server initialization code for OS/400.
713 if (cimserver_initialize() != 0)
714 {
715 // do some logging here!
716 exit(-1);
717 }
718 #endif
|
719 mday 1.62
|
720 kumpf 1.63 #ifdef PEGASUS_OS_HPUX
721 umask(S_IWGRP|S_IWOTH);
|
722 kumpf 1.79
723 //
724 // check if CIMServer is already running
725 // if CIMServer is already running, print message and
726 // notify parent process (if there is a parent process) to terminate
727 //
728 if(isCIMServerRunning())
729 {
730 cout << "Unable to start CIMServer." << endl;
731 cout << "CIMServer is already running." << endl;
732
733 //
734 // notify parent process (if there is a parent process) to terminate
735 //
736 if (daemonOption)
737 notify_parent();
738
739 exit(1);
740 }
741
|
742 kumpf 1.63 #endif
|
743 kumpf 1.51
|
744 mike 1.32 // try loop to bind the address, and run the server
745 try
746 {
|
747 kumpf 1.75 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
|
748 mike 1.32 slp_client *discovery = new slp_client() ;;
749 String serviceURL;
750 serviceURL.assign("service:cim.pegasus://");
751 String host_name = slp_get_host_name();
|
752 kumpf 1.67 serviceURL.append(host_name);
753 serviceURL.append(":");
754 serviceURL.append(address);
|
755 mike 1.35 #endif
|
756 mike 1.32
|
757 mday 1.61 Monitor monitor(true);
|
758 kumpf 1.38 CIMServer server(&monitor, useSSL);
|
759 kumpf 1.41
760 // bind throws an exception if the bind fails
761 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
762 cout << "Binding to domain socket" << endl;
|
763 kumpf 1.63 #elif !defined(PEGASUS_OS_HPUX)
|
764 mike 1.33 cout << "Binding to " << address << endl;
|
765 kumpf 1.41 #endif
|
766 mike 1.35
767 server.bind(portNumber);
|
768 kumpf 1.73
|
769 dan 1.76 // notify parent process (if there is a parent process) to terminate
770 // so user knows that cimserver is ready to serve CIM requests.
771 if (daemonOption)
772 notify_parent();
|
773 mike 1.32
774 time_t last = 0;
|
775 mike 1.35
|
776 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
777 //
|
778 kumpf 1.56 // create a file to indicate that the cimserver has started and
779 // save the process id of the cimserver process in the file
|
780 kumpf 1.45 //
|
781 kumpf 1.56
782 // remove the old file if it exists
783 System::removeFile(fname);
784
785 // open the file
786 FILE *pid_file = fopen(fname, "w");
787 if (pid_file)
|
788 kumpf 1.45 {
|
789 kumpf 1.56 // save the pid in the file
790 fprintf(pid_file, "%ld\n", (long)server_pid);
791 fclose(pid_file);
|
792 kumpf 1.45 }
793 #endif
|
794 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
|
795 kumpf 1.54 cout << "Started. " << endl;
|
796 kumpf 1.63 #endif
|
797 kumpf 1.54
798 // Put server started message to the logger
|
799 kumpf 1.63 #ifdef PEGASUS_OS_HPUX
800 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
801 "Started $0 version $1 on port $2.",
802 PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION, address);
803 #else
|
804 kumpf 1.54 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
805 kumpf 1.57 "Started $0 version $1 on port $2.",
806 PEGASUS_NAME, PEGASUS_VERSION, address);
|
807 kumpf 1.63 #endif
|
808 kumpf 1.45
|
809 mday 1.62
|
810 mike 1.35 //
811 // Loop to call CIMServer's runForever() method until CIMServer
812 // has been shutdown
813 //
|
814 mday 1.79.2.3 while( false == server.terminated() )
|
815 mike 1.32 {
|
816 kumpf 1.75 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
|
817 mike 1.32 if(useSLP )
818 {
819 if( (time(NULL) - last ) > 60 )
820 {
|
821 kumpf 1.69 if( discovery != NULL && serviceURL.size() )
822 discovery->srv_reg_all(serviceURL.getCString(),
|
823 mike 1.35 "(namespace=root/cimv2)",
|
824 mike 1.32 "service:cim.pegasus",
825 "DEFAULT",
826 70) ;
827 time(&last);
828 }
829
830 discovery->service_listener();
831 }
|
832 mike 1.35 #endif
|
833 mike 1.32 server.runForever();
834 }
835
|
836 kumpf 1.45 //
837 // normal termination
|
838 mike 1.34 //
|
839 kumpf 1.54 // Put server shutdown message to the logger
840 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
841 "$0 stopped.", PEGASUS_NAME);
|
842 kumpf 1.45
843 #if defined(PEGASUS_OS_HPUX)
844 //
|
845 kumpf 1.56 // close the file created at startup time to indicate that the
846 // cimserver has terminated normally.
|
847 kumpf 1.45 //
848 FileSystem::removeFile(CIMSERVERSTART_FILE);
849 #endif
|
850 mike 1.32 }
851 catch(Exception& e)
852 {
853 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
854 kumpf 1.77
855 //
856 // notify parent process (if there is a parent process) to terminate
857 //
858 if (daemonOption)
859 notify_parent();
860
|
861 kumpf 1.54 return 1;
|
862 mike 1.32 }
|
863 mday 1.79.2.1 #if defined(PEGASUS_OS_TYPE_UNIX)
864 kill(getpid(), SIGKILL);
865 #endif
866 #if defined(PEGASUS_OS_TYPE_WINDOWS)
867 ExitProcess(0);
868 #endif
869 _exit(1);
|
870 mike 1.32 return 0;
871 }
|