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