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