1 karl 1.4 //%2003////////////////////////////////////////////////////////////////////////
|
2 kumpf 1.1 //
|
3 karl 1.4 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
|
7 kumpf 1.1 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Mike Brasher (mbrasher@bmc.com)
27 //
28 kumpf 1.1 // Modified By: Mike Day (mdday@us.ibm.com)
29 //
30 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
31 //
32 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
33 //
34 // Modified By: Jenny Yu (jenny_yu@hp.com)
35 //
36 // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
|
37 kumpf 1.2 // Carol Ann Krug Graves, Hewlett-Packard Company
38 // (carolann_graves@hp.com)
39 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
|
40 kumpf 1.1 //
|
41 kumpf 1.3 // Modified By: Dave Rosckes (rosckes@us.ibm.com)
42 //
43 // Modified By: Humberto Rivero (hurivero@us.ibm.com)
44 //
45 // Modified By: Jair Santos, Hewlett-Packard Company (jair.santos@hp.com)
46 //
|
47 kumpf 1.1 //%/////////////////////////////////////////////////////////////////////////////
48
49
50 //////////////////////////////////////////////////////////////////////
51 //
52 // Notes on deamon operation (Unix) and service operation (Win 32):
53 //
54 // To run pegasus as a daemon on Unix platforms:
55 //
56 // cimserver
57 //
58 // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
59 // property to false:
60 //
61 // cimserver daemon=false
62 //
63 // The daemon config property has no effect on windows operation.
64 //
65 // To shutdown pegasus, use the -s option:
66 //
67 // cimserver -s
68 kumpf 1.1 //
69 // To run pegasus as an NT service, there are FOUR different possibilities:
70 //
71 // To INSTALL the Pegasus service,
72 //
73 // cimserver -install
74 //
75 // To REMOVE the Pegasus service,
76 //
77 // cimserver -remove
78 //
79 // To START the Pegasus service,
80 //
81 // net start cimserver
82 //
83 // To STOP the Pegasus service,
84 //
85 // net stop cimserver
86 //
87 // Alternatively, you can use the windows service manager. Pegasus shows up
88 // in the service database as "Pegasus CIM Object Manager"
89 kumpf 1.1 //
90 // Mike Day, mdday@us.ibm.com
91 //
92 //////////////////////////////////////////////////////////////////////
93
94
95 #include <Pegasus/Common/Config.h>
96 #include <Pegasus/Common/Constants.h>
97 #include <iostream>
98 #include <cassert>
99 #include <cstdlib>
100 #include <fstream>
101 #include <Pegasus/Common/FileSystem.h>
102 #include <Pegasus/Common/Monitor.h>
103 #include <WMIMapper/PegServer/CIMServer.h>
104 #include <Pegasus/Common/PegasusVersion.h>
105 #include <Pegasus/Common/Logger.h>
106 #include <Pegasus/Common/System.h>
107 #include <Pegasus/Common/Tracer.h>
108 #include <Pegasus/Config/ConfigManager.h>
109 #include <Pegasus/Client/CIMClient.h>
110 kumpf 1.1 #include <Pegasus/Server/ShutdownService.h>
111 #include <Pegasus/Common/Destroyer.h>
112
|
113 kumpf 1.3
|
114 kumpf 1.1 #if defined(PEGASUS_OS_TYPE_WINDOWS)
115 # include "cimserver_windows.cpp"
116 #elif defined(PEGASUS_OS_TYPE_UNIX)
117 # if defined(PEGASUS_OS_OS400)
118 # include "cimserver_os400.cpp"
119 # else
120 # include "cimserver_unix.cpp"
121 #endif
122 #else
123 # error "Unsupported platform"
124 #endif
125
126 PEGASUS_USING_PEGASUS;
127 PEGASUS_USING_STD;
128
129 //
130 // The command name.
131 //
132 static const char COMMAND_NAME [] = "cimserver";
133
134 //
135 kumpf 1.1 // The constant defining usage string.
136 //
137 static const char USAGE [] = "Usage: ";
138
139 /**
140 Constants representing the command line options.
141 */
142 static const char OPTION_VERSION = 'v';
143
144 static const char OPTION_HELP = 'h';
145
146 static const char OPTION_HOME = 'D';
147
148 static const char OPTION_SHUTDOWN = 's';
149
|
150 kumpf 1.3 static const char OPTION_INSTALL[] = "install";
151
152 static const char OPTION_REMOVE[] = "remove";
153
154 static const char OPTION_START[] = "start";
155
156 static const char OPTION_STOP[] = "stop";
157
|
158 kumpf 1.1 #if defined(PEGASUS_OS_HPUX)
159 static const char OPTION_BINDVERBOSE = 'X';
160 #endif
161
162 static const String PROPERTY_TIMEOUT = "shutdownTimeout";
163
164 ConfigManager* configManager;
165
166 /** GetOptions function - This function defines the Options Table
167 and sets up the options from that table using the config manager.
168 */
169 void GetOptions(
170 ConfigManager* cm,
171 int& argc,
172 char** argv,
173 const String& pegasusHome)
174 {
175 try
176 {
177 cm->mergeConfigFiles();
178
179 kumpf 1.1 cm->mergeCommandLine(argc, argv);
180 }
|
181 kumpf 1.5 catch (NoSuchFile&)
|
182 kumpf 1.1 {
|
183 kumpf 1.5 throw;
|
184 kumpf 1.1 }
|
185 kumpf 1.5 catch (FileNotReadable&)
|
186 kumpf 1.1 {
|
187 kumpf 1.5 throw;
|
188 kumpf 1.1 }
|
189 kumpf 1.5 catch (CannotRenameFile&)
|
190 kumpf 1.1 {
|
191 kumpf 1.5 throw;
|
192 kumpf 1.1 }
|
193 kumpf 1.5 catch (ConfigFileSyntaxError&)
|
194 kumpf 1.1 {
|
195 kumpf 1.5 throw;
|
196 kumpf 1.1 }
|
197 kumpf 1.5 catch(UnrecognizedConfigProperty&)
|
198 kumpf 1.1 {
|
199 kumpf 1.5 throw;
|
200 kumpf 1.1 }
|
201 kumpf 1.5 catch(InvalidPropertyValue&)
|
202 kumpf 1.1 {
|
203 kumpf 1.5 throw;
|
204 kumpf 1.1 }
205 }
206
207 /* PrintHelp - This is temporary until we expand the options manager to allow
208 options help to be defined with the OptionRow entries and presented from
209 those entries.
210 */
211 void PrintHelp(const char* arg0)
212 {
213 /**
214 Build the usage string for the config command.
215 */
216 String usage = String (USAGE);
217 usage.append (COMMAND_NAME);
218 usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
219 usage.append (" options\n");
|
220 kumpf 1.3 usage.append (" -v - displays CIM Server version number\n");
221 usage.append (" -h - prints this help message\n");
222 usage.append (" -s - shuts down CIM Server\n");
|
223 kumpf 1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
224 kumpf 1.3 usage.append (" -D [home] - sets pegasus home directory\n");
|
225 kumpf 1.1 #endif
226 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
227 kumpf 1.3 usage.append (" -install [name] - installs pegasus as a Windows NT Service\n");
228 usage.append (" [name] is optional and overrides the\n");
229 usage.append (" default CIM Server Service Name\n");
230 usage.append (" -remove [name] - removes pegasus as a Windows NT Service\n");
231 usage.append (" [name] is optional and overrides the\n");
232 usage.append (" default CIM Server Service Name\n");
233 usage.append (" -start [name] - starts pegasus as a Windows NT Service\n");
234 usage.append (" [name] is optional and overrides the\n");
235 usage.append (" default CIM Server Service Name\n");
236 usage.append (" -stop [name] - stops pegasus as a Windows NT Service\n");
237 usage.append (" [name] is optional and overrides the\n");
238 usage.append (" default CIM Server Service Name\n\n");
|
239 kumpf 1.1 #endif
240 usage.append (" configProperty=value\n");
|
241 kumpf 1.3 usage.append (" - sets CIM Server configuration property\n");
|
242 kumpf 1.1
243 cout << endl;
|
244 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
245 kumpf 1.1 cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
246 #else
247 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
248 #endif
249 cout << endl;
250 cout << usage << endl;
251 }
252
|
253 kumpf 1.3 //
254 // cimserver_exit: platform specific exit routine calls
255 //
256 void cimserver_exit( int rc ){
257 #ifdef PEGASUS_OS_OS400
258 cimserver_exitRC(rc);
259 #endif
260 exit(rc);
261 }
262
|
263 kumpf 1.1 void shutdownCIMOM(Uint32 timeoutValue)
264 {
265 //
266 // Create CIMClient object
267 //
268 CIMClient client;
269
270 //
271 // Get local host name
272 //
273 String hostStr = System::getHostName();
274
275 //
276 // open connection to CIMOM
277 //
278 try
279 {
280 client.connectLocal();
281
282 //
283 // set client timeout to 2 seconds
284 kumpf 1.1 //
285 client.setTimeout(2000);
286 }
287 catch(Exception& e)
288 {
|
289 kumpf 1.3 #ifdef PEGASUS_OS_OS400
290 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
291 "Unable to connect to CIM Server. CIM Server may not be running." );
292 // The server job may still be active but not responding.
293 // Kill the job if it exists.
294 if(cimserver_kill() == -1)
295 cimserver_exit(2);
296 cimserver_exit(1);
297 #else
|
298 kumpf 1.1 PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
299 PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
300 #endif
|
301 kumpf 1.3 cimserver_exit(1);
|
302 kumpf 1.1 }
303
304 try
305 {
306 //
307 // construct CIMObjectPath
308 //
309 String referenceStr = "//";
310 referenceStr.append(hostStr);
|
311 kumpf 1.2 referenceStr.append("/");
312 referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
|
313 kumpf 1.1 referenceStr.append(":");
|
314 kumpf 1.2 referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
|
315 kumpf 1.1 CIMObjectPath reference(referenceStr);
316
317 //
318 // issue the invokeMethod request on the shutdown method
319 //
320 Array<CIMParamValue> inParams;
321 Array<CIMParamValue> outParams;
322
323 // set force option to true for now
324 inParams.append(CIMParamValue("force",
325 CIMValue(Boolean(true))));
326
327 inParams.append(CIMParamValue("timeout",
328 CIMValue(Uint32(timeoutValue))));
329
330 CIMValue retValue = client.invokeMethod(
331 PEGASUS_NAMESPACENAME_SHUTDOWN,
332 reference,
333 "shutdown",
334 inParams,
335 outParams);
336 kumpf 1.1 }
337 catch(CIMException& e)
338 {
|
339 kumpf 1.3 #ifdef PEGASUS_OS_OS400
340
341 if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
342 {
343 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
344 "Failed to shutdown server: $0", "The repository may be empty.");
345 }
346 else
347 {
348 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
349 "Failed to shutdown server: $0", e.getMessage());
350 }
351 // Kill the server job.
352 if(cimserver_kill() == -1)
353 cimserver_exit(2);
354 #else
|
355 kumpf 1.1 PEGASUS_STD(cerr) << "Failed to shutdown server: ";
356 if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
357 {
358 PEGASUS_STD(cerr) << "The repository may be empty.";
359 PEGASUS_STD(cerr) << PEGASUS_STD(endl);
360 }
361 else
362 {
363 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
364 }
365 #endif
|
366 kumpf 1.3 cimserver_exit(1);
367
|
368 kumpf 1.1 }
369 catch(Exception& e)
370 {
371 //
|
372 kumpf 1.3 // This may mean that the CIM Server has terminated, causing this
373 // client to get a "Empty HTTP response message" exception. It may
374 // also mean that the CIM Server is taking longer than 2 seconds
375 // (client timeout value) to terminate, causing this client to
376 // timeout with a "connection timeout" exception.
|
377 kumpf 1.1 //
|
378 kumpf 1.3 // Check to see if CIM Server is still running. If CIM Server
|
379 kumpf 1.1 // is still running and the shutdown timeout has not expired,
|
380 kumpf 1.3 // loop and wait one second until either the CIM Server is
381 // terminated or timeout expires. If timeout expires and
382 // the CIM Server is still running, kill the CIMServer process.
383 //
|
384 kumpf 1.1 Uint32 maxWaitTime = timeoutValue - 2;
385 Boolean running = isCIMServerRunning();
386 while ( running && maxWaitTime > 0 )
387 {
388 System::sleep(1);
389 running = isCIMServerRunning();
390 maxWaitTime = maxWaitTime - 1;
391 }
392
393 if (running)
394 {
|
395 kumpf 1.3 int kill_rc = cimserver_kill();
396 #ifdef PEGASUS_OS_OS400
397 if(kill_rc == -1)
398 cimserver_exit(2);
399 cimserver_exit(1);
400 #endif
401
402 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
403 if (kill_rc != -1)
404 {
405 cout << "Shutdown timeout expired. CIM Server process killed." << endl;
406 exit(0);
407 }
408 #endif
|
409 kumpf 1.1 }
410 }
411
412 return;
413 }
414
415
416 /////////////////////////////////////////////////////////////////////////
417 // MAIN
418 //////////////////////////////////////////////////////////////////////////
419 int main(int argc, char** argv)
420 {
421 String pegasusHome = String::EMPTY;
422 String logsDirectory = String::EMPTY;
423 Boolean useSLP = false;
424 Boolean daemonOption = false;
425 Boolean shutdownOption = false;
426 Uint32 timeoutValue = 0;
427
428 #ifdef PEGASUS_OS_OS400
429 // Initialize Pegasus home to the shipped OS/400 directory.
430 kumpf 1.1 pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
431 #endif
432
|
433 kumpf 1.3 #ifndef PEGASUS_OS_TYPE_WINDOWS
|
434 kumpf 1.1 //
435 // Get environment variables:
436 //
437 const char* tmp = getenv("PEGASUS_HOME");
438
439 if (tmp)
440 {
441 pegasusHome = tmp;
442 }
443
444 FileSystem::translateSlashes(pegasusHome);
|
445 kumpf 1.3 #else
|
446 kumpf 1.1
|
447 kumpf 1.3 // windows only
448 setHome(pegasusHome);
449 #endif
|
450 kumpf 1.1 // on Windows NT if there are no command-line options, run as a service
451
452 if (argc == 1 )
453 {
|
454 kumpf 1.3 cim_server_service(argc, argv);
|
455 kumpf 1.1 }
456 else
457 {
458 // Get help, version, and shutdown options
|
459 kumpf 1.3
|
460 kumpf 1.1 for (int i = 1; i < argc; )
461 {
462 const char* arg = argv[i];
463
464 // Check for -option
465 if (*arg == '-')
466 {
467 // Get the option
468 const char* option = arg + 1;
469
470 //
471 // Check to see if user asked for the version (-v option):
472 //
|
473 kumpf 1.3 if (*option == OPTION_VERSION &&
474 strlen(option) == 1)
|
475 kumpf 1.1 {
|
476 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
477 kumpf 1.1 cout << PLATFORM_PRODUCT_VERSION << endl;
478 #else
479 cout << PEGASUS_VERSION << endl;
480 #endif
481 exit(0);
482 }
483 //
484 // Check to see if user asked for help (-h option):
485 //
|
486 kumpf 1.3 else if (*option == OPTION_HELP &&
487 (strlen(option) == 1))
|
488 kumpf 1.1 {
489 PrintHelp(argv[0]);
490 exit(0);
491 }
|
492 kumpf 1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
493 kumpf 1.3 else if (*option == OPTION_HOME &&
494 (strlen(option) == 1))
|
495 kumpf 1.1 {
496 if (i + 1 < argc)
497 {
498 pegasusHome.assign(argv[i + 1]);
499 }
500 else
501 {
502 cout << "Missing argument for option -" << option << endl;
503 exit(0);
504 }
505
506 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
507 argc -= 2;
508 }
509 #endif
510 #if defined(PEGASUS_OS_HPUX)
511 //
512 // Check to see if user asked for the version (-X option):
513 //
|
514 kumpf 1.3 if (*option == OPTION_BINDVERBOSE &&
515 (strlen(option) == 1))
|
516 kumpf 1.1 {
|
517 kumpf 1.3 System::bindVerbose = true;
|
518 kumpf 1.1 cout << "Unsupported debug option, BIND_VERBOSE, enabled."
519 << endl;
520 // remove the option from the command line
521 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
522 argc--;
523 }
524 #endif
525 //
526 // Check to see if user asked for shutdown (-s option):
527 //
|
528 kumpf 1.3 else if (*option == OPTION_SHUTDOWN &&
529 (strlen(option) == 1))
|
530 kumpf 1.1 {
531 //
532 // check to see if user is root
533 //
|
534 kumpf 1.2 #ifndef PEGASUS_OS_OS400
|
535 kumpf 1.1 if (!System::isPrivilegedUser(System::getEffectiveUserName()))
536 {
537 cout << "You must have superuser privilege to run ";
538 cout << "cimserver." << endl;
539 exit(0);
540 }
|
541 kumpf 1.2 #endif
|
542 kumpf 1.1
543 //
544 // Check to see if shutdown has already been specified:
545 //
546 if (shutdownOption)
547 {
548 cout << "Duplicate shutdown option specified." << endl;
549 exit(0);
550 }
551
552 shutdownOption = true;
553
554 // remove the option from the command line
555 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
556 argc--;
557 }
|
558 kumpf 1.3 #ifdef PEGASUS_OS_TYPE_WINDOWS
559 else if (strcmp(option, OPTION_INSTALL) == 0)
560 {
561 //
562 // Install as a NT service
563 //
564 char *opt_arg = NULL;
565 if (i+1 < argc)
566 {
567 opt_arg = argv[i+1];
568
569 }
570 if(cimserver_install_nt_service(opt_arg))
571 {
572 cout << "\nPegasus installed as NT Service";
573 exit(0);
574 }
575 else
576 {
577 exit(0);
578 }
579 kumpf 1.3 }
580 else if (strcmp(option, OPTION_REMOVE) == 0)
581 {
582 //
583 // Remove Pegasus as an NT service
584 //
585 char *opt_arg = NULL;
586 if (i+1 < argc)
587 {
588 opt_arg = argv[i+1];
589 }
590 if(cimserver_remove_nt_service(opt_arg))
591 {
592 cout << "\nPegasus removed as NT Service";
593 exit(0);
594 }
595 else
596 {
597 exit(0);
598 }
599
600 kumpf 1.3 }
601 else if (strcmp(option, OPTION_START) == 0)
602 {
603 //
604 // Start as a NT service
605 //
606 char *opt_arg = NULL;
607 if (i+1 < argc)
608 {
609 opt_arg = argv[i+1];
610 }
611 if(cimserver_start_nt_service(opt_arg))
612 {
613 cout << "\nPegasus started as NT Service";
614 exit(0);
615 }
616 else
617 {
618 exit(0);
619 }
620 }
621 kumpf 1.3 else if (strcmp(option, OPTION_STOP) == 0)
622 {
623 //
624 // Stop as a NT service
625 //
626 char *opt_arg = NULL;
627 if (i+1 < argc)
628 {
629 opt_arg = argv[i+1];
630 }
631 if(cimserver_stop_nt_service(opt_arg))
632 {
633 cout << "\nPegasus stopped as NT Service";
634 exit(0);
635 }
636 else
637 {
638 exit(0);
639 }
640 }
641 #endif
|
642 kumpf 1.1 else
|
643 kumpf 1.3 i++;
|
644 kumpf 1.1 }
645 else
|
646 kumpf 1.3 i++;
|
647 kumpf 1.1 }
648 }
649
650 //
651 // Set the value for pegasusHome property
652 //
653 ConfigManager::setPegasusHome(pegasusHome);
654
655 //
656 // Get an instance of the Config Manager.
657 //
658 configManager = ConfigManager::getInstance();
659
660 //
661 // Get options (from command line and from configuration file); this
662 // removes corresponding options and their arguments from the command
663 // line.
664 //
665 try
666 {
667 GetOptions(configManager, argc, argv, pegasusHome);
668 kumpf 1.1 }
669 catch (Exception& e)
670 {
|
671 kumpf 1.3 #ifdef PEGASUS_OS_OS400
672 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
673 "$0: $1",argv[0] ,e.getMessage());
674 #else
|
675 kumpf 1.1 cerr << argv[0] << ": " << e.getMessage() << endl;
|
676 kumpf 1.3 #endif
|
677 kumpf 1.1 exit(1);
678 }
679
|
680 kumpf 1.3 // l10n
681 // Set the home directory, msg sub-dir, into the MessageLoader.
682 // This will be the default directory where the resource bundles
683 // are found.
684 String messagesDir = String::EMPTY;
685 #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM
686 messagesDir = OS400_DEFAULT_MESSAGE_SOURCE;
687 #else
688 messagesDir = ConfigManager::getHomedPath("msg");
689 #endif
690 MessageLoader::setPegasusMsgHome(messagesDir);
691
|
692 kumpf 1.2 Boolean enableHttpConnection = String::equal(
|
693 kumpf 1.3 configManager->getCurrentValue("enableHttpConnection"), "true");
694 Boolean enableHttpsConnection = String::equal(
695 configManager->getCurrentValue("enableHttpsConnection"), "true");
|
696 kumpf 1.2
697 // Make sure at least one connection is enabled
698 #ifndef PEGASUS_LOCAL_DOMAIN_SOCKET
699 if (!enableHttpConnection && !enableHttpsConnection)
700 {
|
701 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
|
702 kumpf 1.2 "Neither HTTP nor HTTPS connection is enabled. "
703 "CIMServer will not be started.");
|
704 kumpf 1.3 cerr << "Neither HTTP nor HTTPS connection is enabled. "
|
705 kumpf 1.2 "CIMServer will not be started." << endl;
|
706 kumpf 1.3 exit(1);
|
707 kumpf 1.2 }
708 #endif
709
|
710 kumpf 1.1 try
711 {
712 //
713 // Check to see if we should Pegasus as a daemon
714 //
715
716 if (String::equal(configManager->getCurrentValue("daemon"), "true"))
717 {
718 daemonOption = true;
719 }
720
721 // Get the log file directory definition.
722 // We put String into Cstring because
723 // Directory functions only handle Cstring.
724 // ATTN-KS: create String based directory functions.
725
726 logsDirectory = configManager->getCurrentValue("logdir");
|
727 kumpf 1.3 logsDirectory =
728 ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
|
729 kumpf 1.1
730 // Set up the Logger. This does not open the logs
731 // Might be more logical to clean before set.
732 // ATTN: Need tool to completely disable logging.
733
|
734 kumpf 1.3 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
735 !defined(PEGASUS_OS_OS400)
|
736 kumpf 1.1 Logger::setHomeDirectory(logsDirectory);
737 #endif
738
739 //
740 // Check to see if we need to shutdown CIMOM
741 //
742 if (shutdownOption)
743 {
744 String configTimeout =
745 configManager->getCurrentValue("shutdownTimeout");
746 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
747
748 shutdownCIMOM(timeoutValue);
749
|
750 kumpf 1.3 #ifdef PEGASUS_OS_OS400
751 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
752 "CIM Server stopped.");
753 #else
|
754 kumpf 1.1 cout << "CIM Server stopped." << endl;
|
755 kumpf 1.2 #endif
|
756 kumpf 1.3 cimserver_exit(0);
|
757 kumpf 1.1 }
758
759 // Leave this in until people get familiar with the logs.
|
760 kumpf 1.3 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
761 !defined(PEGASUS_OS_OS400)
|
762 kumpf 1.1 cout << "Logs Directory = " << logsDirectory << endl;
763 #endif
764
765 if (String::equal(configManager->getCurrentValue("slp"), "true"))
766 {
767 useSLP = true;
768 }
769 }
|
770 kumpf 1.5 catch (UnrecognizedConfigProperty& e)
|
771 kumpf 1.1 {
|
772 kumpf 1.3
773 #ifdef PEGASUS_OS_OS400
774 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
775 "Error: $0",e.getMessage());
776 #else
777 cout << "Error: " << e.getMessage() << endl;
778 #endif
|
779 kumpf 1.1 }
780
|
781 kumpf 1.2 Uint32 portNumberHttps;
782 Uint32 portNumberHttp;
|
783 kumpf 1.1
|
784 kumpf 1.2 if (enableHttpsConnection)
|
785 kumpf 1.1 {
|
786 kumpf 1.2 String httpsPort = configManager->getCurrentValue("httpsPort");
|
787 kumpf 1.1 CString portString = httpsPort.getCString();
|
788 kumpf 1.3 char* end = 0;
789 Uint32 port = strtol(portString, &end, 10);
790 assert(end != 0 && *end == '\0');
|
791 kumpf 1.1
792 //
|
793 kumpf 1.3 // Look up the WBEM-HTTPS port number
|
794 kumpf 1.1 //
|
795 kumpf 1.2 portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
|
796 kumpf 1.1 }
|
797 kumpf 1.2
798 if (enableHttpConnection)
|
799 kumpf 1.1 {
|
800 kumpf 1.2 String httpPort = configManager->getCurrentValue("httpPort");
|
801 kumpf 1.1 CString portString = httpPort.getCString();
|
802 kumpf 1.3 char* end = 0;
803 Uint32 port = strtol(portString, &end, 10);
804 assert(end != 0 && *end == '\0');
|
805 kumpf 1.1
806 //
|
807 kumpf 1.3 // Look up the WBEM-HTTP port number
|
808 kumpf 1.1 //
|
809 kumpf 1.2 portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
|
810 kumpf 1.1 }
811
812 // Put out startup up message.
|
813 kumpf 1.3 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
814 !defined(PEGASUS_OS_OS400)
|
815 kumpf 1.2 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
|
816 kumpf 1.1 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
|
817 kumpf 1.3 cout <<"Starting..."
818 << (useSLP ? " SLP reg. " : " No SLP ")
819 << endl;
|
820 kumpf 1.1 #endif
|
821 kumpf 1.3
|
822 kumpf 1.1 // do we need to run as a daemon ?
823 if (daemonOption)
824 {
825 if(-1 == cimserver_fork())
|
826 kumpf 1.2 #ifndef PEGASUS_OS_OS400
|
827 kumpf 1.3 {
828 exit(-1);
829 }
|
830 kumpf 1.2 #else
|
831 kumpf 1.3 {
832 return(-1);
833 }
|
834 kumpf 1.2 else
|
835 kumpf 1.3 {
836 return(0);
837 }
|
838 kumpf 1.2 #endif
|
839 kumpf 1.3
|
840 kumpf 1.1 }
841
842 #ifdef PEGASUS_OS_OS400
843 // Special server initialization code for OS/400.
844 if (cimserver_initialize() != 0)
845 {
|
846 kumpf 1.3 // do some logging here!
847 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
848 "CIM Server failed to initialize");
849 exit(-1);
|
850 kumpf 1.1 }
851 #endif
852
|
853 kumpf 1.3 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
854 kumpf 1.1 umask(S_IWGRP|S_IWOTH);
|
855 kumpf 1.2
856 //
857 // check if CIMServer is already running
858 // if CIMServer is already running, print message and
859 // notify parent process (if there is a parent process) to terminate
860 //
861 if(isCIMServerRunning())
862 {
863 cout << "Unable to start CIMServer." << endl;
864 cout << "CIMServer is already running." << endl;
865
866 //
867 // notify parent process (if there is a parent process) to terminate
868 //
869 if (daemonOption)
|
870 kumpf 1.3 notify_parent(1);
|
871 kumpf 1.2
872 exit(1);
873 }
874
|
875 kumpf 1.1 #endif
876
877 // try loop to bind the address, and run the server
878 try
879 {
|
880 kumpf 1.3 Monitor monitor(true);
881 CIMServer server(&monitor);
|
882 kumpf 1.2
883 if (enableHttpConnection)
884 {
885 server.addAcceptor(false, portNumberHttp, false);
|
886 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
887 kumpf 1.2 "Listening on HTTP port $0.", portNumberHttp);
888 }
889 if (enableHttpsConnection)
890 {
891 server.addAcceptor(false, portNumberHttps, true);
|
892 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
893 kumpf 1.2 "Listening on HTTPS port $0.", portNumberHttps);
894 }
895 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
896 server.addAcceptor(true, 0, false);
|
897 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
898 kumpf 1.2 "Listening on local connection socket.");
|
899 kumpf 1.1 #endif
900
|
901 kumpf 1.3 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && !defined(PEGASUS_OS_OS400)
|
902 kumpf 1.2 if (enableHttpConnection)
903 {
904 cout << "Listening on HTTP port " << portNumberHttp << endl;
905 }
906 if (enableHttpsConnection)
907 {
908 cout << "Listening on HTTPS port " << portNumberHttps << endl;
909 }
|
910 kumpf 1.3 # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
|
911 kumpf 1.2 cout << "Listening on local connection socket" << endl;
|
912 kumpf 1.3 # endif
|
913 kumpf 1.1 #endif
914
|
915 kumpf 1.3 // bind throws an exception if the bind fails
916 server.bind();
|
917 kumpf 1.1
|
918 kumpf 1.3 // notify parent process (if there is a parent process) to terminate
919 // so user knows that there is cimserver ready to serve CIM requests.
920 if (daemonOption)
921 notify_parent(0);
|
922 kumpf 1.2
|
923 kumpf 1.3 time_t last = 0;
|
924 kumpf 1.1
|
925 kumpf 1.3 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
926 kumpf 1.1 //
927 // create a file to indicate that the cimserver has started and
928 // save the process id of the cimserver process in the file
929 //
930 // remove the old file if it exists
|
931 kumpf 1.3 System::removeFile(CIMSERVER_START_FILE);
|
932 kumpf 1.1
933 // open the file
|
934 kumpf 1.3 FILE *pid_file = fopen(CIMSERVER_START_FILE, "w");
935
|
936 kumpf 1.1 if (pid_file)
937 {
938 // save the pid in the file
939 fprintf(pid_file, "%ld\n", (long)server_pid);
940 fclose(pid_file);
941 }
942 #endif
|
943 kumpf 1.3
944 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
945 !defined(PEGASUS_OS_OS400)
946 cout << "Started. " << endl;
|
947 kumpf 1.1 #endif
948
949 // Put server started message to the logger
|
950 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
951 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
952 kumpf 1.2 "Started $0 version $1.",
953 PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
|
954 kumpf 1.1 #else
|
955 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
956 kumpf 1.2 "Started $0 version $1.",
957 PEGASUS_NAME, PEGASUS_VERSION);
|
958 kumpf 1.1 #endif
959
|
960 kumpf 1.3
961 //
|
962 kumpf 1.1 // Loop to call CIMServer's runForever() method until CIMServer
963 // has been shutdown
964 //
|
965 kumpf 1.3 while( !server.terminated() )
966 {
967 server.runForever();
968 }
|
969 kumpf 1.1
970 //
971 // normal termination
|
972 kumpf 1.3 //
|
973 kumpf 1.1 // Put server shutdown message to the logger
|
974 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
975 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
976 kumpf 1.2 "$0 stopped.", PLATFORM_PRODUCT_NAME);
977 #else
|
978 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
979 kumpf 1.1 "$0 stopped.", PEGASUS_NAME);
|
980 kumpf 1.2 #endif
|
981 kumpf 1.1
|
982 kumpf 1.3 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
983 kumpf 1.1 //
984 // close the file created at startup time to indicate that the
985 // cimserver has terminated normally.
986 //
|
987 kumpf 1.3 FileSystem::removeFile(CIMSERVER_START_FILE);
|
988 kumpf 1.1 #endif
989 }
990 catch(Exception& e)
991 {
|
992 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
993 "Error: $0", e.getMessage());
|
994 kumpf 1.2
|
995 kumpf 1.3 #ifndef PEGASUS_OS_OS400
996 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
997 #endif
998
999 //
1000 // notify parent process (if there is a parent process) to terminate
|
1001 kumpf 1.2 //
1002 if (daemonOption)
|
1003 kumpf 1.3 notify_parent(1);
|
1004 kumpf 1.2
|
1005 kumpf 1.1 return 1;
1006 }
1007
1008 return 0;
1009 }
|