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