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