1 mike 1.32 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 kumpf 1.58 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 mike 1.32 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 kumpf 1.58 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10 mike 1.32 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
|
13 kumpf 1.58 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
14 mike 1.32 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
16 kumpf 1.58 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19 mike 1.32 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Mike Brasher (mbrasher@bmc.com)
25 //
26 // Modified By: Mike Day (mdday@us.ibm.com)
|
27 mike 1.33 //
|
28 mike 1.32 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
29 //
|
30 mike 1.35 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
31 //
32 // Modified By: Jenny Yu (jenny_yu@hp.com)
33 //
|
34 kumpf 1.38 // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
35 //
|
36 mike 1.32 //%/////////////////////////////////////////////////////////////////////////////
37
38
39 //////////////////////////////////////////////////////////////////////
40 //
41 // Notes on deamon operation (Unix) and service operation (Win 32):
42 //
43 // To run pegasus as a daemon on Unix platforms, use the -d option:
44 //
45 // cimserver -d
46 //
47 // The -d option has no effect on windows operation.
48 //
|
49 mike 1.35 // To shutdown pegasus, use the -s option:
50 //
|
51 kumpf 1.54 // cimserver -s [-t timeout_value]
|
52 mike 1.35 //
|
53 mike 1.32 // To run pegasus as an NT service, there are FOUR different possibilities:
54 //
55 // To INSTALL the Pegasus service,
56 //
57 // cimserver -install
58 //
59 // To REMOVE the Pegasus service,
60 //
61 // cimserver -remove
62 //
63 // To START the Pegasus service,
64 //
65 // net start cimserver
66 //
67 // To STOP the Pegasus service,
68 //
69 // net stop cimserver
70 //
71 // Alternatively, you can use the windows service manager. Pegasus shows up
72 // in the service database as "Pegasus CIM Object Manager"
73 //
74 mike 1.32 // Mike Day, mdday@us.ibm.com
75 //
76 //////////////////////////////////////////////////////////////////////
77
78
|
79 mike 1.35 #include <Pegasus/Common/Config.h>
|
80 kumpf 1.59 #include <Pegasus/Common/Constants.h>
|
81 mday 1.47 #include <Pegasus/suballoc/suballoc.h>
|
82 mike 1.32 #include <iostream>
|
83 mike 1.35 #include <cassert>
|
84 mike 1.32 #include <cstdlib>
|
85 kumpf 1.45 #include <fstream>
|
86 mike 1.32 #include <Pegasus/Common/FileSystem.h>
|
87 mike 1.35 #include <Pegasus/Common/Monitor.h>
|
88 mike 1.32 #include <Pegasus/Server/CIMServer.h>
89 #include <Pegasus/Common/PegasusVersion.h>
90 #include <Pegasus/Common/Logger.h>
91 #include <Pegasus/Common/System.h>
|
92 mike 1.35 #include <Pegasus/Common/Tracer.h>
93 #include <Pegasus/Config/ConfigManager.h>
94 #include <Pegasus/Client/CIMClient.h>
95 #include <Pegasus/Server/ShutdownService.h>
|
96 kumpf 1.38 #include <Pegasus/Common/Destroyer.h>
|
97 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
|
98 mike 1.32 #include <slp/slp.h>
|
99 mike 1.35 #endif
|
100 mike 1.32
101
102 #if defined(PEGASUS_OS_TYPE_WINDOWS)
103 # include "cimserver_windows.cpp"
104 #elif defined(PEGASUS_OS_TYPE_UNIX)
105 # include "cimserver_unix.cpp"
106 #else
107 # error "Unsupported platform"
108 #endif
109
110 PEGASUS_USING_PEGASUS;
111 PEGASUS_USING_STD;
112
|
113 mike 1.35 //
114 // The command name.
115 //
116 static const char COMMAND_NAME [] = "cimserver";
117
118 //
119 // The constant defining usage string.
120 //
121 static const char USAGE [] = "Usage: ";
122
123 /**
124 Constants representing the command line options.
125 */
126 static const char OPTION_VERSION = 'v';
127
128 static const char OPTION_HELP = 'h';
129
130 static const char OPTION_HOME = 'D';
131
132 static const char OPTION_SHUTDOWN = 's';
133
134 mike 1.35 static const char OPTION_FORCE = 'f';
135
|
136 kumpf 1.54 static const char OPTION_TIMEOUT = 't';
|
137 mike 1.35
|
138 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
139 static const char OPTION_BINDVERBOSE = 'X';
140 #endif
141
|
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.59 referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN);
|
279 kumpf 1.53 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 kumpf 1.59 PEGASUS_NAMESPACENAME_SHUTDOWN,
|
298 mike 1.35 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.56 // give CIM Server some time to finish up
318 //
|
319 kumpf 1.45 System::sleep(1);
|
320 kumpf 1.56 cimserver_kill();
|
321 kumpf 1.43 }
|
322 mike 1.35 catch(Exception& e)
323 {
|
324 kumpf 1.56 PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: ";
|
325 kumpf 1.45 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
|
326 mike 1.35 exit(1);
327 }
328
329 return;
|
330 mike 1.32 }
331
|
332 mike 1.35
|
333 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
334 mike 1.32 // MAIN
335 //////////////////////////////////////////////////////////////////////////
336 int main(int argc, char** argv)
337 {
|
338 mike 1.35 String pegasusHome = String::EMPTY;
339 Boolean pegasusIOLog = false;
|
340 kumpf 1.53 String httpPort = String::EMPTY;
341 String httpsPort = String::EMPTY;
|
342 mike 1.35 String logsDirectory = String::EMPTY;
343 Boolean useSLP = false;
344 Boolean useSSL = false;
345 Boolean daemonOption = false;
346 Boolean shutdownOption = false;
347 Boolean timeoutOption = false;
348 String timeoutStr = String::EMPTY;
349 long timeoutValue = 0;
|
350 mday 1.47
|
351 kumpf 1.38 //
352 // Get environment variables:
353 //
354 const char* tmp = getenv("PEGASUS_HOME");
355
356 if (tmp)
357 {
358 pegasusHome = tmp;
359 }
360
361 FileSystem::translateSlashes(pegasusHome);
362
|
363 mike 1.32 // on Windows NT if there are no command-line options, run as a service
364
365 if (argc == 1 )
|
366 mike 1.35 {
367 cim_server_service(argc, argv);
368 }
369 else
370 {
371 // Get help, version and home options
372
373 for (int i = 1; i < argc; )
374 {
375 const char* arg = argv[i];
376
377 // Check for -option
378 if (*arg == '-')
379 {
380 // Get the option
381 const char* option = arg + 1;
382
383 //
384 // Check to see if user asked for the version (-v option):
385 //
386 if (*option == OPTION_VERSION)
387 mike 1.35 {
388 cout << PEGASUS_VERSION << endl;
389 exit(0);
390 }
391 //
392 // Check to see if user asked for help (-h option):
393 //
394 else if (*option == OPTION_HELP)
395 {
396 PrintHelp(argv[0]);
397 exit(0);
398 }
399 else if (*option == OPTION_HOME)
400 {
401 if (i + 1 < argc)
402 {
403 pegasusHome.assign(argv[i + 1]);
404 }
405 else
406 {
407 cout << "Missing argument for option -" << option << endl;
408 mike 1.35 exit(0);
409 }
410
411 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
412 argc -= 2;
413 }
|
414 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
415 //
|
416 kumpf 1.49 // Check to see if user asked for the version (-X option):
|
417 kumpf 1.48 //
418 if (*option == OPTION_BINDVERBOSE)
419 {
420 System::bindVerbose = true;
421 cout << "Unsupported debug option, BIND_VERBOSE, enabled."
422 << endl;
423 // remove the option from the command line
424 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
425 argc--;
426 }
427 #endif
|
428 mike 1.35 //
429 // Check to see if user asked for shutdown (-s option):
430 //
431 else if (*option == OPTION_SHUTDOWN)
432 {
|
433 kumpf 1.52
|
434 mike 1.35 //
|
435 kumpf 1.52 // check to see if user is root
|
436 mike 1.35 //
|
437 kumpf 1.55 if (!System::isPrivilegedUser(System::getEffectiveUserName()))
|
438 mike 1.35 {
|
439 kumpf 1.52 cout << "You must have superuser privilege to run ";
440 cout << "cimserver." << endl;
|
441 mike 1.35 exit(0);
442 }
443
444 //
|
445 kumpf 1.52 // Check to see if shutdown has already been specified:
|
446 mike 1.35 //
|
447 kumpf 1.52 if (shutdownOption)
|
448 mike 1.35 {
|
449 kumpf 1.52 cout << "Duplicate shutdown option specified." << endl;
|
450 mike 1.35 exit(0);
451 }
452
|
453 kumpf 1.52 shutdownOption = true;
|
454 mike 1.35
455 // remove the option from the command line
456 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
457 argc--;
458 }
459 else if (*option == OPTION_TIMEOUT)
460 {
461 //
462 // Check to see if shutdown has been specified:
463 //
464 if (!shutdownOption)
465 {
466 cout << "Invalid option -" << option << endl;
467 exit(0);
468 }
469
470 if (timeoutOption)
471 {
472 cout << "Duplicate timeout option specified." << endl;
473 exit(0);
474 }
475 mike 1.35
476 timeoutOption = true;
477
478 if (i + 1 < argc)
479 {
480 // get timeout value
481 timeoutStr.assign(argv[i + 1]);
482
483 // validate timeout value string
484 char* tmp = timeoutStr.allocateCString();
485 char* end = 0;
486 timeoutValue = strtol(tmp, &end, 10);
487
488 if (!end || *end != '\0')
489 {
490 cout << "invalid timeout value specified: ";
491 cout << timeoutStr << endl;
492 delete [] tmp;
493 exit(0);
494 }
495 }
496 mike 1.35 else
497 {
498 cout << "Missing argument for option -";
499 cout << option << endl;
500 exit(0);
501 }
502
503 // remove the option from the command line
504 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
505 argc -= 2;
506 }
507 else
508 i++;
509 }
510 else
511 i++;
|
512 mike 1.32 }
513 }
|
514 mike 1.35
|
515 kumpf 1.38 //
516 // Set the value for pegasusHome property
517 //
518 ConfigManager::setPegasusHome(pegasusHome);
|
519 mike 1.32
|
520 mike 1.35 //
521 // Get an instance of the Config Manager.
522 //
523 configManager = ConfigManager::getInstance();
524
525 //
|
526 mike 1.32 // Get options (from command line and from configuration file); this
|
527 mike 1.35 // removes corresponding options and their arguments from the command
|
528 mike 1.32 // line.
|
529 mike 1.35 //
|
530 mike 1.32 try
531 {
|
532 mike 1.35 GetOptions(configManager, argc, argv, pegasusHome);
|
533 mike 1.32 }
534 catch (Exception& e)
535 {
|
536 mike 1.35 cerr << argv[0] << ": " << e.getMessage() << endl;
537 exit(1);
|
538 mike 1.32 }
539
540
|
541 mike 1.35 try
|
542 mike 1.32 {
|
543 mike 1.35 //
544 // Check to see if we should (can) install as a NT service
545 //
546
547 if (String::equal(configManager->getCurrentValue("install"), "true"))
548 {
549 if( 0 != cimserver_install_nt_service( pegasusHome ))
550 {
551 cout << "\nPegasus installed as NT Service";
552 exit(0);
553 }
554 }
|
555 mike 1.32
|
556 mike 1.35 //
557 // Check to see if we should (can) remove Pegasus as an NT service
558 //
559
560 if (String::equal(configManager->getCurrentValue("remove"), "true"))
561 {
562 if( 0 != cimserver_remove_nt_service() )
563 {
564 cout << "\nPegasus removed as NT Service";
565 exit(0);
566 }
567 }
|
568 mike 1.32
|
569 mike 1.35 //
570 // Check to see if we should Pegasus as a daemon
571 //
572
573 if (String::equal(configManager->getCurrentValue("daemon"), "true"))
574 {
575 daemonOption = true;
576 }
|
577 mike 1.32
|
578 mike 1.35 //
|
579 kumpf 1.36 // Check the log trace options and set global variable
580 //
581
582 if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
583 {
584 pegasusIOLog = true;
585 }
586
587 // Get the log file directory definition.
588 // We put String into Cstring because
589 // Directory functions only handle Cstring.
590 // ATTN-KS: create String based directory functions.
591
592 logsDirectory = configManager->getCurrentValue("logdir");
|
593 kumpf 1.38 logsDirectory =
594 ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
|
595 kumpf 1.36
596 // Set up the Logger. This does not open the logs
597 // Might be more logical to clean before set.
598 // ATTN: Need tool to completely disable logging.
599
|
600 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
|
601 kumpf 1.36 Logger::setHomeDirectory(logsDirectory);
|
602 kumpf 1.57 #endif
|
603 kumpf 1.36
604 //
|
605 mike 1.35 // Check to see if we need to shutdown CIMOM
606 //
607 if (shutdownOption)
608 {
609 //
610 // if timeout was specified, validate the timeout value
611 //
612 if (timeoutOption)
613 {
614 Boolean valid = configManager->validatePropertyValue(
615 PROPERTY_TIMEOUT,
616 timeoutStr);
617 if (!valid)
618 {
619 cout << "Invalid timeout value specified: " << timeoutValue;
620 cout << endl;
621 exit(1);
622 }
623 }
624
|
625 kumpf 1.52 shutdownCIMOM(timeoutValue);
|
626 kumpf 1.45
|
627 kumpf 1.54 cout << "Pegasus CIM Server stopped." << endl;
|
628 mike 1.35 exit(0);
629 }
|
630 mike 1.32
|
631 mike 1.35 //
|
632 kumpf 1.53 // Get the port numbers
|
633 mike 1.35 //
634
|
635 kumpf 1.53 httpPort = configManager->getCurrentValue("httpPort");
636
637 httpsPort = configManager->getCurrentValue("httpsPort");
|
638 mike 1.35
|
639 kumpf 1.36 // Leave this in until people get familiar with the logs.
|
640 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
|
641 kumpf 1.36 cout << "Logs Directory = " << logsDirectory << endl;
|
642 kumpf 1.57 #endif
|
643 mike 1.35
644 if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
645 {
646 Logger::clean(logsDirectory);;
647 }
|
648 mike 1.32
|
649 mike 1.35 if (String::equal(configManager->getCurrentValue("slp"), "true"))
650 {
651 useSLP = true;
652 }
|
653 mike 1.32
|
654 mike 1.35 if (String::equal(configManager->getCurrentValue("SSL"), "true"))
655 {
656 useSSL = true;
657 }
|
658 mike 1.32 }
|
659 mike 1.35 catch (UnrecognizedConfigProperty e)
|
660 mike 1.32 {
|
661 mike 1.35 cout << "Error: " << e.getMessage() << endl;
|
662 mike 1.32 }
663
|
664 kumpf 1.53 Uint32 portNumber;
665
666 char address[32];
667
668 if (useSSL)
669 {
670 char* p = httpsPort.allocateCString();
671 char* end = 0;
672 Uint32 port = strtol(p, &end, 10);
673 assert(end != 0 && *end == '\0');
674 delete [] p;
675
676 //
677 // Look up the WBEM-HTTPS port number
678 //
679 portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
680 sprintf(address, "%u", portNumber);
681 }
682 else
683 {
684 char* p = httpPort.allocateCString();
685 kumpf 1.53 char* end = 0;
686 Uint32 port = strtol(p, &end, 10);
687 assert(end != 0 && *end == '\0');
688 delete [] p;
689
690 //
691 // Look up the WBEM-HTTP port number
692 //
693 portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
694 sprintf(address, "%u", portNumber);
695 }
|
696 mike 1.32
697 // Put out startup up message.
698 cout << PEGASUS_NAME << PEGASUS_VERSION <<
699 " on port " << address << endl;
700 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
|
701 kumpf 1.54 cout <<"Starting..."
|
702 mike 1.32 << (pegasusIOLog ? " Tracing to Log ": " ")
703 << (useSLP ? " SLP reg. " : " No SLP ")
|
704 mike 1.35 << (useSSL ? " Use SSL " : " No SSL ")
|
705 mike 1.32 << endl;
706
|
707 kumpf 1.51 // do we need to run as a daemon ?
708 if (daemonOption)
709 {
710 if(-1 == cimserver_fork())
711 exit(-1);
712 }
713
|
714 mike 1.32 // try loop to bind the address, and run the server
715 try
716 {
|
717 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
|
718 mike 1.32 slp_client *discovery = new slp_client() ;;
719 String serviceURL;
720 serviceURL.assign("service:cim.pegasus://");
721 String host_name = slp_get_host_name();
722 serviceURL += host_name;
723 serviceURL += ":";
724 serviceURL += address;
725 char *url = serviceURL.allocateCString();
726 // free(host_name);
|
727 mike 1.35 #endif
|
728 mike 1.32
|
729 mike 1.35 Monitor monitor;
|
730 kumpf 1.38 CIMServer server(&monitor, useSSL);
|
731 kumpf 1.41
732 // bind throws an exception if the bind fails
733 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
734 cout << "Binding to domain socket" << endl;
735 #else
|
736 mike 1.33 cout << "Binding to " << address << endl;
|
737 kumpf 1.41 #endif
|
738 mike 1.35
739 server.bind(portNumber);
|
740 mike 1.32
741 time_t last = 0;
|
742 mike 1.35
|
743 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
744 //
|
745 kumpf 1.56 // create a file to indicate that the cimserver has started and
746 // save the process id of the cimserver process in the file
|
747 kumpf 1.45 //
|
748 kumpf 1.56
749 // remove the old file if it exists
750 System::removeFile(fname);
751
752 // open the file
753 FILE *pid_file = fopen(fname, "w");
754 if (pid_file)
|
755 kumpf 1.45 {
|
756 kumpf 1.56 // save the pid in the file
757 fprintf(pid_file, "%ld\n", (long)server_pid);
758 fclose(pid_file);
|
759 kumpf 1.45 }
760 #endif
|
761 kumpf 1.54 cout << "Started. " << endl;
762
763 // Put server started message to the logger
764 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
765 kumpf 1.57 "Started $0 version $1 on port $2.",
766 PEGASUS_NAME, PEGASUS_VERSION, address);
767
|
768 kumpf 1.45
|
769 mike 1.35 //
770 // Loop to call CIMServer's runForever() method until CIMServer
771 // has been shutdown
772 //
773 while( !server.terminated() )
|
774 mike 1.32 {
|
775 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
|
776 mike 1.32 if(useSLP )
777 {
778 if( (time(NULL) - last ) > 60 )
779 {
780 if( discovery != NULL && url != NULL )
781 discovery->srv_reg_all(url,
|
782 mike 1.35 "(namespace=root/cimv2)",
|
783 mike 1.32 "service:cim.pegasus",
784 "DEFAULT",
785 70) ;
786 time(&last);
787 }
788
789 discovery->service_listener();
790 }
|
791 mike 1.35 #endif
|
792 mike 1.32 server.runForever();
793 }
794
|
795 kumpf 1.45 //
796 // normal termination
|
797 mike 1.34 //
|
798 kumpf 1.54 // Put server shutdown message to the logger
799 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
800 "$0 stopped.", PEGASUS_NAME);
|
801 kumpf 1.45
802 #if defined(PEGASUS_OS_HPUX)
803 //
|
804 kumpf 1.56 // close the file created at startup time to indicate that the
805 // cimserver has terminated normally.
|
806 kumpf 1.45 //
807 FileSystem::removeFile(CIMSERVERSTART_FILE);
808 #endif
|
809 mike 1.32 }
810 catch(Exception& e)
811 {
812 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
813 kumpf 1.58 "$0. Abnormal Termination.", e.getMessage());
|
814 mike 1.32
815 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
816 kumpf 1.54 return 1;
|
817 mike 1.32 }
818
819 return 0;
820 }
|