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 tony 1.83 static const char OPTION_INSTALL[] = "install";
146
147 static const char OPTION_REMOVE[] = "remove";
148
149 static const char OPTION_START[] = "start";
150
151 static const char OPTION_STOP[] = "stop";
152
|
153 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
154 static const char OPTION_BINDVERBOSE = 'X';
155 #endif
156
|
157 kumpf 1.54 static const String PROPERTY_TIMEOUT = "shutdownTimeout";
|
158 kumpf 1.63 static const String CIMSERVERSTART_FILE = "/etc/opt/wbem/cimserver_start.conf";
|
159 mike 1.35
160 ConfigManager* configManager;
161
|
162 mike 1.32 /** GetOptions function - This function defines the Options Table
|
163 mike 1.35 and sets up the options from that table using the config manager.
|
164 mike 1.32 */
165 void GetOptions(
|
166 mike 1.35 ConfigManager* cm,
|
167 mike 1.32 int& argc,
168 char** argv,
169 const String& pegasusHome)
170 {
|
171 mike 1.35 try
|
172 mike 1.32 {
|
173 kumpf 1.38 cm->mergeConfigFiles();
|
174 mike 1.33
|
175 mike 1.35 cm->mergeCommandLine(argc, argv);
176 }
177 catch (NoSuchFile nsf)
178 {
179 throw nsf;
180 }
181 catch (FileNotReadable fnr)
182 {
183 throw fnr;
184 }
185 catch (CannotRenameFile ftrf)
186 {
187 throw ftrf;
188 }
189 catch (ConfigFileSyntaxError cfse)
190 {
191 throw cfse;
192 }
193 catch(UnrecognizedConfigProperty ucp)
194 {
195 throw ucp;
196 mike 1.35 }
197 catch(InvalidPropertyValue ipv)
198 {
199 throw ipv;
200 }
|
201 mike 1.32 }
202
203 /* PrintHelp - This is temporary until we expand the options manager to allow
204 options help to be defined with the OptionRow entries and presented from
205 those entries.
206 */
207 void PrintHelp(const char* arg0)
208 {
|
209 mike 1.35 /**
210 Build the usage string for the config command.
211 */
212 String usage = String (USAGE);
213 usage.append (COMMAND_NAME);
214 usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
215 usage.append (" options\n");
|
216 kumpf 1.60 usage.append (" -v - displays CIM Server version number\n");
|
217 mike 1.35 usage.append (" -h - prints this help message\n");
|
218 kumpf 1.60 usage.append (" -s - shuts down CIM Server\n");
|
219 kumpf 1.80 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
220 mike 1.35 usage.append (" -D [home] - sets pegasus home directory\n");
|
221 kumpf 1.60 #endif
222 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
223 mike 1.35 usage.append (" -install - installs pegasus as a Windows NT Service\n");
224 usage.append (" -remove - removes pegasus as a Windows NT Service\n");
|
225 tony 1.82 usage.append (" -start - starts pegasus as a Windows NT Service\n");
226 usage.append (" -stop - stops pegasus as a Windows NT Service\n");
|
227 kumpf 1.54 #endif
|
228 mike 1.35 usage.append (" configProperty=value\n");
|
229 kumpf 1.60 usage.append (" - sets CIM Server configuration property\n");
|
230 mike 1.35
231 cout << endl;
|
232 kumpf 1.80 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
233 kumpf 1.63 cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
234 #else
|
235 mike 1.32 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
|
236 kumpf 1.63 #endif
|
237 mike 1.32 cout << endl;
|
238 mike 1.35 cout << usage << endl;
239 }
240
|
241 kumpf 1.52 void shutdownCIMOM(Uint32 timeoutValue)
|
242 mike 1.35 {
243 //
244 // Create CIMClient object
245 //
|
246 kumpf 1.42 CIMClient client;
|
247 mike 1.35
248 //
|
249 kumpf 1.53 // Get local host name
|
250 mike 1.35 //
251 String hostStr = System::getHostName();
252
253 //
254 // open connection to CIMOM
255 //
256 try
257 {
|
258 kumpf 1.43 client.connectLocal();
|
259 kumpf 1.52
260 //
|
261 kumpf 1.63 // set client timeout to 2 seconds
|
262 kumpf 1.52 //
|
263 kumpf 1.71 client.setTimeout(2000);
|
264 mike 1.35 }
|
265 kumpf 1.64 catch(Exception& e)
|
266 mike 1.35 {
|
267 kumpf 1.52 PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
268 PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
|
269 chuck 1.66 #ifdef PEGASUS_OS_OS400
270 // The server job may still be active but not responding.
271 // Kill the job if it exists.
272 cimserver_kill();
|
273 diane 1.81 return;
|
274 chuck 1.66 #endif
|
275 kumpf 1.45 exit(0);
|
276 mike 1.35 }
277
278 try
279 {
280 //
|
281 kumpf 1.52 // construct CIMObjectPath
|
282 mike 1.35 //
283 String referenceStr = "//";
284 referenceStr.append(hostStr);
|
285 chuck 1.70 referenceStr.append("/");
|
286 kumpf 1.72 referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
|
287 kumpf 1.53 referenceStr.append(":");
|
288 kumpf 1.72 referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
|
289 kumpf 1.50 CIMObjectPath reference(referenceStr);
|
290 mike 1.35
291 //
292 // issue the invokeMethod request on the shutdown method
293 //
294 Array<CIMParamValue> inParams;
295 Array<CIMParamValue> outParams;
296
|
297 kumpf 1.52 // set force option to true for now
|
298 kumpf 1.40 inParams.append(CIMParamValue("force",
|
299 kumpf 1.52 CIMValue(Boolean(true))));
|
300 mike 1.35
|
301 kumpf 1.40 inParams.append(CIMParamValue("timeout",
|
302 kumpf 1.39 CIMValue(Uint32(timeoutValue))));
|
303 mike 1.35
304 CIMValue retValue = client.invokeMethod(
|
305 kumpf 1.59 PEGASUS_NAMESPACENAME_SHUTDOWN,
|
306 mike 1.35 reference,
307 "shutdown",
308 inParams,
309 outParams);
|
310 kumpf 1.43 }
|
311 kumpf 1.65 catch(CIMException& e)
|
312 kumpf 1.46 {
313 PEGASUS_STD(cerr) << "Failed to shutdown server: ";
|
314 kumpf 1.63 if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
315 {
316 PEGASUS_STD(cerr) << "The repository may be empty.";
317 PEGASUS_STD(cerr) << PEGASUS_STD(endl);
318 }
319 else
320 {
321 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
322 }
|
323 chuck 1.66 #ifdef PEGASUS_OS_OS400
324 // Kill the server job.
325 cimserver_kill();
|
326 diane 1.81 return;
|
327 chuck 1.66 #endif
|
328 kumpf 1.46 exit(1);
329 }
|
330 kumpf 1.65 catch(Exception& e)
|
331 kumpf 1.45 {
332 //
|
333 kumpf 1.54 // This may mean the CIM Server has been terminated and returns a
334 // "Empty HTTP response message" HTTP error response. To be sure
335 // CIM Server gets shutdown, if CIM Server is still running at
336 // this time, we will kill the cimserver process.
|
337 kumpf 1.45 //
|
338 kumpf 1.56 // give CIM Server some time to finish up
339 //
|
340 kumpf 1.63 //System::sleep(1);
341 //cimserver_kill();
342
343 //
344 // Check to see if CIMServer is still running. If CIMServer
345 // is still running and the shutdown timeout has not expired,
346 // loop and wait one second until either CIM Server is
347 // terminated or until timeout expires. If timeout expires
348 // and CIMServer is still running, kill the CIMServer
349 // process.
350 //
351 Uint32 maxWaitTime = timeoutValue - 2;
352 Boolean running = isCIMServerRunning();
353 while ( running && maxWaitTime > 0 )
354 {
355 System::sleep(1);
356 running = isCIMServerRunning();
357 maxWaitTime = maxWaitTime - 1;
358 }
359
360 if (running)
361 kumpf 1.63 {
362 cimserver_kill();
363 }
|
364 kumpf 1.43 }
|
365 kumpf 1.65 //catch(Exception& e)
366 //{
367 // PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: ";
368 // PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
369 // exit(1);
370 //}
|
371 mike 1.35
372 return;
|
373 mike 1.32 }
374
|
375 mike 1.35
|
376 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
377 mike 1.32 // MAIN
378 //////////////////////////////////////////////////////////////////////////
379 int main(int argc, char** argv)
380 {
|
381 mike 1.35 String pegasusHome = String::EMPTY;
382 Boolean pegasusIOLog = false;
|
383 kumpf 1.53 String httpPort = String::EMPTY;
384 String httpsPort = String::EMPTY;
|
385 mike 1.35 String logsDirectory = String::EMPTY;
386 Boolean useSLP = false;
387 Boolean useSSL = false;
388 Boolean daemonOption = false;
389 Boolean shutdownOption = false;
|
390 kumpf 1.60 Uint32 timeoutValue = 0;
|
391 mday 1.47
|
392 chuck 1.66 #ifdef PEGASUS_OS_OS400
393 // Initialize Pegasus home to the shipped OS/400 directory.
394 pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
395 #endif
396
|
397 tony 1.82 #ifndef PEGASUS_OS_TYPE_WINDOWS
|
398 kumpf 1.38 //
399 // Get environment variables:
400 //
401 const char* tmp = getenv("PEGASUS_HOME");
402
403 if (tmp)
404 {
405 pegasusHome = tmp;
406 }
407
408 FileSystem::translateSlashes(pegasusHome);
|
409 tony 1.82 #else
|
410 kumpf 1.38
|
411 tony 1.82 // windows only
412 setHome(pegasusHome);
413 #endif
|
414 mike 1.32 // on Windows NT if there are no command-line options, run as a service
415
416 if (argc == 1 )
|
417 mike 1.35 {
418 cim_server_service(argc, argv);
419 }
420 else
421 {
|
422 kumpf 1.60 // Get help, version, and shutdown options
|
423 mike 1.35
424 for (int i = 1; i < argc; )
425 {
426 const char* arg = argv[i];
427
428 // Check for -option
429 if (*arg == '-')
430 {
431 // Get the option
432 const char* option = arg + 1;
433
434 //
435 // Check to see if user asked for the version (-v option):
436 //
|
437 tony 1.83 if (*option == OPTION_VERSION &&
438 strlen(option) == 1)
|
439 mike 1.35 {
|
440 kumpf 1.80 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
441 kumpf 1.63 cout << PLATFORM_PRODUCT_VERSION << endl;
442 #else
|
443 mike 1.35 cout << PEGASUS_VERSION << endl;
|
444 kumpf 1.63 #endif
|
445 mike 1.35 exit(0);
446 }
447 //
448 // Check to see if user asked for help (-h option):
449 //
|
450 tony 1.83 else if (*option == OPTION_HELP &&
451 (strlen(option) == 1))
|
452 mike 1.35 {
453 PrintHelp(argv[0]);
454 exit(0);
455 }
|
456 kumpf 1.80 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
457 tony 1.83 else if (*option == OPTION_HOME &&
458 (strlen(option) == 1))
|
459 mike 1.35 {
|
460 kumpf 1.60 if (i + 1 < argc)
|
461 mike 1.35 {
462 pegasusHome.assign(argv[i + 1]);
463 }
464 else
465 {
466 cout << "Missing argument for option -" << option << endl;
467 exit(0);
468 }
469
470 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
471 argc -= 2;
472 }
|
473 kumpf 1.63 #endif
|
474 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
475 //
|
476 kumpf 1.49 // Check to see if user asked for the version (-X option):
|
477 kumpf 1.48 //
|
478 tony 1.83 if (*option == OPTION_BINDVERBOSE &&
479 (strlen(option) == 1))
|
480 kumpf 1.48 {
481 System::bindVerbose = true;
482 cout << "Unsupported debug option, BIND_VERBOSE, enabled."
483 << endl;
484 // remove the option from the command line
485 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
486 argc--;
487 }
488 #endif
|
489 mike 1.35 //
490 // Check to see if user asked for shutdown (-s option):
491 //
|
492 tony 1.82 else if (*option == OPTION_SHUTDOWN &&
493 (strlen(option) == 1))
|
494 mike 1.35 {
495 //
|
496 kumpf 1.52 // check to see if user is root
|
497 mike 1.35 //
|
498 chuck 1.70 #ifndef PEGASUS_OS_OS400
|
499 kumpf 1.55 if (!System::isPrivilegedUser(System::getEffectiveUserName()))
|
500 mike 1.35 {
|
501 kumpf 1.52 cout << "You must have superuser privilege to run ";
502 cout << "cimserver." << endl;
|
503 mike 1.35 exit(0);
504 }
|
505 chuck 1.70 #endif
|
506 mike 1.35
507 //
|
508 kumpf 1.52 // Check to see if shutdown has already been specified:
|
509 mike 1.35 //
|
510 kumpf 1.52 if (shutdownOption)
|
511 mike 1.35 {
|
512 kumpf 1.52 cout << "Duplicate shutdown option specified." << endl;
|
513 mike 1.35 exit(0);
514 }
515
|
516 kumpf 1.52 shutdownOption = true;
|
517 mike 1.35
518 // remove the option from the command line
519 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
520 argc--;
521 }
|
522 tony 1.83 else if (strcmp(option, OPTION_INSTALL) == 0)
523 {
524 //
525 // Install as a NT service
526 //
527 if(cimserver_install_nt_service())
528 {
529 cout << "\nPegasus installed as NT Service";
530 exit(0);
531 }
532 else
533 {
534 exit(0);
535 }
536 }
537 else if (strcmp(option, OPTION_REMOVE) == 0)
538 {
539 //
540 // Remove Pegasus as an NT service
541 //
542 if(cimserver_remove_nt_service())
543 tony 1.83 {
544 cout << "\nPegasus removed as NT Service";
545 exit(0);
546 }
547 else
548 {
549 exit(0);
550 }
551
552 }
553 else if (strcmp(option, OPTION_START) == 0)
554 {
555 //
556 // Start as a NT service
557 //
558 if(cimserver_start_nt_service())
559 {
560 cout << "\nPegasus started as NT Service";
561 exit(0);
562 }
563 else
564 tony 1.83 {
565 exit(0);
566 }
567 }
568 else if (strcmp(option, OPTION_STOP) == 0)
569 {
570 //
571 // Stop as a NT service
572 //
573 if(cimserver_stop_nt_service())
574 {
575 cout << "\nPegasus stopped as NT Service";
576 exit(0);
577 }
578 else
579 {
580 exit(0);
581 }
582 }
|
583 mike 1.35 else
584 i++;
585 }
586 else
587 i++;
|
588 mike 1.32 }
589 }
|
590 mike 1.35
|
591 kumpf 1.38 //
592 // Set the value for pegasusHome property
593 //
594 ConfigManager::setPegasusHome(pegasusHome);
|
595 mike 1.32
|
596 mike 1.35 //
597 // Get an instance of the Config Manager.
598 //
599 configManager = ConfigManager::getInstance();
600
601 //
|
602 mike 1.32 // Get options (from command line and from configuration file); this
|
603 mike 1.35 // removes corresponding options and their arguments from the command
|
604 mike 1.32 // line.
|
605 mike 1.35 //
|
606 mike 1.32 try
607 {
|
608 mike 1.35 GetOptions(configManager, argc, argv, pegasusHome);
|
609 mike 1.32 }
610 catch (Exception& e)
611 {
|
612 mike 1.35 cerr << argv[0] << ": " << e.getMessage() << endl;
613 exit(1);
|
614 mike 1.32 }
615
|
616 mike 1.35 try
|
617 mike 1.32 {
|
618 mike 1.35 //
619 // Check to see if we should Pegasus as a daemon
620 //
621
622 if (String::equal(configManager->getCurrentValue("daemon"), "true"))
623 {
624 daemonOption = true;
625 }
|
626 mday 1.62
|
627 mike 1.35 //
|
628 kumpf 1.36 // Check the log trace options and set global variable
629 //
630
631 if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
632 {
633 pegasusIOLog = true;
634 }
635
636 // Get the log file directory definition.
637 // We put String into Cstring because
638 // Directory functions only handle Cstring.
639 // ATTN-KS: create String based directory functions.
640
641 logsDirectory = configManager->getCurrentValue("logdir");
|
642 kumpf 1.38 logsDirectory =
643 ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
|
644 kumpf 1.36
645 // Set up the Logger. This does not open the logs
646 // Might be more logical to clean before set.
647 // ATTN: Need tool to completely disable logging.
648
|
649 kumpf 1.80 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
650 kumpf 1.36 Logger::setHomeDirectory(logsDirectory);
|
651 kumpf 1.57 #endif
|
652 kumpf 1.36
653 //
|
654 mike 1.35 // Check to see if we need to shutdown CIMOM
655 //
656 if (shutdownOption)
657 {
|
658 kumpf 1.60 String configTimeout =
659 configManager->getCurrentValue("shutdownTimeout");
|
660 kumpf 1.69 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
|
661 kumpf 1.60
|
662 kumpf 1.52 shutdownCIMOM(timeoutValue);
|
663 kumpf 1.45
|
664 kumpf 1.60 cout << "CIM Server stopped." << endl;
|
665 diane 1.81 #ifdef PEGASUS_OS_OS400
666 return(0);
667 #endif
|
668 mike 1.35 exit(0);
669 }
|
670 mike 1.32
|
671 mike 1.35 //
|
672 kumpf 1.53 // Get the port numbers
|
673 mike 1.35 //
674
|
675 kumpf 1.53 httpPort = configManager->getCurrentValue("httpPort");
676
677 httpsPort = configManager->getCurrentValue("httpsPort");
|
678 mike 1.35
|
679 kumpf 1.36 // Leave this in until people get familiar with the logs.
|
680 kumpf 1.80 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
681 kumpf 1.36 cout << "Logs Directory = " << logsDirectory << endl;
|
682 kumpf 1.57 #endif
|
683 mike 1.35
684 if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
685 {
686 Logger::clean(logsDirectory);;
687 }
|
688 mike 1.32
|
689 mike 1.35 if (String::equal(configManager->getCurrentValue("slp"), "true"))
690 {
691 useSLP = true;
692 }
|
693 mike 1.32
|
694 kumpf 1.78 #if defined(PEGASUS_USE_RELEASE_CONFIG_OPTIONS)
695 Boolean enableHttpConnection = String::equal(
696 configManager->getCurrentValue("enableHttpConnection"), "true");
697 Boolean enableHttpsConnection = String::equal(
698 configManager->getCurrentValue("enableHttpsConnection"), "true");
699
700 if (enableHttpConnection && enableHttpsConnection)
701 {
702 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
703 "Enabling both HTTP and HTTPS connections is unsupported. "
704 "Only the HTTPS connection is enabled.");
705 cerr << "Enabling both HTTP and HTTPS connections is unsupported. "
706 "Only the HTTPS connection is enabled." << endl;
707 }
708 else if (!enableHttpConnection && !enableHttpsConnection)
709 {
710 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
711 "Neither HTTP nor HTTPS connection is enabled. "
712 "CIMServer will not be started.");
713 cerr << "Neither HTTP nor HTTPS connection is enabled. "
714 "CIMServer will not be started." << endl;
715 kumpf 1.78 exit(1);
716 }
717
718 useSSL = enableHttpsConnection;
719
720 #else
|
721 mike 1.35 if (String::equal(configManager->getCurrentValue("SSL"), "true"))
722 {
723 useSSL = true;
724 }
|
725 kumpf 1.78 #endif
|
726 mike 1.32 }
|
727 mike 1.35 catch (UnrecognizedConfigProperty e)
|
728 mike 1.32 {
|
729 mike 1.35 cout << "Error: " << e.getMessage() << endl;
|
730 mike 1.32 }
731
|
732 kumpf 1.53 Uint32 portNumber;
733
734 char address[32];
735
736 if (useSSL)
737 {
738 char* end = 0;
|
739 kumpf 1.69 CString portString = httpsPort.getCString();
740 Uint32 port = strtol(portString, &end, 10);
|
741 kumpf 1.53 assert(end != 0 && *end == '\0');
742
743 //
744 // Look up the WBEM-HTTPS port number
745 //
746 portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
747 sprintf(address, "%u", portNumber);
748 }
749 else
750 {
751 char* end = 0;
|
752 kumpf 1.69 CString portString = httpPort.getCString();
753 Uint32 port = strtol(portString, &end, 10);
|
754 kumpf 1.53 assert(end != 0 && *end == '\0');
755
756 //
757 // Look up the WBEM-HTTP port number
758 //
759 portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
760 sprintf(address, "%u", portNumber);
761 }
|
762 mike 1.32
763 // Put out startup up message.
|
764 kumpf 1.80 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
765 mike 1.32 cout << PEGASUS_NAME << PEGASUS_VERSION <<
766 " on port " << address << endl;
767 cout << "Built " << __DATE__ << " " << __TIME__ << endl;
|
768 kumpf 1.54 cout <<"Starting..."
|
769 mike 1.32 << (pegasusIOLog ? " Tracing to Log ": " ")
770 << (useSLP ? " SLP reg. " : " No SLP ")
|
771 mike 1.35 << (useSSL ? " Use SSL " : " No SSL ")
|
772 mike 1.32 << endl;
|
773 kumpf 1.63 #endif
|
774 mike 1.32
|
775 kumpf 1.63 // do we need to run as a daemon ?
776 if (daemonOption)
777 {
778 if(-1 == cimserver_fork())
|
779 diane 1.81 #ifndef PEGASUS_OS_OS400
|
780 kumpf 1.63 exit(-1);
|
781 diane 1.81 #else
782 return(-1);
783 else
784 return(0);
785 #endif
|
786 kumpf 1.63 }
|
787 chuck 1.66
788 #ifdef PEGASUS_OS_OS400
789 // Special server initialization code for OS/400.
790 if (cimserver_initialize() != 0)
791 {
792 // do some logging here!
793 exit(-1);
794 }
795 #endif
|
796 mday 1.62
|
797 kumpf 1.63 #ifdef PEGASUS_OS_HPUX
798 umask(S_IWGRP|S_IWOTH);
|
799 kumpf 1.79
800 //
801 // check if CIMServer is already running
802 // if CIMServer is already running, print message and
803 // notify parent process (if there is a parent process) to terminate
804 //
805 if(isCIMServerRunning())
806 {
807 cout << "Unable to start CIMServer." << endl;
808 cout << "CIMServer is already running." << endl;
809
810 //
811 // notify parent process (if there is a parent process) to terminate
812 //
813 if (daemonOption)
814 notify_parent();
815
816 exit(1);
817 }
818
|
819 kumpf 1.63 #endif
|
820 kumpf 1.51
|
821 mike 1.32 // try loop to bind the address, and run the server
822 try
823 {
|
824 kumpf 1.75 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
|
825 mike 1.32 slp_client *discovery = new slp_client() ;;
826 String serviceURL;
827 serviceURL.assign("service:cim.pegasus://");
828 String host_name = slp_get_host_name();
|
829 kumpf 1.67 serviceURL.append(host_name);
830 serviceURL.append(":");
831 serviceURL.append(address);
|
832 mike 1.35 #endif
|
833 mike 1.32
|
834 mday 1.61 Monitor monitor(true);
|
835 kumpf 1.38 CIMServer server(&monitor, useSSL);
|
836 kumpf 1.41
837 // bind throws an exception if the bind fails
838 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
839 cout << "Binding to domain socket" << endl;
|
840 kumpf 1.80 #elif !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
841 mike 1.33 cout << "Binding to " << address << endl;
|
842 kumpf 1.41 #endif
|
843 mike 1.35
844 server.bind(portNumber);
|
845 kumpf 1.73
|
846 dan 1.76 // notify parent process (if there is a parent process) to terminate
847 // so user knows that cimserver is ready to serve CIM requests.
848 if (daemonOption)
849 notify_parent();
|
850 mike 1.32
851 time_t last = 0;
|
852 mike 1.35
|
853 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
854 //
|
855 kumpf 1.56 // create a file to indicate that the cimserver has started and
856 // save the process id of the cimserver process in the file
|
857 kumpf 1.45 //
|
858 kumpf 1.56
859 // remove the old file if it exists
860 System::removeFile(fname);
861
862 // open the file
863 FILE *pid_file = fopen(fname, "w");
864 if (pid_file)
|
865 kumpf 1.45 {
|
866 kumpf 1.56 // save the pid in the file
867 fprintf(pid_file, "%ld\n", (long)server_pid);
868 fclose(pid_file);
|
869 kumpf 1.45 }
870 #endif
|
871 kumpf 1.80 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
872 kumpf 1.54 cout << "Started. " << endl;
|
873 kumpf 1.63 #endif
|
874 kumpf 1.54
875 // Put server started message to the logger
|
876 kumpf 1.80 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
|
877 kumpf 1.63 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
878 "Started $0 version $1 on port $2.",
879 PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION, address);
880 #else
|
881 kumpf 1.54 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
|
882 kumpf 1.57 "Started $0 version $1 on port $2.",
883 PEGASUS_NAME, PEGASUS_VERSION, address);
|
884 kumpf 1.63 #endif
|
885 kumpf 1.45
|
886 mday 1.62
|
887 mike 1.35 //
888 // Loop to call CIMServer's runForever() method until CIMServer
889 // has been shutdown
890 //
891 while( !server.terminated() )
|
892 mike 1.32 {
|
893 kumpf 1.75 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
|
894 mike 1.32 if(useSLP )
895 {
896 if( (time(NULL) - last ) > 60 )
897 {
|
898 kumpf 1.69 if( discovery != NULL && serviceURL.size() )
899 discovery->srv_reg_all(serviceURL.getCString(),
|
900 mike 1.35 "(namespace=root/cimv2)",
|
901 mike 1.32 "service:cim.pegasus",
902 "DEFAULT",
903 70) ;
904 time(&last);
905 }
906
907 discovery->service_listener();
908 }
|
909 mike 1.35 #endif
|
910 mike 1.32 server.runForever();
911 }
912
|
913 kumpf 1.45 //
914 // normal termination
|
915 mike 1.34 //
|
916 kumpf 1.54 // Put server shutdown message to the logger
917 Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
918 "$0 stopped.", PEGASUS_NAME);
|
919 kumpf 1.45
920 #if defined(PEGASUS_OS_HPUX)
921 //
|
922 kumpf 1.56 // close the file created at startup time to indicate that the
923 // cimserver has terminated normally.
|
924 kumpf 1.45 //
925 FileSystem::removeFile(CIMSERVERSTART_FILE);
926 #endif
|
927 mike 1.32 }
928 catch(Exception& e)
929 {
930 PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
|
931 kumpf 1.77
932 //
933 // notify parent process (if there is a parent process) to terminate
934 //
935 if (daemonOption)
936 notify_parent();
937
|
938 kumpf 1.54 return 1;
|
939 mike 1.32 }
940
941 return 0;
942 }
|