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