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