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