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 kumpf 1.54 // cimserver -s [-t timeout_value]
|
51 mike 1.35 //
|
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 kumpf 1.54 static const char OPTION_TIMEOUT = 't';
|
135 mike 1.35
|
136 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
137 static const char OPTION_BINDVERBOSE = 'X';
138 #endif
139
|
140 kumpf 1.43 static const String NAMESPACE = "root/PG_Internal";
|
141 mike 1.35 static const String CLASSNAME_SHUTDOWNSERVICE = "PG_ShutdownService";
|
142 kumpf 1.54 static const String PROPERTY_TIMEOUT = "shutdownTimeout";
|
143 kumpf 1.45 static const String CIMSERVERSTART_FILE = "/etc/wbem/cimserver_start.conf";
|
144 mike 1.35
145 ConfigManager* configManager;
146
|
147 mike 1.32 /** GetOptions function - This function defines the Options Table
|
148 mike 1.35 and sets up the options from that table using the config manager.
|
149 mike 1.32 */
150 void GetOptions(
|
151 mike 1.35 ConfigManager* cm,
|
152 mike 1.32 int& argc,
153 char** argv,
154 const String& pegasusHome)
155 {
|
156 mike 1.35 try
|
157 mike 1.32 {
|
158 kumpf 1.38 cm->mergeConfigFiles();
|
159 mike 1.33
|
160 mike 1.35 cm->mergeCommandLine(argc, argv);
161 }
162 catch (NoSuchFile nsf)
163 {
164 throw nsf;
165 }
166 catch (FileNotReadable fnr)
167 {
168 throw fnr;
169 }
170 catch (CannotRenameFile ftrf)
171 {
172 throw ftrf;
173 }
174 catch (ConfigFileSyntaxError cfse)
175 {
176 throw cfse;
177 }
178 catch(UnrecognizedConfigProperty ucp)
179 {
180 throw ucp;
181 mike 1.35 }
182 catch(InvalidPropertyValue ipv)
183 {
184 throw ipv;
185 }
|
186 mike 1.32 }
187
188 /* PrintHelp - This is temporary until we expand the options manager to allow
189 options help to be defined with the OptionRow entries and presented from
190 those entries.
191 */
192 void PrintHelp(const char* arg0)
193 {
|
194 mike 1.35 /**
195 Build the usage string for the config command.
196 */
197 String usage = String (USAGE);
198 usage.append (COMMAND_NAME);
199 usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
200 usage.append (" options\n");
201 usage.append (" -v - displays pegasus version number\n");
202 usage.append (" -h - prints this help message\n");
203 usage.append (" -D [home] - sets pegasus home directory\n");
204 usage.append (" -d - runs pegasus as a daemon\n");
|
205 kumpf 1.54 usage.append (" -s [-t timeout] \n");
|
206 mike 1.35 usage.append (" - shuts down pegasus\n");
|
207 kumpf 1.54 #if !defined(PEGASUS_OS_HPUX)
|
208 mike 1.35 usage.append (" -cleanlogs - clears the log files at startup\n");
209 usage.append (" -install - installs pegasus as a Windows NT Service\n");
210 usage.append (" -remove - removes pegasus as a Windows NT Service\n");
211 usage.append (" -slp - registers pegasus as a service with SLP\n\n");
212 usage.append (" -SSL - uses SSL\n\n");
|
213 kumpf 1.54 #endif
|
214 mike 1.35 usage.append (" configProperty=value\n");
215 usage.append (" port=nnnn - sets port number to listen on\n");
216 usage.append (" logdir=/pegasus/logs - directory for log files\n");
217
218 cout << endl;
|
219 mike 1.32 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
220 cout << endl;
|
221 mike 1.35 cout << usage << endl;
222 }
223
|
224 kumpf 1.52 void shutdownCIMOM(Uint32 timeoutValue)
|
225 mike 1.35 {
226 //
227 // Create CIMClient object
228 //
|
229 kumpf 1.42 CIMClient client;
|
230 mike 1.35
231 //
|
232 kumpf 1.53 // Get local host name
|
233 mike 1.35 //
234 String hostStr = System::getHostName();
235
236 //
237 // open connection to CIMOM
238 //
239 try
240 {
|
241 kumpf 1.43 client.connectLocal();
|
242 kumpf 1.52
243 //
|
244 kumpf 1.54 // set client timeout to 2 seconds more than the shutdown timeout
|
245 kumpf 1.52 // so that the command client does not timeout before the cimserver
246 // terminates
247 //
|
248 kumpf 1.54 Uint32 clientTimeout;
249 if (timeoutValue == 0)
250 {
251 String configTimeout =
252 configManager->getCurrentValue("shutdownTimeout");
253 ArrayDestroyer<char> timeoutCString(configTimeout.allocateCString());
254 clientTimeout =
255 ((strtol(timeoutCString.getPointer(), (char **)0,10))+2)*1000;
256 }
257 else
258 {
259 clientTimeout = (timeoutValue + 2)*1000;
260 }
261
262 client.setTimeOut(clientTimeout);
|
263 mike 1.35 }
|
264 kumpf 1.43 catch(CIMClientException& e)
|
265 mike 1.35 {
|
266 kumpf 1.52 PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
267 PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
|
268 kumpf 1.45 exit(0);
|
269 mike 1.35 }
270
271 try
272 {
273 //
|
274 kumpf 1.52 // construct CIMObjectPath
|
275 mike 1.35 //
276 String referenceStr = "//";
277 referenceStr.append(hostStr);
|
278 kumpf 1.53 referenceStr.append(PEGASUS_NAMESPACENAME_CIMV2);
279 referenceStr.append(":");
280 referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN);
|
281 kumpf 1.50 CIMObjectPath reference(referenceStr);
|
282 mike 1.35
283 //
284 // issue the invokeMethod request on the shutdown method
285 //
286 Array<CIMParamValue> inParams;
287 Array<CIMParamValue> outParams;
288
|
289 kumpf 1.52 // set force option to true for now
|
290 kumpf 1.40 inParams.append(CIMParamValue("force",
|
291 kumpf 1.52 CIMValue(Boolean(true))));
|
292 mike 1.35
|
293 kumpf 1.40 inParams.append(CIMParamValue("timeout",
|
294 kumpf 1.39 CIMValue(Uint32(timeoutValue))));
|
295 mike 1.35
296 CIMValue retValue = client.invokeMethod(
297 NAMESPACE,
298 reference,
299 "shutdown",
300 inParams,
301 outParams);
|
302 kumpf 1.43 }
|
303 kumpf 1.46 catch(CIMClientCIMException& e)
304 {
305 PEGASUS_STD(cerr) << "Failed to shutdown server: ";
306 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
307 exit(1);
308 }
|
309 kumpf 1.45 catch(CIMClientException& e)
310 {
311 //
|
312 kumpf 1.54 // This may mean the CIM Server has been terminated and returns a
313 // "Empty HTTP response message" HTTP error response. To be sure
314 // CIM Server gets shutdown, if CIM Server is still running at
315 // this time, we will kill the cimserver process.
|
316 kumpf 1.45 //
|
317 kumpf 1.54
318 #if defined(PEGASUS_OS_HPUX)
319
320 // give cimom some time to finish up
|
321 kumpf 1.45 System::sleep(1);
|
322 kumpf 1.54
323 // add code to kill cimom if it is still running
324
|
325 kumpf 1.45 #endif
|
326 kumpf 1.43 }
|
327 mike 1.35 catch(Exception& e)
328 {
|
329 kumpf 1.45 PEGASUS_STD(cerr) << "Failed to shutdown server: ";
330 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
|
331 mike 1.35 exit(1);
332 }
333
334 return;
|
335 mike 1.32 }
336
|
337 mike 1.35
|
338 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
339 mike 1.32 // MAIN
340 //////////////////////////////////////////////////////////////////////////
341 int main(int argc, char** argv)
342 {
|
343 mike 1.35 String pegasusHome = String::EMPTY;
344 Boolean pegasusIOLog = false;
|
345 kumpf 1.53 String httpPort = String::EMPTY;
346 String httpsPort = String::EMPTY;
|
347 mike 1.35 String logsDirectory = String::EMPTY;
348 Boolean useSLP = false;
349 Boolean useSSL = false;
350 Boolean daemonOption = false;
351 Boolean shutdownOption = false;
352 Boolean timeoutOption = false;
353 String timeoutStr = String::EMPTY;
354 long timeoutValue = 0;
|
355 mday 1.47
|
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 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
420 //
|
421 kumpf 1.49 // Check to see if user asked for the version (-X option):
|
422 kumpf 1.48 //
423 if (*option == OPTION_BINDVERBOSE)
424 {
425 System::bindVerbose = true;
426 cout << "Unsupported debug option, BIND_VERBOSE, enabled."
427 << endl;
428 // remove the option from the command line
429 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
430 argc--;
431 }
432 #endif
|
433 mike 1.35 //
434 // Check to see if user asked for shutdown (-s option):
435 //
436 else if (*option == OPTION_SHUTDOWN)
437 {
|
438 kumpf 1.52
|
439 mike 1.35 //
|
440 kumpf 1.52 // check to see if user is root
|
441 mike 1.35 //
|
442 kumpf 1.55 if (!System::isPrivilegedUser(System::getEffectiveUserName()))
|
443 mike 1.35 {
|
444 kumpf 1.52 cout << "You must have superuser privilege to run ";
445 cout << "cimserver." << endl;
|
446 mike 1.35 exit(0);
447 }
448
449 //
|
450 kumpf 1.52 // Check to see if shutdown has already been specified:
|
451 mike 1.35 //
|
452 kumpf 1.52 if (shutdownOption)
|
453 mike 1.35 {
|
454 kumpf 1.52 cout << "Duplicate shutdown option specified." << endl;
|
455 mike 1.35 exit(0);
456 }
457
|
458 kumpf 1.52 shutdownOption = true;
|
459 mike 1.35
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 {
477 cout << "Duplicate timeout option specified." << endl;
478 exit(0);
479 }
480 mike 1.35
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 delete [] tmp;
498 exit(0);
499 }
500 }
501 mike 1.35 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.52 shutdownCIMOM(timeoutValue);
|
629 kumpf 1.45
|
630 kumpf 1.54 cout << "Pegasus CIM Server stopped." << endl;
|
631 mike 1.35 exit(0);
632 }
|
633 mike 1.32
|
634 mike 1.35 //
|
635 kumpf 1.53 // Get the port numbers
|
636 mike 1.35 //
637
|
638 kumpf 1.53 httpPort = configManager->getCurrentValue("httpPort");
639
640 httpsPort = configManager->getCurrentValue("httpsPort");
|
641 mike 1.35
|
642 kumpf 1.36 // Leave this in until people get familiar with the logs.
643 cout << "Logs Directory = " << logsDirectory << endl;
|
644 mike 1.35
645 if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
646 {
647 Logger::clean(logsDirectory);;
648 }
|
649 mike 1.32
|
650 mike 1.35 if (String::equal(configManager->getCurrentValue("slp"), "true"))
651 {
652 useSLP = true;
653 }
|
654 mike 1.32
|
655 mike 1.35 if (String::equal(configManager->getCurrentValue("SSL"), "true"))
656 {
657 useSSL = true;
658 }
|
659 mike 1.32 }
|
660 mike 1.35 catch (UnrecognizedConfigProperty e)
|
661 mike 1.32 {
|
662 mike 1.35 cout << "Error: " << e.getMessage() << endl;
|
663 mike 1.32 }
664
|
665 kumpf 1.53 Uint32 portNumber;
666
667 char address[32];
668
669 if (useSSL)
670 {
671 char* p = httpsPort.allocateCString();
672 char* end = 0;
673 Uint32 port = strtol(p, &end, 10);
674 assert(end != 0 && *end == '\0');
675 delete [] p;
676
677 //
678 // Look up the WBEM-HTTPS port number
679 //
680 portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
681 sprintf(address, "%u", portNumber);
682 }
683 else
684 {
685 char* p = httpPort.allocateCString();
686 kumpf 1.53 char* end = 0;
687 Uint32 port = strtol(p, &end, 10);
688 assert(end != 0 && *end == '\0');
689 delete [] p;
690
691 //
692 // Look up the WBEM-HTTP port number
693 //
694 portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
695 sprintf(address, "%u", portNumber);
696 }
|
697 mike 1.32
698 // Put out startup up message.
699 cout << PEGASUS_NAME << PEGASUS_VERSION <<
700 " on port " << address << endl;
701 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
|
702 kumpf 1.54 cout <<"Starting..."
|
703 mike 1.32 << (pegasusIOLog ? " Tracing to Log ": " ")
704 << (useSLP ? " SLP reg. " : " No SLP ")
|
705 mike 1.35 << (useSSL ? " Use SSL " : " No SSL ")
|
706 mike 1.32 << endl;
707
|
708 kumpf 1.51 // do we need to run as a daemon ?
709 if (daemonOption)
710 {
711 if(-1 == cimserver_fork())
712 exit(-1);
713 }
714
|
715 kumpf 1.54 // Put server starting message to the logger
|
716 mike 1.32 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
717 kumpf 1.54 "Starting $0 version $1 on port $2 $3 $4 $5",
|
718 mike 1.32 PEGASUS_NAME,
719 PEGASUS_VERSION,
720 address,
|
721 mike 1.35 (useSLP ? " SLP on " : " SLP off "),
722 (useSSL ? " Use SSL " : " No SSL "));
|
723 mike 1.32
724 // try loop to bind the address, and run the server
725 try
726 {
|
727 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
|
728 mike 1.32 slp_client *discovery = new slp_client() ;;
729 String serviceURL;
730 serviceURL.assign("service:cim.pegasus://");
731 String host_name = slp_get_host_name();
732 serviceURL += host_name;
733 serviceURL += ":";
734 serviceURL += address;
735 char *url = serviceURL.allocateCString();
736 // free(host_name);
|
737 mike 1.35 #endif
|
738 mike 1.32
|
739 mike 1.35 Monitor monitor;
|
740 kumpf 1.38 CIMServer server(&monitor, useSSL);
|
741 kumpf 1.41
742 // bind throws an exception if the bind fails
743 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
744 cout << "Binding to domain socket" << endl;
745 #else
|
746 mike 1.33 cout << "Binding to " << address << endl;
|
747 kumpf 1.41 #endif
|
748 mike 1.35
749 server.bind(portNumber);
|
750 mike 1.32
751 time_t last = 0;
|
752 mike 1.35
|
753 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
754 //
755 // create a file to indicate that the cimserver has started
756 //
757 fstream fs;
758 ArrayDestroyer<char> p(CIMSERVERSTART_FILE.allocateCString());
759 fs.open(p.getPointer(), ios::in | ios::out);
760 if (!fs)
761 {
762 //
763 // failed to create the file, write an entry to the log file
764 // and proceed
765 //
|
766 kumpf 1.54 //Logger::put(Logger::STANDARD_LOG, "CIMServer",
767 // Logger::INFORMATION,
768 // "Failed to open the $0 file needed by cimserverd.",
769 // CIMSERVERSTART_FILE);
|
770 kumpf 1.45 }
771 else
772 {
773 fs.close();
774 }
775 #endif
|
776 kumpf 1.54 cout << "Started. " << endl;
777
778 // Put server started message to the logger
779 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
780 "$0 started.", PEGASUS_NAME);
|
781 kumpf 1.45
|
782 mike 1.35 //
783 // Loop to call CIMServer's runForever() method until CIMServer
784 // has been shutdown
785 //
786 while( !server.terminated() )
|
787 mike 1.32 {
|
788 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
|
789 mike 1.32 if(useSLP )
790 {
791 if( (time(NULL) - last ) > 60 )
792 {
793 if( discovery != NULL && url != NULL )
794 discovery->srv_reg_all(url,
|
795 mike 1.35 "(namespace=root/cimv2)",
|
796 mike 1.32 "service:cim.pegasus",
797 "DEFAULT",
798 70) ;
799 time(&last);
800 }
801
802 discovery->service_listener();
803 }
|
804 mike 1.35 #endif
|
805 mike 1.32 server.runForever();
806 }
807
|
808 kumpf 1.45 //
809 // normal termination
|
810 mike 1.34 //
|
811 kumpf 1.54 // Put server shutdown message to the logger
812 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
813 "$0 stopped.", PEGASUS_NAME);
|
814 kumpf 1.45
815 #if defined(PEGASUS_OS_HPUX)
816 //
817 // close the file at startup time to indicate that the cimserver
818 // has terminated normally.
819 //
820 FileSystem::removeFile(CIMSERVERSTART_FILE);
821 #endif
|
822 mike 1.32 }
823 catch(Exception& e)
824 {
825 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
826 kumpf 1.54 "$0 Abnormal Termination.", e.getMessage());
|
827 mike 1.32
828 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
829 kumpf 1.54 return 1;
|
830 mike 1.32 }
831
832 return 0;
833 }
|