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 dj.gorey 1.7 // Modified By: Dan Gorey (djgorey@us.ibm.com)
|
48 kumpf 1.1 //%/////////////////////////////////////////////////////////////////////////////
49
50
51 //////////////////////////////////////////////////////////////////////
52 //
53 // Notes on deamon operation (Unix) and service operation (Win 32):
54 //
55 // To run pegasus as a daemon on Unix platforms:
56 //
57 // cimserver
58 //
59 // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
60 // property to false:
61 //
62 // cimserver daemon=false
63 //
64 // The daemon config property has no effect on windows operation.
65 //
66 // To shutdown pegasus, use the -s option:
67 //
68 // cimserver -s
69 kumpf 1.1 //
70 // To run pegasus as an NT service, there are FOUR different possibilities:
71 //
72 // To INSTALL the Pegasus service,
73 //
74 // cimserver -install
75 //
76 // To REMOVE the Pegasus service,
77 //
78 // cimserver -remove
79 //
80 // To START the Pegasus service,
81 //
82 // net start cimserver
83 //
84 // To STOP the Pegasus service,
85 //
86 // net stop cimserver
87 //
88 // Alternatively, you can use the windows service manager. Pegasus shows up
89 // in the service database as "Pegasus CIM Object Manager"
90 kumpf 1.1 //
91 // Mike Day, mdday@us.ibm.com
92 //
93 //////////////////////////////////////////////////////////////////////
94
95
96 #include <Pegasus/Common/Config.h>
97 #include <Pegasus/Common/Constants.h>
98 #include <iostream>
99 #include <cassert>
100 #include <cstdlib>
101 #include <fstream>
102 #include <Pegasus/Common/FileSystem.h>
103 #include <Pegasus/Common/Monitor.h>
104 #include <WMIMapper/PegServer/CIMServer.h>
105 #include <Pegasus/Common/PegasusVersion.h>
106 #include <Pegasus/Common/Logger.h>
107 #include <Pegasus/Common/System.h>
108 #include <Pegasus/Common/Tracer.h>
109 #include <Pegasus/Config/ConfigManager.h>
110 #include <Pegasus/Client/CIMClient.h>
111 kumpf 1.1 #include <Pegasus/Server/ShutdownService.h>
112 #include <Pegasus/Common/Destroyer.h>
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 kumpf 1.5 catch (NoSuchFile&)
|
183 kumpf 1.1 {
|
184 kumpf 1.5 throw;
|
185 kumpf 1.1 }
|
186 kumpf 1.5 catch (FileNotReadable&)
|
187 kumpf 1.1 {
|
188 kumpf 1.5 throw;
|
189 kumpf 1.1 }
|
190 kumpf 1.5 catch (CannotRenameFile&)
|
191 kumpf 1.1 {
|
192 kumpf 1.5 throw;
|
193 kumpf 1.1 }
|
194 kumpf 1.5 catch (ConfigFileSyntaxError&)
|
195 kumpf 1.1 {
|
196 kumpf 1.5 throw;
|
197 kumpf 1.1 }
|
198 kumpf 1.5 catch(UnrecognizedConfigProperty&)
|
199 kumpf 1.1 {
|
200 kumpf 1.5 throw;
|
201 kumpf 1.1 }
|
202 kumpf 1.5 catch(InvalidPropertyValue&)
|
203 kumpf 1.1 {
|
204 kumpf 1.5 throw;
|
205 kumpf 1.1 }
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 kumpf 1.5 catch (UnrecognizedConfigProperty& e)
|
772 kumpf 1.1 {
|
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 dj.gorey 1.8 #ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
|
882 kumpf 1.3 Monitor monitor(true);
|
883 dj.gorey 1.7 #else
884 monitor_2 monitor();
885 #endif
|
886 kumpf 1.3 CIMServer server(&monitor);
|
887 kumpf 1.2
888 if (enableHttpConnection)
889 {
890 server.addAcceptor(false, portNumberHttp, false);
|
891 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
892 kumpf 1.2 "Listening on HTTP port $0.", portNumberHttp);
893 }
894 if (enableHttpsConnection)
895 {
896 server.addAcceptor(false, portNumberHttps, true);
|
897 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
898 kumpf 1.2 "Listening on HTTPS port $0.", portNumberHttps);
899 }
900 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
901 server.addAcceptor(true, 0, false);
|
902 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
903 kumpf 1.2 "Listening on local connection socket.");
|
904 kumpf 1.1 #endif
905
|
906 kumpf 1.3 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && !defined(PEGASUS_OS_OS400)
|
907 kumpf 1.2 if (enableHttpConnection)
908 {
909 cout << "Listening on HTTP port " << portNumberHttp << endl;
910 }
911 if (enableHttpsConnection)
912 {
913 cout << "Listening on HTTPS port " << portNumberHttps << endl;
914 }
|
915 kumpf 1.3 # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
|
916 kumpf 1.2 cout << "Listening on local connection socket" << endl;
|
917 kumpf 1.3 # endif
|
918 kumpf 1.1 #endif
919
|
920 kumpf 1.3 // bind throws an exception if the bind fails
921 server.bind();
|
922 kumpf 1.1
|
923 kumpf 1.3 // notify parent process (if there is a parent process) to terminate
924 // so user knows that there is cimserver ready to serve CIM requests.
925 if (daemonOption)
926 notify_parent(0);
|
927 kumpf 1.2
|
928 kumpf 1.3 time_t last = 0;
|
929 kumpf 1.1
|
930 kumpf 1.3 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
931 kumpf 1.1 //
932 // create a file to indicate that the cimserver has started and
933 // save the process id of the cimserver process in the file
934 //
935 // remove the old file if it exists
|
936 kumpf 1.3 System::removeFile(CIMSERVER_START_FILE);
|
937 kumpf 1.1
938 // open the file
|
939 kumpf 1.3 FILE *pid_file = fopen(CIMSERVER_START_FILE, "w");
940
|
941 kumpf 1.1 if (pid_file)
942 {
943 // save the pid in the file
944 fprintf(pid_file, "%ld\n", (long)server_pid);
945 fclose(pid_file);
946 }
947 #endif
|
948 kumpf 1.3
949 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
950 !defined(PEGASUS_OS_OS400)
951 cout << "Started. " << endl;
|
952 kumpf 1.1 #endif
953
954 // Put server started message to the logger
|
955 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
956 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
957 kumpf 1.2 "Started $0 version $1.",
958 PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
|
959 kumpf 1.1 #else
|
960 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
961 kumpf 1.2 "Started $0 version $1.",
962 PEGASUS_NAME, PEGASUS_VERSION);
|
963 kumpf 1.1 #endif
964
|
965 kumpf 1.3
966 //
|
967 kumpf 1.1 // Loop to call CIMServer's runForever() method until CIMServer
968 // has been shutdown
969 //
|
970 kumpf 1.3 while( !server.terminated() )
971 {
972 server.runForever();
973 }
|
974 kumpf 1.1
975 //
976 // normal termination
|
977 kumpf 1.3 //
|
978 kumpf 1.1 // Put server shutdown message to the logger
|
979 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
980 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
981 kumpf 1.2 "$0 stopped.", PLATFORM_PRODUCT_NAME);
982 #else
|
983 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
984 kumpf 1.1 "$0 stopped.", PEGASUS_NAME);
|
985 kumpf 1.2 #endif
|
986 kumpf 1.1
|
987 kumpf 1.3 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
|
988 kumpf 1.1 //
989 // close the file created at startup time to indicate that the
990 // cimserver has terminated normally.
991 //
|
992 kumpf 1.3 FileSystem::removeFile(CIMSERVER_START_FILE);
|
993 kumpf 1.1 #endif
994 }
995 catch(Exception& e)
996 {
|
997 kumpf 1.3 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
998 "Error: $0", e.getMessage());
|
999 kumpf 1.2
|
1000 kumpf 1.3 #ifndef PEGASUS_OS_OS400
1001 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1002 #endif
1003
1004 //
1005 // notify parent process (if there is a parent process) to terminate
|
1006 kumpf 1.2 //
1007 if (daemonOption)
|
1008 kumpf 1.3 notify_parent(1);
|
1009 kumpf 1.2
|
1010 kumpf 1.1 return 1;
1011 }
1012
1013 return 0;
1014 }
|