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