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