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