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 mike 1.35 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
30 //
31 // Modified By: Jenny Yu (jenny_yu@hp.com)
32 //
|
33 kumpf 1.38 // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
34 //
|
35 mike 1.32 //%/////////////////////////////////////////////////////////////////////////////
36
37
38 //////////////////////////////////////////////////////////////////////
39 //
40 // Notes on deamon operation (Unix) and service operation (Win 32):
41 //
42 // To run pegasus as a daemon on Unix platforms, use the -d option:
43 //
44 // cimserver -d
45 //
46 // The -d option has no effect on windows operation.
47 //
|
48 mike 1.35 // To shutdown pegasus, use the -s option:
49 //
50 // cimserver -s [-f] [-T timeout_value]
51 //
|
52 mike 1.32 // To run pegasus as an NT service, there are FOUR different possibilities:
53 //
54 // To INSTALL the Pegasus service,
55 //
56 // cimserver -install
57 //
58 // To REMOVE the Pegasus service,
59 //
60 // cimserver -remove
61 //
62 // To START the Pegasus service,
63 //
64 // net start cimserver
65 //
66 // To STOP the Pegasus service,
67 //
68 // net stop cimserver
69 //
70 // Alternatively, you can use the windows service manager. Pegasus shows up
71 // in the service database as "Pegasus CIM Object Manager"
72 //
73 mike 1.32 // Mike Day, mdday@us.ibm.com
74 //
75 //////////////////////////////////////////////////////////////////////
76
77
|
78 mike 1.35 #include <Pegasus/Common/Config.h>
|
79 mday 1.47 #include <Pegasus/suballoc/suballoc.h>
|
80 mike 1.32 #include <iostream>
|
81 mike 1.35 #include <cassert>
|
82 mike 1.32 #include <cstdlib>
|
83 kumpf 1.45 #include <fstream>
|
84 mike 1.32 #include <Pegasus/Common/FileSystem.h>
|
85 mike 1.35 #include <Pegasus/Common/Monitor.h>
|
86 mike 1.32 #include <Pegasus/Server/CIMServer.h>
87 #include <Pegasus/Common/PegasusVersion.h>
88 #include <Pegasus/Common/Logger.h>
89 #include <Pegasus/Common/System.h>
|
90 mike 1.35 #include <Pegasus/Common/Tracer.h>
91 #include <Pegasus/Config/ConfigManager.h>
92 #include <Pegasus/Client/CIMClient.h>
93 #include <Pegasus/Server/ShutdownService.h>
|
94 kumpf 1.38 #include <Pegasus/Common/Destroyer.h>
|
95 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
|
96 mike 1.32 #include <slp/slp.h>
|
97 mike 1.35 #endif
|
98 mike 1.32
99
100 #if defined(PEGASUS_OS_TYPE_WINDOWS)
101 # include "cimserver_windows.cpp"
102 #elif defined(PEGASUS_OS_TYPE_UNIX)
103 # include "cimserver_unix.cpp"
104 #else
105 # error "Unsupported platform"
106 #endif
107
108 PEGASUS_USING_PEGASUS;
109 PEGASUS_USING_STD;
110
|
111 mike 1.35 //
112 // The command name.
113 //
114 static const char COMMAND_NAME [] = "cimserver";
115
116 //
117 // The constant defining usage string.
118 //
119 static const char USAGE [] = "Usage: ";
120
121 /**
122 Constants representing the command line options.
123 */
124 static const char OPTION_VERSION = 'v';
125
126 static const char OPTION_HELP = 'h';
127
128 static const char OPTION_HOME = 'D';
129
130 static const char OPTION_SHUTDOWN = 's';
131
132 mike 1.35 static const char OPTION_FORCE = 'f';
133
134 static const char OPTION_TIMEOUT = 'T';
135
|
136 kumpf 1.43 static const String NAMESPACE = "root/PG_Internal";
|
137 mike 1.35 static const String CLASSNAME_SHUTDOWNSERVICE = "PG_ShutdownService";
|
138 kumpf 1.36 static const String PROPERTY_TIMEOUT = "operationTimeout";
|
139 kumpf 1.45 static const String CIMSERVERSTART_FILE = "/etc/wbem/cimserver_start.conf";
|
140 mike 1.35
141 ConfigManager* configManager;
142
|
143 mike 1.32 /** GetOptions function - This function defines the Options Table
|
144 mike 1.35 and sets up the options from that table using the config manager.
|
145 mike 1.32 */
146 void GetOptions(
|
147 mike 1.35 ConfigManager* cm,
|
148 mike 1.32 int& argc,
149 char** argv,
150 const String& pegasusHome)
151 {
|
152 mike 1.35 try
|
153 mike 1.32 {
|
154 kumpf 1.38 cm->mergeConfigFiles();
|
155 mike 1.33
|
156 mike 1.35 cm->mergeCommandLine(argc, argv);
157 }
158 catch (NoSuchFile nsf)
159 {
160 throw nsf;
161 }
162 catch (FileNotReadable fnr)
163 {
164 throw fnr;
165 }
166 catch (CannotRenameFile ftrf)
167 {
168 throw ftrf;
169 }
170 catch (ConfigFileSyntaxError cfse)
171 {
172 throw cfse;
173 }
174 catch(UnrecognizedConfigProperty ucp)
175 {
176 throw ucp;
177 mike 1.35 }
178 catch(InvalidPropertyValue ipv)
179 {
180 throw ipv;
181 }
|
182 mike 1.32 }
183
184 /* PrintHelp - This is temporary until we expand the options manager to allow
185 options help to be defined with the OptionRow entries and presented from
186 those entries.
187 */
188 void PrintHelp(const char* arg0)
189 {
|
190 mike 1.35 /**
191 Build the usage string for the config command.
192 */
193 String usage = String (USAGE);
194 usage.append (COMMAND_NAME);
195 usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
196 usage.append (" options\n");
197 usage.append (" -v - displays pegasus version number\n");
198 usage.append (" -h - prints this help message\n");
199 usage.append (" -D [home] - sets pegasus home directory\n");
200 usage.append (" -t - turns tracing on\n");
201 usage.append (" -t - turns on trace of client IO to console\n");
202 usage.append (" -l - turns on trace of client IO to trace file\n");
203 usage.append (" -d - runs pegasus as a daemon\n");
204 usage.append (" -s [-f] [-T timeout] \n");
205 usage.append (" - shuts down pegasus\n");
206 usage.append (" -cleanlogs - clears the log files at startup\n");
207 usage.append (" -install - installs pegasus as a Windows NT Service\n");
208 usage.append (" -remove - removes pegasus as a Windows NT Service\n");
209 usage.append (" -slp - registers pegasus as a service with SLP\n\n");
210 usage.append (" -SSL - uses SSL\n\n");
211 mike 1.35
212 usage.append (" configProperty=value\n");
213 usage.append (" port=nnnn - sets port number to listen on\n");
214 usage.append (" logdir=/pegasus/logs - directory for log files\n");
215
216 cout << endl;
|
217 mike 1.32 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
218 cout << endl;
|
219 mike 1.35 cout << usage << endl;
220 }
221
|
222 kumpf 1.36 void shutdownCIMOM(Boolean forceOption, Uint32 timeoutValue)
|
223 mike 1.35 {
224 //
225 // Create CIMClient object
226 //
|
227 kumpf 1.42 CIMClient client;
|
228 mike 1.35
229 //
230 // Get the port number
231 //
232 String portNumberStr = configManager->getCurrentValue("port");
233
234 String hostStr = System::getHostName();
235 hostStr.append(":");
236 hostStr.append(portNumberStr);
237
|
238 kumpf 1.36 // Put server shutdown message to the logger
239 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
240 "Shutdown $0 on port $1.", PEGASUS_NAME, portNumberStr);
241
|
242 mike 1.35 //
243 // open connection to CIMOM
244 //
245 try
246 {
|
247 kumpf 1.43 client.connectLocal();
|
248 mike 1.35 }
|
249 kumpf 1.43 catch(CIMClientException& e)
|
250 mike 1.35 {
|
251 kumpf 1.36 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
252 "Failed to connect to $0 $1.", PEGASUS_NAME, e.getMessage());
253
|
254 kumpf 1.45 PEGASUS_STD(cerr) << "Failed to connect to server: ";
255 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
256 exit(0);
|
257 mike 1.35 }
258
259 try
260 {
261 //
262 // construct CIMReference
263 //
264 String referenceStr = "//";
265 referenceStr.append(hostStr);
266 referenceStr.append("/root/cimv2:PG_ShutdownService");
267 CIMReference reference(referenceStr);
268
269 //
270 // issue the invokeMethod request on the shutdown method
271 //
272 Array<CIMParamValue> inParams;
273 Array<CIMParamValue> outParams;
274
|
275 kumpf 1.40 inParams.append(CIMParamValue("force",
|
276 kumpf 1.39 CIMValue(Boolean(forceOption))));
|
277 mike 1.35
|
278 kumpf 1.40 inParams.append(CIMParamValue("timeout",
|
279 kumpf 1.39 CIMValue(Uint32(timeoutValue))));
|
280 mike 1.35
281 CIMValue retValue = client.invokeMethod(
282 NAMESPACE,
283 reference,
284 "shutdown",
285 inParams,
286 outParams);
|
287 kumpf 1.36
288 // Put server shutdown message to the logger
289 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
290 "$0 terminated on port $1.", PEGASUS_NAME, portNumberStr);
291
|
292 kumpf 1.43 }
|
293 kumpf 1.46 catch(CIMClientCIMException& e)
294 {
295 PEGASUS_STD(cerr) << "Failed to shutdown server: ";
296 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
297 exit(1);
298 }
|
299 kumpf 1.45 catch(CIMClientException& e)
300 {
301 //
302 // This may mean the cimserver has been terminated and returns the
303 // "Empty HTTP response message" HTTP error response. To be sure,
304 // we need to check if cimserver is indeed terminated.
305 //
306 #ifdef PEGASUS_OS_TYPE_UNIX
307 System::sleep(1);
308 int ret = system("ps -ef | grep cimserver | grep -v grep | grep -v cimserverd >/dev/null");
309 if (ret == 0)
310 {
311 // cimserver has been terminated
312 // Put server shutdown message to the logger
313 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
314 "$0 terminated on port $1.", PEGASUS_NAME, portNumberStr);
315 }
316 else
317 {
318 // cimserver is still running
319 PEGASUS_STD(cerr) << "Failed to shutdown server: ";
320 kumpf 1.45 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
321 exit(1);
322 }
323 #endif
|
324 kumpf 1.43 }
|
325 mike 1.35 catch(Exception& e)
326 {
|
327 kumpf 1.45 PEGASUS_STD(cerr) << "Failed to shutdown server: ";
328 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
|
329 mike 1.35 exit(1);
330 }
331
332 return;
|
333 mike 1.32 }
334
|
335 mike 1.35
|
336 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
337 mike 1.32 // MAIN
338 //////////////////////////////////////////////////////////////////////////
339 int main(int argc, char** argv)
340 {
|
341 mike 1.35 String pegasusHome = String::EMPTY;
342 Boolean pegasusIOTrace = false;
343 Boolean pegasusIOLog = false;
344 String portOption = String::EMPTY;
345 String logsDirectory = String::EMPTY;
346 Boolean useSLP = false;
347 Boolean useSSL = false;
348 Boolean daemonOption = false;
349 Boolean shutdownOption = false;
350 Boolean forceOption = false;
351 Boolean timeoutOption = false;
352 String timeoutStr = String::EMPTY;
353 long timeoutValue = 0;
|
354 mday 1.47
|
355 mike 1.35
|
356 kumpf 1.38 //
357 // Get environment variables:
358 //
359 const char* tmp = getenv("PEGASUS_HOME");
360
361 if (tmp)
362 {
363 pegasusHome = tmp;
364 }
365
366 FileSystem::translateSlashes(pegasusHome);
367
|
368 mike 1.32 // on Windows NT if there are no command-line options, run as a service
369
370 if (argc == 1 )
|
371 mike 1.35 {
372 cim_server_service(argc, argv);
373 }
374 else
375 {
376 // Get help, version and home options
377
378 for (int i = 1; i < argc; )
379 {
380 const char* arg = argv[i];
381
382 // Check for -option
383 if (*arg == '-')
384 {
385 // Get the option
386 const char* option = arg + 1;
387
388 //
389 // Check to see if user asked for the version (-v option):
390 //
391 if (*option == OPTION_VERSION)
392 mike 1.35 {
393 cout << PEGASUS_VERSION << endl;
394 exit(0);
395 }
396 //
397 // Check to see if user asked for help (-h option):
398 //
399 else if (*option == OPTION_HELP)
400 {
401 PrintHelp(argv[0]);
402 exit(0);
403 }
404 else if (*option == OPTION_HOME)
405 {
406 if (i + 1 < argc)
407 {
408 pegasusHome.assign(argv[i + 1]);
409 }
410 else
411 {
412 cout << "Missing argument for option -" << option << endl;
413 mike 1.35 exit(0);
414 }
415
416 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
417 argc -= 2;
418 }
419 //
420 // Check to see if user asked for shutdown (-s option):
421 //
422 else if (*option == OPTION_SHUTDOWN)
423 {
424 //
425 // Check to see if shutdown has already been specified:
426 //
427 if (shutdownOption)
428 {
429 cout << "Duplicate shutdown option specified." << endl;
430 exit(0);
431 }
432 shutdownOption = true;
433
434 mike 1.35 // remove the option from the command line
435 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
436 argc--;
437 }
438 else if (*option == OPTION_FORCE)
439 {
440 //
441 // Check to see if shutdown has been specified:
442 //
443 if (!shutdownOption)
444 {
445 cout << "Invalid option -" << option << endl;
446 exit(0);
447 }
448
449 //
450 // Check to see if force has already been specified:
451 //
452 if (forceOption)
453 {
454 cout << "Duplicate force option specified." << endl;
455 mike 1.35 exit(0);
456 }
457
458 forceOption = true;
459
460 // remove the option from the command line
461 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
462 argc--;
463 }
464 else if (*option == OPTION_TIMEOUT)
465 {
466 //
467 // Check to see if shutdown has been specified:
468 //
469 if (!shutdownOption)
470 {
471 cout << "Invalid option -" << option << endl;
472 exit(0);
473 }
474
475 if (timeoutOption)
476 mike 1.35 {
477 cout << "Duplicate timeout option specified." << endl;
478 exit(0);
479 }
480
481 timeoutOption = true;
482
483 if (i + 1 < argc)
484 {
485 // get timeout value
486 timeoutStr.assign(argv[i + 1]);
487
488 // validate timeout value string
489 char* tmp = timeoutStr.allocateCString();
490 char* end = 0;
491 timeoutValue = strtol(tmp, &end, 10);
492
493 if (!end || *end != '\0')
494 {
495 cout << "invalid timeout value specified: ";
496 cout << timeoutStr << endl;
497 mike 1.35 delete [] tmp;
498 exit(0);
499 }
500 }
501 else
502 {
503 cout << "Missing argument for option -";
504 cout << option << endl;
505 exit(0);
506 }
507
508 // remove the option from the command line
509 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
510 argc -= 2;
511 }
512 else
513 i++;
514 }
515 else
516 i++;
|
517 mike 1.32 }
518 }
|
519 mike 1.35
|
520 kumpf 1.38 //
521 // Set the value for pegasusHome property
522 //
523 ConfigManager::setPegasusHome(pegasusHome);
|
524 mike 1.32
|
525 mike 1.35 //
526 // Get an instance of the Config Manager.
527 //
528 configManager = ConfigManager::getInstance();
529
530 //
|
531 mike 1.32 // Get options (from command line and from configuration file); this
|
532 mike 1.35 // removes corresponding options and their arguments from the command
|
533 mike 1.32 // line.
|
534 mike 1.35 //
|
535 mike 1.32 try
536 {
|
537 mike 1.35 GetOptions(configManager, argc, argv, pegasusHome);
|
538 mike 1.32 }
539 catch (Exception& e)
540 {
|
541 mike 1.35 cerr << argv[0] << ": " << e.getMessage() << endl;
542 exit(1);
|
543 mike 1.32 }
544
545
|
546 mike 1.35 try
|
547 mike 1.32 {
|
548 mike 1.35 //
549 // Check to see if we should (can) install as a NT service
550 //
551
552 if (String::equal(configManager->getCurrentValue("install"), "true"))
553 {
554 if( 0 != cimserver_install_nt_service( pegasusHome ))
555 {
556 cout << "\nPegasus installed as NT Service";
557 exit(0);
558 }
559 }
|
560 mike 1.32
|
561 mike 1.35 //
562 // Check to see if we should (can) remove Pegasus as an NT service
563 //
564
565 if (String::equal(configManager->getCurrentValue("remove"), "true"))
566 {
567 if( 0 != cimserver_remove_nt_service() )
568 {
569 cout << "\nPegasus removed as NT Service";
570 exit(0);
571 }
572 }
|
573 mike 1.32
|
574 mike 1.35 //
575 // Check to see if we should Pegasus as a daemon
576 //
577
578 if (String::equal(configManager->getCurrentValue("daemon"), "true"))
579 {
580 daemonOption = true;
581 }
|
582 mike 1.32
|
583 mike 1.35 //
|
584 kumpf 1.36 // Check the log trace options and set global variable
585 //
586
587 if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
588 {
589 pegasusIOLog = true;
590 }
591
592 // Get the log file directory definition.
593 // We put String into Cstring because
594 // Directory functions only handle Cstring.
595 // ATTN-KS: create String based directory functions.
596
597 logsDirectory = configManager->getCurrentValue("logdir");
|
598 kumpf 1.38 logsDirectory =
599 ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
|
600 kumpf 1.36
601 // Set up the Logger. This does not open the logs
602 // Might be more logical to clean before set.
603 // ATTN: Need tool to completely disable logging.
604
605 Logger::setHomeDirectory(logsDirectory);
606
607 //
|
608 mike 1.35 // Check to see if we need to shutdown CIMOM
609 //
610 if (shutdownOption)
611 {
612 //
613 // if timeout was specified, validate the timeout value
614 //
615 if (timeoutOption)
616 {
617 Boolean valid = configManager->validatePropertyValue(
618 PROPERTY_TIMEOUT,
619 timeoutStr);
620 if (!valid)
621 {
622 cout << "Invalid timeout value specified: " << timeoutValue;
623 cout << endl;
624 exit(1);
625 }
626 }
627
|
628 kumpf 1.36 shutdownCIMOM(forceOption, timeoutValue);
|
629 kumpf 1.45
|
630 mike 1.35 cout << "Pegasus CIM Server terminated." << endl;
631 exit(0);
632 }
|
633 mike 1.32
|
634 mike 1.35 //
635 // Grab the port option:
636 //
637
638 portOption = configManager->getCurrentValue("port");
639
640 //
641 // Check the trace options and set global variable
642 //
643
644 if (String::equal(configManager->getCurrentValue("trace"), "true"))
645 {
646 pegasusIOTrace = true;
647 cout << "Trace Set" << endl;
648 }
649
|
650 kumpf 1.36 // Leave this in until people get familiar with the logs.
651 cout << "Logs Directory = " << logsDirectory << endl;
|
652 mike 1.35
653 if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
654 {
655 Logger::clean(logsDirectory);;
656 }
|
657 mike 1.32
|
658 mike 1.35 if (String::equal(configManager->getCurrentValue("slp"), "true"))
659 {
660 useSLP = true;
661 }
|
662 mike 1.32
|
663 mike 1.35 if (String::equal(configManager->getCurrentValue("SSL"), "true"))
664 {
665 useSSL = true;
666 }
|
667 mike 1.32 }
|
668 mike 1.35 catch (UnrecognizedConfigProperty e)
|
669 mike 1.32 {
|
670 mike 1.35 cout << "Error: " << e.getMessage() << endl;
|
671 mike 1.32 }
672
673 char* address = portOption.allocateCString();
674
675 // Put out startup up message.
676 cout << PEGASUS_NAME << PEGASUS_VERSION <<
677 " on port " << address << endl;
678 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
679 cout <<"Started..."
680 << (pegasusIOTrace ? " Tracing to Display ": " ")
681 << (pegasusIOLog ? " Tracing to Log ": " ")
682 << (useSLP ? " SLP reg. " : " No SLP ")
|
683 mike 1.35 << (useSSL ? " Use SSL " : " No SSL ")
|
684 mike 1.32 << endl;
685
686 // Put server start message to the logger
687 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
688 mike 1.35 "Start $0 $1 port $2 $3 $4 $5",
|
689 mike 1.32 PEGASUS_NAME,
690 PEGASUS_VERSION,
691 address,
692 (pegasusIOTrace ? " Tracing": " "),
|
693 mike 1.35 (useSLP ? " SLP on " : " SLP off "),
694 (useSSL ? " Use SSL " : " No SSL "));
|
695 mike 1.32
|
696 mike 1.35 // do we need to run as a daemon ?
697 if (daemonOption)
698 {
699 if(-1 == cimserver_fork())
700 exit(-1);
701 }
|
702 mike 1.32
703 // try loop to bind the address, and run the server
704 try
705 {
|
706 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
|
707 mike 1.32 slp_client *discovery = new slp_client() ;;
708 String serviceURL;
709 serviceURL.assign("service:cim.pegasus://");
710 String host_name = slp_get_host_name();
711 serviceURL += host_name;
712 serviceURL += ":";
713 serviceURL += address;
714 char *url = serviceURL.allocateCString();
715 // free(host_name);
|
716 mike 1.35 #endif
|
717 mike 1.32
|
718 mike 1.35 Monitor monitor;
|
719 kumpf 1.38 CIMServer server(&monitor, useSSL);
|
720 kumpf 1.41
721 // bind throws an exception if the bind fails
722 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
723 cout << "Binding to domain socket" << endl;
724 #else
|
725 mike 1.33 cout << "Binding to " << address << endl;
|
726 kumpf 1.41 #endif
|
727 mike 1.35
728 char* end = 0;
729 long portNumber = strtol(address, &end, 10);
730 assert(end != 0 && *end == '\0');
731 server.bind(portNumber);
732
|
733 mike 1.32 delete [] address;
734
735 time_t last = 0;
|
736 mike 1.35
|
737 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
738 //
739 // create a file to indicate that the cimserver has started
740 //
741 fstream fs;
742 ArrayDestroyer<char> p(CIMSERVERSTART_FILE.allocateCString());
743 fs.open(p.getPointer(), ios::in | ios::out);
744 if (!fs)
745 {
746 //
747 // failed to create the file, write an entry to the log file
748 // and proceed
749 //
750 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
751 "Failed to open the $0 file needed by cimserverd.",
752 CIMSERVERSTART_FILE);
753 }
754 else
755 {
756 fs.close();
757 }
758 kumpf 1.45 #endif
759
|
760 mike 1.35 //
761 // Loop to call CIMServer's runForever() method until CIMServer
762 // has been shutdown
763 //
764 while( !server.terminated() )
|
765 mike 1.32 {
|
766 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
|
767 mike 1.32 if(useSLP )
768 {
769 if( (time(NULL) - last ) > 60 )
770 {
771 if( discovery != NULL && url != NULL )
772 discovery->srv_reg_all(url,
|
773 mike 1.35 "(namespace=root/cimv2)",
|
774 mike 1.32 "service:cim.pegasus",
775 "DEFAULT",
776 70) ;
777 time(&last);
778 }
779
780 discovery->service_listener();
781 }
|
782 mike 1.35 #endif
|
783 mike 1.32 server.runForever();
784 }
785
|
786 kumpf 1.45 //
787 // normal termination
|
788 mike 1.34 //
|
789 kumpf 1.45 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
790 "Normal Termination");
791
792 #if defined(PEGASUS_OS_HPUX)
793 //
794 // close the file at startup time to indicate that the cimserver
795 // has terminated normally.
796 //
797 FileSystem::removeFile(CIMSERVERSTART_FILE);
798 #endif
|
799 mike 1.32 }
800 catch(Exception& e)
801 {
802 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
803 "Abnormal Termination $0", e.getMessage());
804
805 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
806 }
807
808 return 0;
809 }
|