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.74 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
|
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.52
|
249 mday 1.79.2.1 // use the local port only.
250 String addr("127.0.0.1:");
251 if (String::equal(configManager->getCurrentValue("SSL"), "true"))
252 {
253 addr.append(configManager->getCurrentValue("httpsPort"));
254 }
255 else
256 {
257 addr.append(configManager->getCurrentValue("httpPort"));
258 }
259
260 // use localPrivilegedOnly instead
261 client.connect(addr);
262
263 }
264 catch(Exception &)
265 {
266 try
267 {
268 client.connectLocal();
269 }
270 mday 1.79.2.1
271 catch(Exception& e)
272 {
273 PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
274 PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
|
275 chuck 1.66 #ifdef PEGASUS_OS_OS400
|
276 mday 1.79.2.1 // The server job may still be active but not responding.
277 // Kill the job if it exists.
278 cimserver_kill();
|
279 chuck 1.66 #endif
|
280 mday 1.79.2.1 exit(0);
281 }
|
282 mike 1.35 }
|
283 mday 1.79.2.1 client.setTimeout(2000);
|
284 mike 1.35
285 try
286 {
287 //
|
288 kumpf 1.52 // construct CIMObjectPath
|
289 mike 1.35 //
|
290 mday 1.79.2.2 String referenceStr;
|
291 mike 1.35 referenceStr.append(hostStr);
|
292 chuck 1.70 referenceStr.append("/");
|
293 kumpf 1.72 referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
|
294 kumpf 1.53 referenceStr.append(":");
|
295 kumpf 1.72 referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
|
296 kumpf 1.50 CIMObjectPath reference(referenceStr);
|
297 mike 1.35
298 //
299 // issue the invokeMethod request on the shutdown method
300 //
301 Array<CIMParamValue> inParams;
302 Array<CIMParamValue> outParams;
303
|
304 kumpf 1.52 // set force option to true for now
|
305 kumpf 1.40 inParams.append(CIMParamValue("force",
|
306 kumpf 1.52 CIMValue(Boolean(true))));
|
307 mike 1.35
|
308 kumpf 1.40 inParams.append(CIMParamValue("timeout",
|
309 kumpf 1.39 CIMValue(Uint32(timeoutValue))));
|
310 mike 1.35
311 CIMValue retValue = client.invokeMethod(
|
312 kumpf 1.59 PEGASUS_NAMESPACENAME_SHUTDOWN,
|
313 mike 1.35 reference,
314 "shutdown",
315 inParams,
316 outParams);
|
317 kumpf 1.43 }
|
318 kumpf 1.65 catch(CIMException& e)
|
319 kumpf 1.46 {
320 PEGASUS_STD(cerr) << "Failed to shutdown server: ";
|
321 kumpf 1.63 if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
322 {
323 PEGASUS_STD(cerr) << "The repository may be empty.";
324 PEGASUS_STD(cerr) << PEGASUS_STD(endl);
325 }
326 else
327 {
328 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
329 }
|
330 chuck 1.66 #ifdef PEGASUS_OS_OS400
331 // Kill the server job.
332 cimserver_kill();
333 #endif
|
334 kumpf 1.46 exit(1);
335 }
|
336 kumpf 1.65 catch(Exception& e)
|
337 kumpf 1.45 {
338 //
|
339 kumpf 1.54 // This may mean the CIM Server has been terminated and returns a
340 // "Empty HTTP response message" HTTP error response. To be sure
341 // CIM Server gets shutdown, if CIM Server is still running at
342 // this time, we will kill the cimserver process.
|
343 kumpf 1.45 //
|
344 kumpf 1.56 // give CIM Server some time to finish up
345 //
|
346 kumpf 1.63 //System::sleep(1);
347 //cimserver_kill();
348
349 //
350 // Check to see if CIMServer is still running. If CIMServer
351 // is still running and the shutdown timeout has not expired,
352 // loop and wait one second until either CIM Server is
353 // terminated or until timeout expires. If timeout expires
354 // and CIMServer is still running, kill the CIMServer
355 // process.
356 //
357 Uint32 maxWaitTime = timeoutValue - 2;
358 Boolean running = isCIMServerRunning();
359 while ( running && maxWaitTime > 0 )
360 {
361 System::sleep(1);
362 running = isCIMServerRunning();
363 maxWaitTime = maxWaitTime - 1;
364 }
365
366 if (running)
367 kumpf 1.63 {
368 cimserver_kill();
369 }
|
370 kumpf 1.43 }
|
371 kumpf 1.65 //catch(Exception& e)
372 //{
373 // PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: ";
374 // PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
375 // exit(1);
376 //}
|
377 mike 1.35
378 return;
|
379 mike 1.32 }
380
|
381 mike 1.35
|
382 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
383 mike 1.32 // MAIN
384 //////////////////////////////////////////////////////////////////////////
385 int main(int argc, char** argv)
386 {
|
387 mike 1.35 String pegasusHome = String::EMPTY;
388 Boolean pegasusIOLog = false;
|
389 kumpf 1.53 String httpPort = String::EMPTY;
390 String httpsPort = String::EMPTY;
|
391 mike 1.35 String logsDirectory = String::EMPTY;
392 Boolean useSLP = false;
393 Boolean useSSL = false;
394 Boolean daemonOption = false;
395 Boolean shutdownOption = false;
|
396 kumpf 1.60 Uint32 timeoutValue = 0;
|
397 mday 1.47
|
398 chuck 1.66 #ifdef PEGASUS_OS_OS400
399 // Initialize Pegasus home to the shipped OS/400 directory.
400 pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
401 #endif
402
|
403 kumpf 1.38 //
404 // Get environment variables:
405 //
406 const char* tmp = getenv("PEGASUS_HOME");
407
408 if (tmp)
409 {
410 pegasusHome = tmp;
411 }
412
413 FileSystem::translateSlashes(pegasusHome);
414
|
415 mike 1.32 // on Windows NT if there are no command-line options, run as a service
416
417 if (argc == 1 )
|
418 mike 1.35 {
419 cim_server_service(argc, argv);
420 }
421 else
422 {
|
423 kumpf 1.60 // Get help, version, and shutdown options
|
424 mike 1.35
425 for (int i = 1; i < argc; )
426 {
427 const char* arg = argv[i];
428
429 // Check for -option
430 if (*arg == '-')
431 {
432 // Get the option
433 const char* option = arg + 1;
434
435 //
436 // Check to see if user asked for the version (-v option):
437 //
438 if (*option == OPTION_VERSION)
439 {
|
440 kumpf 1.63 #if defined(PEGASUS_OS_HPUX)
441 cout << PLATFORM_PRODUCT_VERSION << endl;
442 #else
|
443 mike 1.35 cout << PEGASUS_VERSION << endl;
|
444 kumpf 1.63 #endif
|
445 mike 1.35 exit(0);
446 }
447 //
448 // Check to see if user asked for help (-h option):
449 //
450 else if (*option == OPTION_HELP)
451 {
452 PrintHelp(argv[0]);
453 exit(0);
454 }
|
455 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
|
456 mike 1.35 else if (*option == OPTION_HOME)
457 {
|
458 kumpf 1.60 if (i + 1 < argc)
|
459 mike 1.35 {
460 pegasusHome.assign(argv[i + 1]);
461 }
462 else
463 {
464 cout << "Missing argument for option -" << option << endl;
465 exit(0);
466 }
467
468 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
469 argc -= 2;
470 }
|
471 kumpf 1.63 #endif
|
472 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
473 //
|
474 kumpf 1.49 // Check to see if user asked for the version (-X option):
|
475 kumpf 1.48 //
476 if (*option == OPTION_BINDVERBOSE)
477 {
478 System::bindVerbose = true;
479 cout << "Unsupported debug option, BIND_VERBOSE, enabled."
480 << endl;
481 // remove the option from the command line
482 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
483 argc--;
484 }
485 #endif
|
486 mike 1.35 //
487 // Check to see if user asked for shutdown (-s option):
488 //
489 else if (*option == OPTION_SHUTDOWN)
490 {
491 //
|
492 kumpf 1.52 // check to see if user is root
|
493 mike 1.35 //
|
494 chuck 1.70 #ifndef PEGASUS_OS_OS400
|
495 kumpf 1.55 if (!System::isPrivilegedUser(System::getEffectiveUserName()))
|
496 mike 1.35 {
|
497 kumpf 1.52 cout << "You must have superuser privilege to run ";
498 cout << "cimserver." << endl;
|
499 mike 1.35 exit(0);
500 }
|
501 chuck 1.70 #endif
|
502 mike 1.35
503 //
|
504 kumpf 1.52 // Check to see if shutdown has already been specified:
|
505 mike 1.35 //
|
506 kumpf 1.52 if (shutdownOption)
|
507 mike 1.35 {
|
508 kumpf 1.52 cout << "Duplicate shutdown option specified." << endl;
|
509 mike 1.35 exit(0);
510 }
511
|
512 kumpf 1.52 shutdownOption = true;
|
513 mike 1.35
514 // remove the option from the command line
515 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
516 argc--;
517 }
518 else
519 i++;
520 }
521 else
522 i++;
|
523 mike 1.32 }
524 }
|
525 mike 1.35
|
526 kumpf 1.38 //
527 // Set the value for pegasusHome property
528 //
529 ConfigManager::setPegasusHome(pegasusHome);
|
530 mike 1.32
|
531 mike 1.35 //
532 // Get an instance of the Config Manager.
533 //
534 configManager = ConfigManager::getInstance();
535
536 //
|
537 mike 1.32 // Get options (from command line and from configuration file); this
|
538 mike 1.35 // removes corresponding options and their arguments from the command
|
539 mike 1.32 // line.
|
540 mike 1.35 //
|
541 mike 1.32 try
542 {
|
543 mike 1.35 GetOptions(configManager, argc, argv, pegasusHome);
|
544 mike 1.32 }
545 catch (Exception& e)
546 {
|
547 mike 1.35 cerr << argv[0] << ": " << e.getMessage() << endl;
548 exit(1);
|
549 mike 1.32 }
550
|
551 mike 1.35 try
|
552 mike 1.32 {
|
553 mike 1.35 //
554 // Check to see if we should (can) install as a NT service
555 //
556
557 if (String::equal(configManager->getCurrentValue("install"), "true"))
558 {
559 if( 0 != cimserver_install_nt_service( pegasusHome ))
560 {
561 cout << "\nPegasus installed as NT Service";
562 exit(0);
563 }
564 }
|
565 mike 1.32
|
566 mike 1.35 //
567 // Check to see if we should (can) remove Pegasus as an NT service
568 //
569
570 if (String::equal(configManager->getCurrentValue("remove"), "true"))
571 {
572 if( 0 != cimserver_remove_nt_service() )
573 {
574 cout << "\nPegasus removed as NT Service";
575 exit(0);
576 }
577 }
|
578 mike 1.32
|
579 mike 1.35 //
580 // Check to see if we should Pegasus as a daemon
581 //
582
583 if (String::equal(configManager->getCurrentValue("daemon"), "true"))
584 {
585 daemonOption = true;
586 }
|
587 mday 1.62
|
588 mike 1.35 //
|
589 kumpf 1.36 // Check the log trace options and set global variable
590 //
591
592 if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
593 {
594 pegasusIOLog = true;
595 }
596
597 // Get the log file directory definition.
598 // We put String into Cstring because
599 // Directory functions only handle Cstring.
600 // ATTN-KS: create String based directory functions.
601
602 logsDirectory = configManager->getCurrentValue("logdir");
|
603 kumpf 1.38 logsDirectory =
604 ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
|
605 kumpf 1.36
606 // Set up the Logger. This does not open the logs
607 // Might be more logical to clean before set.
608 // ATTN: Need tool to completely disable logging.
609
|
610 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
|
611 kumpf 1.36 Logger::setHomeDirectory(logsDirectory);
|
612 kumpf 1.57 #endif
|
613 kumpf 1.36
614 //
|
615 mike 1.35 // Check to see if we need to shutdown CIMOM
616 //
617 if (shutdownOption)
618 {
|
619 kumpf 1.60 String configTimeout =
620 configManager->getCurrentValue("shutdownTimeout");
|
621 kumpf 1.69 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
|
622 kumpf 1.60
|
623 kumpf 1.52 shutdownCIMOM(timeoutValue);
|
624 kumpf 1.45
|
625 kumpf 1.60 cout << "CIM Server stopped." << endl;
|
626 mike 1.35 exit(0);
627 }
|
628 mike 1.32
|
629 mike 1.35 //
|
630 kumpf 1.53 // Get the port numbers
|
631 mike 1.35 //
632
|
633 kumpf 1.53 httpPort = configManager->getCurrentValue("httpPort");
634
635 httpsPort = configManager->getCurrentValue("httpsPort");
|
636 mike 1.35
|
637 kumpf 1.36 // Leave this in until people get familiar with the logs.
|
638 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
|
639 kumpf 1.36 cout << "Logs Directory = " << logsDirectory << endl;
|
640 kumpf 1.57 #endif
|
641 mike 1.35
642 if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
643 {
644 Logger::clean(logsDirectory);;
645 }
|
646 mike 1.32
|
647 mike 1.35 if (String::equal(configManager->getCurrentValue("slp"), "true"))
648 {
649 useSLP = true;
650 }
|
651 mike 1.32
|
652 kumpf 1.78 #if defined(PEGASUS_USE_RELEASE_CONFIG_OPTIONS)
653 Boolean enableHttpConnection = String::equal(
654 configManager->getCurrentValue("enableHttpConnection"), "true");
655 Boolean enableHttpsConnection = String::equal(
656 configManager->getCurrentValue("enableHttpsConnection"), "true");
657
658 if (enableHttpConnection && enableHttpsConnection)
659 {
660 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
661 "Enabling both HTTP and HTTPS connections is unsupported. "
662 "Only the HTTPS connection is enabled.");
663 cerr << "Enabling both HTTP and HTTPS connections is unsupported. "
664 "Only the HTTPS connection is enabled." << endl;
665 }
666 else if (!enableHttpConnection && !enableHttpsConnection)
667 {
668 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
669 "Neither HTTP nor HTTPS connection is enabled. "
670 "CIMServer will not be started.");
671 cerr << "Neither HTTP nor HTTPS connection is enabled. "
672 "CIMServer will not be started." << endl;
673 kumpf 1.78 exit(1);
674 }
675
676 useSSL = enableHttpsConnection;
677
678 #else
|
679 mike 1.35 if (String::equal(configManager->getCurrentValue("SSL"), "true"))
680 {
681 useSSL = true;
682 }
|
683 kumpf 1.78 #endif
|
684 mike 1.32 }
|
685 mike 1.35 catch (UnrecognizedConfigProperty e)
|
686 mike 1.32 {
|
687 mike 1.35 cout << "Error: " << e.getMessage() << endl;
|
688 mike 1.32 }
689
|
690 kumpf 1.53 Uint32 portNumber;
691
692 char address[32];
693
694 if (useSSL)
695 {
696 char* end = 0;
|
697 kumpf 1.69 CString portString = httpsPort.getCString();
698 Uint32 port = strtol(portString, &end, 10);
|
699 kumpf 1.53 assert(end != 0 && *end == '\0');
700
701 //
702 // Look up the WBEM-HTTPS port number
703 //
704 portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
705 sprintf(address, "%u", portNumber);
706 }
707 else
708 {
709 char* end = 0;
|
710 kumpf 1.69 CString portString = httpPort.getCString();
711 Uint32 port = strtol(portString, &end, 10);
|
712 kumpf 1.53 assert(end != 0 && *end == '\0');
713
714 //
715 // Look up the WBEM-HTTP port number
716 //
717 portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
718 sprintf(address, "%u", portNumber);
719 }
|
720 mike 1.32
721 // Put out startup up message.
|
722 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
|
723 mike 1.32 cout << PEGASUS_NAME << PEGASUS_VERSION <<
724 " on port " << address << endl;
725 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
|
726 kumpf 1.54 cout <<"Starting..."
|
727 mike 1.32 << (pegasusIOLog ? " Tracing to Log ": " ")
728 << (useSLP ? " SLP reg. " : " No SLP ")
|
729 mike 1.35 << (useSSL ? " Use SSL " : " No SSL ")
|
730 mike 1.32 << endl;
|
731 kumpf 1.63 #endif
|
732 mike 1.32
|
733 kumpf 1.63 // do we need to run as a daemon ?
734 if (daemonOption)
735 {
736 if(-1 == cimserver_fork())
737 exit(-1);
738 }
|
739 chuck 1.66
740 #ifdef PEGASUS_OS_OS400
741 // Special server initialization code for OS/400.
742 if (cimserver_initialize() != 0)
743 {
744 // do some logging here!
745 exit(-1);
746 }
747 #endif
|
748 mday 1.62
|
749 kumpf 1.63 #ifdef PEGASUS_OS_HPUX
750 umask(S_IWGRP|S_IWOTH);
|
751 kumpf 1.79
752 //
753 // check if CIMServer is already running
754 // if CIMServer is already running, print message and
755 // notify parent process (if there is a parent process) to terminate
756 //
757 if(isCIMServerRunning())
758 {
759 cout << "Unable to start CIMServer." << endl;
760 cout << "CIMServer is already running." << endl;
761
762 //
763 // notify parent process (if there is a parent process) to terminate
764 //
765 if (daemonOption)
766 notify_parent();
767
768 exit(1);
769 }
770
|
771 kumpf 1.63 #endif
|
772 kumpf 1.51
|
773 mike 1.32 // try loop to bind the address, and run the server
774 try
775 {
|
776 kumpf 1.75 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
|
777 mike 1.32 slp_client *discovery = new slp_client() ;;
778 String serviceURL;
779 serviceURL.assign("service:cim.pegasus://");
780 String host_name = slp_get_host_name();
|
781 kumpf 1.67 serviceURL.append(host_name);
782 serviceURL.append(":");
783 serviceURL.append(address);
|
784 mike 1.35 #endif
|
785 mike 1.32
|
786 mday 1.61 Monitor monitor(true);
|
787 kumpf 1.38 CIMServer server(&monitor, useSSL);
|
788 kumpf 1.41
789 // bind throws an exception if the bind fails
790 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
791 cout << "Binding to domain socket" << endl;
|
792 kumpf 1.63 #elif !defined(PEGASUS_OS_HPUX)
|
793 mike 1.33 cout << "Binding to " << address << endl;
|
794 kumpf 1.41 #endif
|
795 mike 1.35
796 server.bind(portNumber);
|
797 kumpf 1.73
|
798 dan 1.76 // notify parent process (if there is a parent process) to terminate
799 // so user knows that cimserver is ready to serve CIM requests.
800 if (daemonOption)
801 notify_parent();
|
802 mike 1.32
803 time_t last = 0;
|
804 mike 1.35
|
805 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
806 //
|
807 kumpf 1.56 // create a file to indicate that the cimserver has started and
808 // save the process id of the cimserver process in the file
|
809 kumpf 1.45 //
|
810 kumpf 1.56
811 // remove the old file if it exists
812 System::removeFile(fname);
813
814 // open the file
815 FILE *pid_file = fopen(fname, "w");
816 if (pid_file)
|
817 kumpf 1.45 {
|
818 kumpf 1.56 // save the pid in the file
819 fprintf(pid_file, "%ld\n", (long)server_pid);
820 fclose(pid_file);
|
821 kumpf 1.45 }
822 #endif
|
823 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
|
824 kumpf 1.54 cout << "Started. " << endl;
|
825 kumpf 1.63 #endif
|
826 kumpf 1.54
827 // Put server started message to the logger
|
828 kumpf 1.63 #ifdef PEGASUS_OS_HPUX
829 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
830 "Started $0 version $1 on port $2.",
831 PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION, address);
832 #else
|
833 kumpf 1.54 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
834 kumpf 1.57 "Started $0 version $1 on port $2.",
835 PEGASUS_NAME, PEGASUS_VERSION, address);
|
836 kumpf 1.63 #endif
|
837 kumpf 1.45
|
838 mday 1.62
|
839 mike 1.35 //
840 // Loop to call CIMServer's runForever() method until CIMServer
841 // has been shutdown
842 //
843 while( !server.terminated() )
|
844 mike 1.32 {
|
845 kumpf 1.75 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
|
846 mike 1.32 if(useSLP )
847 {
848 if( (time(NULL) - last ) > 60 )
849 {
|
850 kumpf 1.69 if( discovery != NULL && serviceURL.size() )
851 discovery->srv_reg_all(serviceURL.getCString(),
|
852 mike 1.35 "(namespace=root/cimv2)",
|
853 mike 1.32 "service:cim.pegasus",
854 "DEFAULT",
855 70) ;
856 time(&last);
857 }
858
859 discovery->service_listener();
860 }
|
861 mike 1.35 #endif
|
862 mike 1.32 server.runForever();
863 }
864
|
865 kumpf 1.45 //
866 // normal termination
|
867 mike 1.34 //
|
868 kumpf 1.54 // Put server shutdown message to the logger
869 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
870 "$0 stopped.", PEGASUS_NAME);
|
871 kumpf 1.45
872 #if defined(PEGASUS_OS_HPUX)
873 //
|
874 kumpf 1.56 // close the file created at startup time to indicate that the
875 // cimserver has terminated normally.
|
876 kumpf 1.45 //
877 FileSystem::removeFile(CIMSERVERSTART_FILE);
878 #endif
|
879 mike 1.32 }
880 catch(Exception& e)
881 {
882 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
883 kumpf 1.77
884 //
885 // notify parent process (if there is a parent process) to terminate
886 //
887 if (daemonOption)
888 notify_parent();
889
|
890 kumpf 1.54 return 1;
|
891 mike 1.32 }
|
892 mday 1.79.2.1 #if defined(PEGASUS_OS_TYPE_UNIX)
893 kill(getpid(), SIGKILL);
894 #endif
895 #if defined(PEGASUS_OS_TYPE_WINDOWS)
896 ExitProcess(0);
897 #endif
898 _exit(1);
|
899 mike 1.32 return 0;
900 }
|