1 mike 1.32 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.32 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By: Mike Day (mdday@us.ibm.com)
|
26 mike 1.33 //
|
27 mike 1.32 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
28 //
|
29 kumpf 1.34.2.1 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
30 //
|
31 kumpf 1.34.2.10 // Modified By: Jenny Yu (jenny_yu@hp.com)
32 //
|
33 mike 1.32 //%/////////////////////////////////////////////////////////////////////////////
34
35
36 //////////////////////////////////////////////////////////////////////
37 //
38 // Notes on deamon operation (Unix) and service operation (Win 32):
39 //
40 // To run pegasus as a daemon on Unix platforms, use the -d option:
41 //
42 // cimserver -d
43 //
44 // The -d option has no effect on windows operation.
45 //
|
46 kumpf 1.34.2.10 // To shutdown pegasus, use the -s option:
47 //
48 // cimserver -s [-f] [-T timeout_value]
49 //
|
50 mike 1.32 // To run pegasus as an NT service, there are FOUR different possibilities:
51 //
52 // To INSTALL the Pegasus service,
53 //
54 // cimserver -install
55 //
56 // To REMOVE the Pegasus service,
57 //
58 // cimserver -remove
59 //
60 // To START the Pegasus service,
61 //
62 // net start cimserver
63 //
64 // To STOP the Pegasus service,
65 //
66 // net stop cimserver
67 //
68 // Alternatively, you can use the windows service manager. Pegasus shows up
69 // in the service database as "Pegasus CIM Object Manager"
70 //
71 mike 1.32 // Mike Day, mdday@us.ibm.com
72 //
73 //////////////////////////////////////////////////////////////////////
74
75
76 #include <iostream>
|
77 sage 1.34.2.9 #include <cassert>
|
78 mike 1.32 #include <cstdlib>
79 #include <Pegasus/Common/FileSystem.h>
|
80 mike 1.34.2.5 #include <Pegasus/Common/Monitor.h>
|
81 mike 1.32 #include <Pegasus/Server/CIMServer.h>
82 #include <Pegasus/Common/PegasusVersion.h>
83 #include <Pegasus/Protocol/Handler.h>
84 #include <Pegasus/Common/Logger.h>
85 #include <Pegasus/Common/System.h>
|
86 kumpf 1.34.2.1 #include <Pegasus/Common/Tracer.h>
87 #include <Pegasus/Config/ConfigManager.h>
|
88 kumpf 1.34.2.10 #include <Pegasus/Client/CIMClient.h>
89 #include <Pegasus/Common/HTTPConnector.h>
90 #include <Pegasus/Server/ShutdownService.h>
|
91 sage 1.34.2.9 #ifndef PEGASUS_OS_ZOS
|
92 mike 1.32 #include <slp/slp.h>
|
93 sage 1.34.2.9 #endif
|
94 mike 1.32
95
96 #if defined(PEGASUS_OS_TYPE_WINDOWS)
97 # include "cimserver_windows.cpp"
98 #elif defined(PEGASUS_OS_TYPE_UNIX)
99 # include "cimserver_unix.cpp"
100 #else
101 # error "Unsupported platform"
102 #endif
103
104 PEGASUS_USING_PEGASUS;
105 PEGASUS_USING_STD;
106
|
107 kumpf 1.34.2.4 //
108 // The command name.
109 //
|
110 kumpf 1.34.2.1 static const char COMMAND_NAME [] = "cimserver";
111
|
112 kumpf 1.34.2.4 //
113 // The constant defining usage string.
114 //
115 static const char USAGE [] = "Usage: ";
116
|
117 kumpf 1.34.2.1 /**
|
118 kumpf 1.34.2.4 Constants representing the command line options.
|
119 kumpf 1.34.2.1 */
|
120 kumpf 1.34.2.4 static const char OPTION_VERSION = 'v';
121
122 static const char OPTION_HELP = 'h';
123
124 static const char OPTION_HOME = 'D';
125
|
126 kumpf 1.34.2.10 static const char OPTION_SHUTDOWN = 's';
127
128 static const char OPTION_FORCE = 'f';
129
130 static const char OPTION_TIMEOUT = 'T';
131
132 static const String NAMESPACE = "root/cimv2";
133 static const String CLASSNAME_SHUTDOWNSERVICE = "PG_ShutdownService";
134 static const String PROPERTY_TIMEOUT = "timeout";
|
135 kumpf 1.34.2.1
|
136 kumpf 1.34.2.10 ConfigManager* configManager;
|
137 kumpf 1.34.2.1
|
138 mike 1.32 void GetEnvironmentVariables(
139 const char* arg0,
140 String& pegasusHome)
141 {
142 // Get environment variables:
143
144 const char* tmp = getenv("PEGASUS_HOME");
145
146 if (!tmp)
147 {
148 cerr << arg0 << ": PEGASUS_HOME environment variable undefined" << endl;
149 exit(1);
150 }
151
152 pegasusHome = tmp;
153 FileSystem::translateSlashes(pegasusHome);
154 }
155
|
156 sage 1.34.2.6 void SetEnvironmentVariables(
157 const char* arg0)
158 {
159 cout << "PEGASUS_HOME is now " << arg0 << endl;
|
160 mike 1.34.2.7
161 String str = "PEGASUS_HOME=";
162 str += arg0;
163 char* tmp = str.allocateCString();
164 putenv(tmp);
165
|
166 mike 1.34.2.8 // Note: don't delete tmp! putenv() uses it.
|
167 sage 1.34.2.6 }
168
|
169 mike 1.32 /** GetOptions function - This function defines the Options Table
|
170 kumpf 1.34.2.1 and sets up the options from that table using the config manager.
|
171 mike 1.32 */
172 void GetOptions(
|
173 kumpf 1.34.2.1 ConfigManager* cm,
|
174 mike 1.32 int& argc,
175 char** argv,
176 const String& pegasusHome)
177 {
|
178 kumpf 1.34.2.1 String currentFile = pegasusHome + "/" + CURRENT_CONFIG_FILE;
179 String plannedFile = pegasusHome + "/" + PLANNED_CONFIG_FILE;
180
181 try
|
182 mike 1.32 {
|
183 kumpf 1.34.2.1 cm->mergeConfigFiles(currentFile, plannedFile);
|
184 mike 1.32
|
185 kumpf 1.34.2.1 cm->mergeCommandLine(argc, argv);
186 }
187 catch (NoSuchFile nsf)
188 {
189 throw nsf;
190 }
191 catch (FileNotReadable fnr)
192 {
193 throw fnr;
194 }
195 catch (CannotRenameFile ftrf)
196 {
197 throw ftrf;
198 }
199 catch (ConfigFileSyntaxError cfse)
200 {
201 throw cfse;
202 }
|
203 kumpf 1.34.2.4 catch(UnrecognizedConfigProperty ucp)
204 {
205 throw ucp;
206 }
207 catch(InvalidPropertyValue ipv)
208 {
209 throw ipv;
210 }
|
211 mike 1.32 }
212
213 /* PrintHelp - This is temporary until we expand the options manager to allow
214 options help to be defined with the OptionRow entries and presented from
215 those entries.
216 */
217 void PrintHelp(const char* arg0)
218 {
|
219 kumpf 1.34.2.1 /**
220 Build the usage string for the config command.
221 */
222 String usage = String (USAGE);
223 usage.append (COMMAND_NAME);
224 usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
225 usage.append (" options\n");
|
226 kumpf 1.34.2.4 usage.append (" -v - displays pegasus version number\n");
227 usage.append (" -h - prints this help message\n");
|
228 sage 1.34.2.6 usage.append (" -D [home] - sets pegasus home directory\n");
|
229 kumpf 1.34.2.4 usage.append (" -t - turns tracing on\n");
230 usage.append (" -t - turns on trace of client IO to console\n");
231 usage.append (" -l - turns on trace of client IO to trace file\n");
232 usage.append (" -d - runs pegasus as a daemon\n");
|
233 kumpf 1.34.2.10 usage.append (" -s [-f] [-T timeout] \n");
234 usage.append (" - shuts down pegasus\n");
|
235 kumpf 1.34.2.4 usage.append (" -cleanlogs - clears the log files at startup\n");
236 usage.append (" -install - installs pegasus as a Windows NT Service\n");
237 usage.append (" -remove - removes pegasus as a Windows NT Service\n");
238 usage.append (" -slp - registers pegasus as a service with SLP\n\n");
239
240 usage.append (" configProperty=value\n");
241 usage.append (" port=nnnn - sets port number to listen on\n");
242 usage.append (" home=/pegasus/bin - sets pegasus home directory\n");
243 usage.append (" logdir=/pegasus/logs - directory for log files\n");
|
244 kumpf 1.34.2.1
245 cout << endl;
|
246 mike 1.32 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
247 cout << endl;
|
248 kumpf 1.34.2.1 cout << usage << endl;
|
249 mike 1.32 }
250
|
251 kumpf 1.34.2.10 void shutdownCIMOM(Boolean forceOption, String timeoutStr)
252 {
253 //
254 // Create CIMClient object
255 //
256 Monitor* monitor = new Monitor;
257 HTTPConnector* httpConnector = new HTTPConnector(monitor);
258 CIMClient client(monitor, httpConnector);
259
260 //
261 // Get the port number
262 //
263 String portNumberStr = configManager->getCurrentValue("port");
264
265 String hostStr = System::getHostName();
266 hostStr.append(":");
267 hostStr.append(portNumberStr);
268
269 //
270 // open connection to CIMOM
271 //
272 kumpf 1.34.2.10 try
273 {
274 client.connect(hostStr.allocateCString());
275 }
276 catch(Exception& e)
277 {
278 PEGASUS_STD(cerr) << "Failed to connect to server: " << e.getMessage() << PEGASUS_STD(endl);
279 exit(1);
280 }
281
282 try
283 {
284 //
285 // construct CIMReference
286 //
287 String referenceStr = "//";
288 referenceStr.append(hostStr);
289 referenceStr.append("/root/cimv2:PG_ShutdownService");
290 CIMReference reference(referenceStr);
291
292 //
293 kumpf 1.34.2.10 // issue the invokeMethod request on the shutdown method
294 //
295 Array<CIMParamValue> inParams;
296 Array<CIMParamValue> outParams;
297
298 if (forceOption)
299 {
300 inParams.append(CIMParamValue(
301 CIMParameter("force", CIMType::STRING),
302 CIMValue("TRUE")));
303 }
304 else
305 {
306 inParams.append(CIMParamValue(
307 CIMParameter("force", CIMType::STRING),
308 CIMValue("FALSE")));
309 }
310
311 inParams.append(CIMParamValue(
312 CIMParameter("timeout", CIMType::STRING),
313 CIMValue(timeoutStr)));
314 kumpf 1.34.2.10
315 CIMValue retValue = client.invokeMethod(
316 NAMESPACE,
317 reference,
318 "shutdown",
319 inParams,
320 outParams);
321 }
322 catch(Exception& e)
323 {
324 PEGASUS_STD(cerr) << "Failed to shutdown server: " << e.getMessage() << PEGASUS_STD(endl);
325 exit(1);
326 }
327
328 return;
329 }
330
331
|
332 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
333 mike 1.32 // MAIN
334 //////////////////////////////////////////////////////////////////////////
335 int main(int argc, char** argv)
336 {
|
337 kumpf 1.34.2.1 String pegasusHome = String::EMPTY;
338 Boolean pegasusIOTrace = false;
339 Boolean pegasusIOLog = false;
340 String portOption = String::EMPTY;
341 String logsDirectory = String::EMPTY;
342 Boolean useSLP = false;
343 Boolean daemonOption = false;
|
344 kumpf 1.34.2.10 Boolean shutdownOption = false;
345 Boolean forceOption = false;
346 Boolean timeoutOption = false;
347 String timeoutStr = String::EMPTY;
348 long timeoutValue = 0;
|
349 kumpf 1.34.2.1
|
350 mike 1.32 // on Windows NT if there are no command-line options, run as a service
351
352 if (argc == 1 )
|
353 kumpf 1.34.2.4 {
|
354 kumpf 1.34.2.10 cim_server_service(argc, argv);
355 }
356 else
357 {
358 // Get help, version and home options
|
359 kumpf 1.34.2.4
|
360 kumpf 1.34.2.10 for (int i = 1; i < argc; )
|
361 kumpf 1.34.2.4 {
|
362 kumpf 1.34.2.10 const char* arg = argv[i];
|
363 kumpf 1.34.2.4
|
364 kumpf 1.34.2.10 // Check for -option
365 if (*arg == '-')
|
366 kumpf 1.34.2.4 {
|
367 kumpf 1.34.2.10 // Get the option
368 const char* option = arg + 1;
369
370 //
371 // Check to see if user asked for the version (-v option):
372 //
373 if (*option == OPTION_VERSION)
|
374 kumpf 1.34.2.4 {
|
375 kumpf 1.34.2.10 cout << PEGASUS_VERSION << endl;
376 exit(0);
|
377 kumpf 1.34.2.4 }
|
378 kumpf 1.34.2.10 //
379 // Check to see if user asked for help (-h option):
380 //
381 else if (*option == OPTION_HELP)
|
382 kumpf 1.34.2.4 {
|
383 kumpf 1.34.2.10 PrintHelp(argv[0]);
|
384 kumpf 1.34.2.4 exit(0);
385 }
|
386 kumpf 1.34.2.10 else if (*option == OPTION_HOME)
387 {
388 if (i + 1 < argc)
389 {
390 pegasusHome.assign(argv[i + 1]);
391 SetEnvironmentVariables(argv[i + 1]);
392 }
393 else
394 {
395 cout << "Missing argument for option -" << option << endl;
396 exit(0);
397 }
|
398 kumpf 1.34.2.4
|
399 kumpf 1.34.2.10 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
400 argc -= 2;
401 }
402 //
403 // Check to see if user asked for shutdown (-s option):
404 //
405 else if (*option == OPTION_SHUTDOWN)
406 {
407 //
408 // Check to see if shutdown has already been specified:
409 //
410 if (shutdownOption)
411 {
412 cout << "Duplicate shutdown option specified." << endl;
413 exit(0);
414 }
415 shutdownOption = true;
416
417 // remove the option from the command line
418 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
419 argc--;
420 kumpf 1.34.2.10 }
421 else if (*option == OPTION_FORCE)
422 {
423 //
424 // Check to see if shutdown has been specified:
425 //
426 if (!shutdownOption)
427 {
428 cout << "Invalid option -" << option << endl;
429 exit(0);
430 }
431
432 //
433 // Check to see if force has already been specified:
434 //
435 if (forceOption)
436 {
437 cout << "Duplicate force option specified." << endl;
438 exit(0);
439 }
440
441 kumpf 1.34.2.10 forceOption = true;
442
443 // remove the option from the command line
444 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
445 argc--;
446 }
447 else if (*option == OPTION_TIMEOUT)
448 {
449 //
450 // Check to see if shutdown has been specified:
451 //
452 if (!shutdownOption)
453 {
454 cout << "Invalid option -" << option << endl;
455 exit(0);
456 }
457
458 if (timeoutOption)
459 {
460 cout << "Duplicate timeout option specified." << endl;
461 exit(0);
462 kumpf 1.34.2.10 }
463
464 timeoutOption = true;
465
466 if (i + 1 < argc)
467 {
468 // get timeout value
469 timeoutStr.assign(argv[i + 1]);
470
471 // validate timeout value string
472 char* tmp = timeoutStr.allocateCString();
473 char* end = 0;
474 timeoutValue = strtol(tmp, &end, 10);
475
476 if (!end || *end != '\0')
477 {
478 cout << "invalid timeout value specified: ";
479 cout << timeoutStr << endl;
480 delete [] tmp;
481 exit(0);
482 }
483 kumpf 1.34.2.10 }
484 else
485 {
486 cout << "Missing argument for option -";
487 cout << option << endl;
488 exit(0);
489 }
490
491 // remove the option from the command line
492 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
493 argc -= 2;
494 }
495 else
496 i++;
|
497 kumpf 1.34.2.4 }
|
498 kumpf 1.34.2.10 else
499 i++;
|
500 mike 1.32 }
501 }
|
502 kumpf 1.34.2.4
|
503 mike 1.32 if (pegasusHome.size() == 0)
504 GetEnvironmentVariables(argv[0], pegasusHome);
505
|
506 kumpf 1.34.2.1 //
507 // Get an instance of the Config Manager.
508 //
|
509 kumpf 1.34.2.10 configManager = ConfigManager::getInstance();
|
510 mike 1.32
|
511 kumpf 1.34.2.1 //
512 // Get options (from command line and from configuration file); this
|
513 kumpf 1.34.2.4 // removes corresponding options and their arguments from the command
|
514 kumpf 1.34.2.1 // line.
515 //
|
516 mike 1.32 try
517 {
|
518 kumpf 1.34.2.1 GetOptions(configManager, argc, argv, pegasusHome);
|
519 mike 1.32 }
520 catch (Exception& e)
521 {
|
522 kumpf 1.34.2.1 cerr << argv[0] << ": " << e.getMessage() << endl;
523 exit(1);
|
524 mike 1.32 }
525
526
|
527 kumpf 1.34.2.1 try
528 {
529 //
530 // Check to see if we should (can) install as a NT service
531 //
532
|
533 kumpf 1.34.2.4 if (String::equal(configManager->getCurrentValue("install"), "true"))
|
534 kumpf 1.34.2.1 {
535 if( 0 != cimserver_install_nt_service( pegasusHome ))
536 {
537 cout << "\nPegasus installed as NT Service";
538 exit(0);
539 }
540 }
|
541 mike 1.32
|
542 kumpf 1.34.2.1 //
543 // Check to see if we should (can) remove Pegasus as an NT service
544 //
545
|
546 kumpf 1.34.2.4 if (String::equal(configManager->getCurrentValue("remove"), "true"))
|
547 kumpf 1.34.2.1 {
548 if( 0 != cimserver_remove_nt_service() )
549 {
550 cout << "\nPegasus removed as NT Service";
551 exit(0);
552 }
553 }
|
554 mike 1.32
|
555 kumpf 1.34.2.1 //
556 // Check to see if we should Pegasus as a daemon
557 //
558
|
559 kumpf 1.34.2.4 if (String::equal(configManager->getCurrentValue("daemon"), "true"))
|
560 kumpf 1.34.2.1 {
561 daemonOption = true;
562 }
|
563 mike 1.32
|
564 kumpf 1.34.2.1 //
|
565 kumpf 1.34.2.10 // Check to see if we need to shutdown CIMOM
566 //
567 if (shutdownOption)
568 {
569 //
570 // if timeout was specified, validate the timeout value
571 //
572 if (timeoutOption)
573 {
574 Boolean valid = configManager->validatePropertyValue(
575 PROPERTY_TIMEOUT,
576 timeoutStr);
577 if (!valid)
578 {
579 cout << "Invalid timeout value specified: " << timeoutValue;
580 cout << endl;
581 exit(1);
582 }
583 }
584
585 shutdownCIMOM(forceOption, timeoutStr);
586 kumpf 1.34.2.10 cout << "Pegasus CIM Server terminated." << endl;
587 exit(0);
588 }
589
590 //
|
591 kumpf 1.34.2.1 // Grab the port option:
592 //
593
594 portOption = configManager->getCurrentValue("port");
595
596 //
597 // Check the trace options and set global variable
598 //
599
|
600 kumpf 1.34.2.4 if (String::equal(configManager->getCurrentValue("trace"), "true"))
|
601 kumpf 1.34.2.1 {
602 Handler::setMessageTrace(true);
603 pegasusIOTrace = true;
604 cout << "Trace Set" << endl;
605 }
606 //
607 // Check the log trace options and set global variable
608 //
609
|
610 kumpf 1.34.2.4 if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
|
611 kumpf 1.34.2.1 {
612 Handler::setMessageLogTrace(true);
613 pegasusIOLog = true;
614 }
|
615 mike 1.32
|
616 kumpf 1.34.2.1 // Get the log file directory definition.
617 // We put String into Cstring because
618 // Directory functions only handle Cstring.
619 // ATTN-KS: create String based directory functions.
620
621 logsDirectory = configManager->getCurrentValue("logdir");
622
623 // Set up the Logger. This does not open the logs
624 // Might be more logical to clean before set.
625 // ATTN: Need tool to completely disable logging.
|
626 kumpf 1.34.2.4
|
627 kumpf 1.34.2.1 Logger::setHomeDirectory(logsDirectory);
628
|
629 kumpf 1.34.2.4 if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
|
630 kumpf 1.34.2.1 {
631 Logger::clean(logsDirectory);;
632 }
|
633 mike 1.32
|
634 kumpf 1.34.2.1 // Leave this in until people get familiar with the logs.
635 cout << "Logs Directory = " << logsDirectory << endl;
|
636 mike 1.32
|
637 kumpf 1.34.2.4 if (String::equal(configManager->getCurrentValue("slp"), "true"))
|
638 kumpf 1.34.2.1 {
639 useSLP = true;
640 }
|
641 mike 1.32 }
|
642 kumpf 1.34.2.1 catch (UnrecognizedConfigProperty e)
|
643 mike 1.32 {
|
644 kumpf 1.34.2.1 cout << "Error: " << e.getMessage() << endl;
|
645 mike 1.32 }
646
647 char* address = portOption.allocateCString();
648
649 // Put out startup up message.
650 cout << PEGASUS_NAME << PEGASUS_VERSION <<
651 " on port " << address << endl;
652 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
653 cout <<"Started..."
654 << (pegasusIOTrace ? " Tracing to Display ": " ")
655 << (pegasusIOLog ? " Tracing to Log ": " ")
656 << (useSLP ? " SLP reg. " : " No SLP ")
657 << endl;
658
659 // Put server start message to the logger
660 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
661 "Start $0 $1 port $2 $3 $4",
662 PEGASUS_NAME,
663 PEGASUS_VERSION,
664 address,
665 (pegasusIOTrace ? " Tracing": " "),
666 mike 1.32 (useSLP ? " SLP on " : " SLP off "));
667
|
668 kumpf 1.34.2.1 // do we need to run as a daemon ?
669 if (daemonOption)
670 {
671 if(-1 == cimserver_fork())
672 exit(-1);
673 }
|
674 mike 1.32
675 // try loop to bind the address, and run the server
676 try
677 {
|
678 sage 1.34.2.9 #ifndef PEGASUS_OS_ZOS
|
679 mike 1.32 slp_client *discovery = new slp_client() ;;
680 String serviceURL;
681 serviceURL.assign("service:cim.pegasus://");
682 String host_name = slp_get_host_name();
683 serviceURL += host_name;
684 serviceURL += ":";
685 serviceURL += address;
686 char *url = serviceURL.allocateCString();
687 // free(host_name);
|
688 sage 1.34.2.9 #endif
|
689 mike 1.32
|
690 mike 1.34.2.5 Monitor monitor;
691 CIMServer server(&monitor, pegasusHome);
|
692 mike 1.32
693 // bind throws an exception of the bind fails
|
694 mike 1.33 cout << "Binding to " << address << endl;
|
695 mike 1.34.2.5
696 char* end = 0;
697 long portNumber = strtol(address, &end, 10);
698 assert(end != 0 && *end == '\0');
699 server.bind(portNumber);
700
|
701 mike 1.32 delete [] address;
702
703 time_t last = 0;
|
704 kumpf 1.34.2.10
705 //
706 // Loop to call CIMServer's runForever() method until CIMServer
707 // has been shutdown
708 //
709 while( !server.terminated() )
|
710 mike 1.32 {
|
711 sage 1.34.2.9 #ifndef PEGASUS_OS_ZOS
|
712 mike 1.32 if(useSLP )
713 {
714 if( (time(NULL) - last ) > 60 )
715 {
716 if( discovery != NULL && url != NULL )
717 discovery->srv_reg_all(url,
|
718 kumpf 1.34.2.4 "(namespace=root/cimv2)",
|
719 mike 1.32 "service:cim.pegasus",
720 "DEFAULT",
721 70) ;
722 time(&last);
723 }
724
725 discovery->service_listener();
726 }
|
727 sage 1.34.2.9 #endif
|
728 mike 1.32 server.runForever();
729 }
730
|
731 mike 1.34 // This statement is unrechable!
732 //
733 // Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
734 // "Normal Termination");
|
735 mike 1.32 }
736 catch(Exception& e)
737 {
738 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
739 "Abnormal Termination $0", e.getMessage());
740
741 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
742 }
743
744 return 0;
745 }
|