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