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