1 karl 1.149 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.32 //
|
3 karl 1.141 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.121 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.141 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.149 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.32 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.58 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.32 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
|
19 kumpf 1.58 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.32 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.58 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.32 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Brasher (mbrasher@bmc.com)
31 //
32 // Modified By: Mike Day (mdday@us.ibm.com)
|
33 mike 1.33 //
|
34 mike 1.32 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
35 //
|
36 mike 1.35 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
37 //
38 // Modified By: Jenny Yu (jenny_yu@hp.com)
39 //
|
40 kumpf 1.38 // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
|
41 kumpf 1.72 // Carol Ann Krug Graves, Hewlett-Packard Company
42 // (carolann_graves@hp.com)
|
43 kumpf 1.73 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
|
44 kumpf 1.38 //
|
45 david 1.85 // Modified By: Dave Rosckes (rosckes@us.ibm.com)
46 //
|
47 humberto 1.90 // Modified By: Humberto Rivero (hurivero@us.ibm.com)
48 //
|
49 s.hills 1.117 // Modified By: Steve Hills (steve.hills@ncr.com)
50 //
|
51 a.arora 1.142 // Modified By: Amit K Arora, IBM (amitarora@in.ibm.com) - pep 167
52 //
|
53 joyce.j 1.144 // Modified By: Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2555
54 //
|
55 joyce.j 1.148 // Modified By: Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2032
56 //
|
57 mike 1.32 //%/////////////////////////////////////////////////////////////////////////////
58
59
60 //////////////////////////////////////////////////////////////////////
61 //
62 // Notes on deamon operation (Unix) and service operation (Win 32):
63 //
|
64 kumpf 1.60 // To run pegasus as a daemon on Unix platforms:
|
65 mike 1.32 //
|
66 kumpf 1.60 // cimserver
|
67 mike 1.32 //
|
68 kumpf 1.60 // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
69 // property to false:
70 //
71 // cimserver daemon=false
72 //
73 // The daemon config property has no effect on windows operation.
|
74 mike 1.32 //
|
75 mike 1.35 // To shutdown pegasus, use the -s option:
76 //
|
77 kumpf 1.60 // cimserver -s
|
78 mike 1.35 //
|
79 mike 1.32 // To run pegasus as an NT service, there are FOUR different possibilities:
80 //
81 // To INSTALL the Pegasus service,
82 //
83 // cimserver -install
84 //
85 // To REMOVE the Pegasus service,
86 //
87 // cimserver -remove
88 //
89 // To START the Pegasus service,
90 //
91 // net start cimserver
|
92 s.hills 1.117 // or
93 // cimserver -start
|
94 mike 1.32 //
95 // To STOP the Pegasus service,
96 //
97 // net stop cimserver
|
98 s.hills 1.117 // or
99 // cimserver -stop
|
100 mike 1.32 //
101 // Alternatively, you can use the windows service manager. Pegasus shows up
102 // in the service database as "Pegasus CIM Object Manager"
103 //
104 // Mike Day, mdday@us.ibm.com
105 //
106 //////////////////////////////////////////////////////////////////////
107
108
|
109 mike 1.35 #include <Pegasus/Common/Config.h>
|
110 kumpf 1.59 #include <Pegasus/Common/Constants.h>
|
111 mike 1.32 #include <iostream>
|
112 mike 1.35 #include <cassert>
|
113 mike 1.32 #include <cstdlib>
|
114 kumpf 1.45 #include <fstream>
|
115 mike 1.32 #include <Pegasus/Common/FileSystem.h>
|
116 mike 1.35 #include <Pegasus/Common/Monitor.h>
|
117 mike 1.32 #include <Pegasus/Server/CIMServer.h>
118 #include <Pegasus/Common/PegasusVersion.h>
119 #include <Pegasus/Common/Logger.h>
120 #include <Pegasus/Common/System.h>
|
121 mike 1.35 #include <Pegasus/Common/Tracer.h>
122 #include <Pegasus/Config/ConfigManager.h>
123 #include <Pegasus/Client/CIMClient.h>
124 #include <Pegasus/Server/ShutdownService.h>
|
125 mike 1.32
|
126 kumpf 1.119 PEGASUS_USING_PEGASUS;
127 PEGASUS_USING_STD;
128
|
129 kumpf 1.118 int cimserver_run( int argc, char** argv, Boolean shutdownOption );
|
130 mike 1.32
|
131 kumpf 1.137 Uint32 parentPid = 0;
132
|
133 mike 1.32 #if defined(PEGASUS_OS_TYPE_WINDOWS)
134 # include "cimserver_windows.cpp"
135 #elif defined(PEGASUS_OS_TYPE_UNIX)
|
136 chuck 1.66 # if defined(PEGASUS_OS_OS400)
|
137 david 1.120 # include "vfyptrs.cinc"
|
138 david 1.100 # include "OS400ConvertChar.h"
|
139 chuck 1.66 # include "cimserver_os400.cpp"
140 # else
141 # include "cimserver_unix.cpp"
142 #endif
|
143 mike 1.32 #else
144 # error "Unsupported platform"
145 #endif
146
|
147 mike 1.35 //
148 // The command name.
149 //
150 static const char COMMAND_NAME [] = "cimserver";
151
152 //
153 // The constant defining usage string.
154 //
155 static const char USAGE [] = "Usage: ";
156
157 /**
158 Constants representing the command line options.
159 */
160 static const char OPTION_VERSION = 'v';
161
162 static const char OPTION_HELP = 'h';
163
164 static const char OPTION_HOME = 'D';
165
166 static const char OPTION_SHUTDOWN = 's';
167
|
168 a.arora 1.142 static const char LONG_HELP [] = "help";
169
170 static const char LONG_VERSION [] = "version";
171
|
172 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
173 static const char OPTION_BINDVERBOSE = 'X';
174 #endif
175
|
176 kumpf 1.54 static const String PROPERTY_TIMEOUT = "shutdownTimeout";
|
177 mike 1.35
178 ConfigManager* configManager;
179
|
180 s.hills 1.117 /** Helper for platform specific handling. So platform specific code
181 can use our single instance of CIMServer.
182 */
183 class CimserverHolder
184 {
185 public:
186 CimserverHolder( CIMServer* s )
187 {
188 cimserver_set( s );
189 }
190 virtual ~CimserverHolder()
191 {
192 cimserver_set( 0 );
193 }
194 };
195
|
196 mike 1.32 /** GetOptions function - This function defines the Options Table
|
197 mike 1.35 and sets up the options from that table using the config manager.
|
198 mike 1.32 */
199 void GetOptions(
|
200 mike 1.35 ConfigManager* cm,
|
201 mike 1.32 int& argc,
|
202 s.hills 1.117 char** argv)
|
203 mike 1.32 {
|
204 mike 1.35 try
|
205 mike 1.32 {
|
206 kumpf 1.38 cm->mergeConfigFiles();
|
207 mike 1.33
|
208 mike 1.35 cm->mergeCommandLine(argc, argv);
209 }
|
210 kumpf 1.122 catch (NoSuchFile&)
|
211 mike 1.35 {
|
212 kumpf 1.122 throw;
|
213 mike 1.35 }
|
214 kumpf 1.122 catch (FileNotReadable&)
|
215 mike 1.35 {
|
216 kumpf 1.122 throw;
|
217 mike 1.35 }
|
218 kumpf 1.122 catch (CannotRenameFile&)
|
219 mike 1.35 {
|
220 kumpf 1.122 throw;
|
221 mike 1.35 }
|
222 kumpf 1.122 catch (ConfigFileSyntaxError&)
|
223 mike 1.35 {
|
224 kumpf 1.122 throw;
|
225 mike 1.35 }
|
226 kumpf 1.122 catch(UnrecognizedConfigProperty&)
|
227 mike 1.35 {
|
228 kumpf 1.122 throw;
|
229 mike 1.35 }
|
230 kumpf 1.122 catch(InvalidPropertyValue&)
|
231 mike 1.35 {
|
232 kumpf 1.122 throw;
|
233 mike 1.35 }
|
234 kumpf 1.123 catch (CannotOpenFile&)
235 {
236 throw;
237 }
|
238 mike 1.32 }
239
240 /* PrintHelp - This is temporary until we expand the options manager to allow
241 options help to be defined with the OptionRow entries and presented from
242 those entries.
243 */
244 void PrintHelp(const char* arg0)
245 {
|
246 mike 1.35 String usage = String (USAGE);
247 usage.append (COMMAND_NAME);
248 usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
249 usage.append (" options\n");
|
250 a.arora 1.142 usage.append (" -v, --version - displays CIM Server version number\n");
251 usage.append (" -h, --help - prints this help message\n");
|
252 humberto 1.97 usage.append (" -s - shuts down CIM Server\n");
|
253 kumpf 1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
254 usage.append (" -D [home] - sets pegasus home directory\n");
|
255 humberto 1.97 #endif
256 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
257 joyce.j 1.148 usage.append (" -install [name] - installs pegasus as a Windows Service\n");
|
258 humberto 1.97 usage.append (" [name] is optional and overrides the\n");
259 usage.append (" default CIM Server Service Name\n");
|
260 joyce.j 1.148 usage.append (" -remove [name] - removes pegasus as a Windows Service\n");
|
261 humberto 1.97 usage.append (" [name] is optional and overrides the\n");
262 usage.append (" default CIM Server Service Name\n");
|
263 joyce.j 1.148 usage.append (" -start [name] - starts pegasus as a Windows Service\n");
|
264 humberto 1.97 usage.append (" [name] is optional and overrides the\n");
265 usage.append (" default CIM Server Service Name\n");
|
266 joyce.j 1.148 usage.append (" -stop [name] - stops pegasus as a Windows Service\n");
|
267 humberto 1.97 usage.append (" [name] is optional and overrides the\n");
268 usage.append (" default CIM Server Service Name\n\n");
269 #endif
270 usage.append (" configProperty=value\n");
271 usage.append (" - sets CIM Server configuration property\n");
272
273 cout << endl;
|
274 kumpf 1.143 cout << PEGASUS_PRODUCT_NAME << " " << PEGASUS_PRODUCT_VERSION << endl;
|
275 humberto 1.97 cout << endl;
276
277 #if defined(PEGASUS_OS_TYPE_WINDOWS)
|
278 humberto 1.104 MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
|
279 kumpf 1.138 #elif defined(PEGASUS_OS_USE_RELEASE_DIRS)
280 MessageLoaderParms parms("src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);
|
281 humberto 1.97 #else
|
282 kumpf 1.138 MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
|
283 humberto 1.97 #endif
284 cout << MessageLoader::getMessage(parms) << endl;
|
285 mike 1.35 }
286
|
287 chuck 1.96 // l10n
288 //
289 // Dummy function for the Thread object associated with the initial thread.
290 // Since the initial thread is used to process CIM requests, this is
291 // needed to localize the exceptions thrown during CIM request processing.
292 // Note: This function should never be called!
293 //
294 PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
295 {
296 return((PEGASUS_THREAD_RETURN)0);
297 }
298
|
299 kumpf 1.52 void shutdownCIMOM(Uint32 timeoutValue)
|
300 mike 1.35 {
301 //
302 // Create CIMClient object
303 //
|
304 kumpf 1.42 CIMClient client;
|
305 mike 1.35
306 //
|
307 kumpf 1.53 // Get local host name
|
308 mike 1.35 //
309 String hostStr = System::getHostName();
310
311 //
312 // open connection to CIMOM
313 //
314 try
315 {
|
316 kumpf 1.43 client.connectLocal();
|
317 kumpf 1.52
318 //
|
319 kumpf 1.63 // set client timeout to 2 seconds
|
320 kumpf 1.52 //
|
321 kumpf 1.71 client.setTimeout(2000);
|
322 mike 1.35 }
|
323 s.hills 1.117 catch(Exception&)
|
324 mike 1.35 {
|
325 david 1.85 #ifdef PEGASUS_OS_OS400
|
326 humberto 1.97 //l10n
327 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
328 //"Unable to connect to CIM Server. CIM Server may not be running." );
329 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
330 "src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
|
331 david 1.85 "Unable to connect to CIM Server. CIM Server may not be running." );
332 // The server job may still be active but not responding.
333 // Kill the job if it exists.
|
334 humberto 1.90 if(cimserver_kill() == -1)
|
335 s.hills 1.117 cimserver_exitRC(2);
336 cimserver_exitRC(1);
|
337 david 1.85 #else
|
338 humberto 1.97 //l10n
339 //PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
340 //PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
341 MessageLoaderParms parms("src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
|
342 kumpf 1.105 "Unable to connect to CIM Server.\nCIM Server may not be running.\n");
|
343 humberto 1.97 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
|
344 s.hills 1.117 exit(1);
|
345 chuck 1.66 #endif
|
346 mike 1.35 }
347
348 try
349 {
350 //
|
351 kumpf 1.52 // construct CIMObjectPath
|
352 mike 1.35 //
353 String referenceStr = "//";
354 referenceStr.append(hostStr);
|
355 chuck 1.70 referenceStr.append("/");
|
356 kumpf 1.72 referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
|
357 kumpf 1.53 referenceStr.append(":");
|
358 kumpf 1.72 referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
|
359 kumpf 1.50 CIMObjectPath reference(referenceStr);
|
360 mike 1.35
361 //
362 // issue the invokeMethod request on the shutdown method
363 //
364 Array<CIMParamValue> inParams;
365 Array<CIMParamValue> outParams;
366
|
367 kumpf 1.52 // set force option to true for now
|
368 kumpf 1.40 inParams.append(CIMParamValue("force",
|
369 kumpf 1.52 CIMValue(Boolean(true))));
|
370 mike 1.35
|
371 kumpf 1.40 inParams.append(CIMParamValue("timeout",
|
372 kumpf 1.39 CIMValue(Uint32(timeoutValue))));
|
373 mike 1.35
374 CIMValue retValue = client.invokeMethod(
|
375 kumpf 1.59 PEGASUS_NAMESPACENAME_SHUTDOWN,
|
376 mike 1.35 reference,
377 "shutdown",
378 inParams,
379 outParams);
|
380 kumpf 1.43 }
|
381 kumpf 1.65 catch(CIMException& e)
|
382 kumpf 1.46 {
|
383 david 1.85 #ifdef PEGASUS_OS_OS400
384
385 if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
386 {
|
387 humberto 1.97 //l10n
388 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
389 //"Failed to shutdown server: $0", "The repository may be empty.");
390 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
391 "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
|
392 humberto 1.107 "Error in server shutdown: The repository may be empty.");
|
393 david 1.85 }
394 else
395 {
|
396 humberto 1.97 //l10n
397 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
398 //"Failed to shutdown server: $0", e.getMessage());
399 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
400 "src.Server.cimserver.SHUTDOWN_FAILED",
|
401 humberto 1.107 "Error in server shutdown: $0", e.getMessage());
|
402 david 1.85 }
403 // Kill the server job.
|
404 humberto 1.90 if(cimserver_kill() == -1)
|
405 s.hills 1.117 cimserver_exitRC(2);
|
406 david 1.85 #else
|
407 kumpf 1.105 //l10n - TODO
|
408 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.SHUTDOWN_FAILED",
|
409 kumpf 1.105 "Error in server shutdown: ");
|
410 humberto 1.97 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
|
411 kumpf 1.63 if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
412 {
|
413 kumpf 1.105 //
414 // Repository may be empty.
415 //
416 //l10n - TODO
417 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
418 "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
419 "Error in server shutdown: The repository may be empty.");
|
420 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.REPOSITORY_EMPTY",
|
421 kumpf 1.105 "The repository may be empty.");
422 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
|
423 kumpf 1.63 }
424 else
425 {
|
426 kumpf 1.105 //l10n - TODO
427 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
428 "src.Server.cimserver.SHUTDOWN_FAILED",
429 "Error in server shutdown: $0", e.getMessage());
|
430 kumpf 1.63 PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
431 }
|
432 kumpf 1.105
433 // Kill the cimserver process
434 if (cimserver_kill() == 0)
435 {
436 //l10n - TODO
437 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
438 "src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
439 "Forced shutdown initiated.");
440 MessageLoaderParms parms("src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
441 "Forced shutdown initiated.");
442 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
443 }
|
444 s.hills 1.117 exit(1);
|
445 chuck 1.66 #endif
|
446 kumpf 1.46 }
|
447 s.hills 1.117 catch(Exception&)
|
448 kumpf 1.45 {
449 //
|
450 kumpf 1.91 // This may mean that the CIM Server has terminated, causing this
451 // client to get a "Empty HTTP response message" exception. It may
452 // also mean that the CIM Server is taking longer than 2 seconds
453 // (client timeout value) to terminate, causing this client to
454 // timeout with a "connection timeout" exception.
|
455 kumpf 1.45 //
|
456 kumpf 1.91 // Check to see if CIM Server is still running. If CIM Server
|
457 kumpf 1.63 // is still running and the shutdown timeout has not expired,
|
458 kumpf 1.91 // loop and wait one second until either the CIM Server is
459 // terminated or timeout expires. If timeout expires and
460 // the CIM Server is still running, kill the CIMServer process.
461 //
|
462 kumpf 1.63 Uint32 maxWaitTime = timeoutValue - 2;
463 Boolean running = isCIMServerRunning();
464 while ( running && maxWaitTime > 0 )
465 {
466 System::sleep(1);
467 running = isCIMServerRunning();
468 maxWaitTime = maxWaitTime - 1;
469 }
470
471 if (running)
472 {
|
473 mday 1.112 int kill_rc = cimserver_kill();
474
|
475 humberto 1.90 #ifdef PEGASUS_OS_OS400
476 if(kill_rc == -1)
|
477 s.hills 1.117 cimserver_exitRC(2);
478 cimserver_exitRC(1);
|
479 humberto 1.90 #endif
|
480 kumpf 1.91
|
481 tony 1.128 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
|
482 kumpf 1.91 if (kill_rc != -1)
483 {
|
484 kumpf 1.105 //l10n - TODO
485 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
486 "src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
487 "Shutdown timeout expired. Forced shutdown initiated.");
|
488 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
|
489 kumpf 1.105 "Shutdown timeout expired. Forced shutdown initiated.");
|
490 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
491 kumpf 1.91 exit(0);
492 }
493 #endif
|
494 kumpf 1.63 }
|
495 kumpf 1.43 }
|
496 mike 1.35
497 return;
|
498 mike 1.32 }
499
|
500 mike 1.35
|
501 mike 1.33 /////////////////////////////////////////////////////////////////////////
|
502 mike 1.32 // MAIN
503 //////////////////////////////////////////////////////////////////////////
504 int main(int argc, char** argv)
505 {
|
506 mike 1.35 String pegasusHome = String::EMPTY;
507 Boolean shutdownOption = false;
|
508 mday 1.47
|
509 humberto 1.97 //l10n
510 // Set Message loading to process locale
511 MessageLoader::_useProcessLocale = true;
512 //l10n
513
|
514 kv.le 1.140 //l10n
515 #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
516 setlocale(LC_ALL, "");
517 #endif
518
|
519 chuck 1.66 #ifdef PEGASUS_OS_OS400
|
520 david 1.120
521 VFYPTRS_INCDCL; // VFYPTRS local variables
522
523 // verify pointers
524 #pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\
525 0,_C2_MH_ESCAPE)
526 for( int arg_index = 1; arg_index < argc; arg_index++ ){
527 VFYPTRS(VERIFY_SPP_NULL(argv[arg_index]));
528 }
529 #pragma disable_handler
530
|
531 david 1.100 // Convert the args to ASCII
532 for(Uint32 i = 0;i< argc;++i)
533 {
534 EtoA(argv[i]);
535 }
536
|
537 chuck 1.66 // Initialize Pegasus home to the shipped OS/400 directory.
538 pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
539 #endif
540
|
541 kv.le 1.134
|
542 tony 1.82 #ifndef PEGASUS_OS_TYPE_WINDOWS
|
543 kumpf 1.38 //
544 // Get environment variables:
545 //
|
546 david 1.100 #ifdef PEGASUS_OS_OS400
547 #pragma convert(37)
548 const char* tmp = getenv("PEGASUS_HOME");
549 #pragma convert(0)
550 char home[256] = {0};
551 if (tmp && strlen(tmp) < 256)
552 {
553 strcpy(home, tmp);
554 EtoA(home);
555 pegasusHome = home;
556 }
557 #else
|
558 kv.le 1.134 #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
559 pegasusHome = AIX_RELEASE_PEGASUS_HOME;
|
560 kumpf 1.138 #elif !defined(PEGASUS_USE_RELEASE_DIRS)
|
561 kumpf 1.38 const char* tmp = getenv("PEGASUS_HOME");
562
563 if (tmp)
564 {
565 pegasusHome = tmp;
566 }
|
567 kv.le 1.134 #endif
|
568 david 1.100 #endif
|
569 kumpf 1.38
570 FileSystem::translateSlashes(pegasusHome);
|
571 tony 1.82 #else
|
572 kumpf 1.38
|
573 tony 1.82 // windows only
574 setHome(pegasusHome);
575 #endif
|
576 mike 1.32
|
577 kumpf 1.60 // Get help, version, and shutdown options
|
578 mike 1.35
579 for (int i = 1; i < argc; )
580 {
581 const char* arg = argv[i];
|
582 a.arora 1.142 if(String::equal(arg,"--help"))
583 {
584 PrintHelp(argv[0]);
585 exit(0);
586 }
587 else if(String::equal(arg,"--version"))
588 {
|
589 kumpf 1.143 cout << PEGASUS_PRODUCT_VERSION << endl;
|
590 a.arora 1.142 exit(0);
591 }
|
592 mike 1.35 // Check for -option
|
593 a.arora 1.142 else if (*arg == '-')
|
594 mike 1.35 {
595 // Get the option
596 const char* option = arg + 1;
597
598 //
599 // Check to see if user asked for the version (-v option):
600 //
|
601 tony 1.83 if (*option == OPTION_VERSION &&
602 strlen(option) == 1)
|
603 mike 1.35 {
|
604 kumpf 1.143 cout << PEGASUS_PRODUCT_VERSION << endl;
|
605 mike 1.35 exit(0);
606 }
607 //
608 // Check to see if user asked for help (-h option):
609 //
|
610 tony 1.83 else if (*option == OPTION_HELP &&
611 (strlen(option) == 1))
|
612 mike 1.35 {
613 PrintHelp(argv[0]);
614 exit(0);
615 }
|
616 kumpf 1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
|
617 tony 1.83 else if (*option == OPTION_HOME &&
618 (strlen(option) == 1))
|
619 mike 1.35 {
|
620 kumpf 1.60 if (i + 1 < argc)
|
621 mike 1.35 {
622 pegasusHome.assign(argv[i + 1]);
623 }
624 else
625 {
|
626 humberto 1.97 //l10n
627 //cout << "Missing argument for option -" << option << endl;
|
628 humberto 1.99 String opt(option);
|
629 humberto 1.97 MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
630 "Missing argument for option -$0",
|
631 humberto 1.99 opt);
|
632 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
633 mike 1.35 exit(0);
634 }
635
636 memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
637 argc -= 2;
638 }
|
639 kumpf 1.63 #endif
|
640 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
641 //
|
642 kumpf 1.49 // Check to see if user asked for the version (-X option):
|
643 kumpf 1.48 //
|
644 tony 1.83 if (*option == OPTION_BINDVERBOSE &&
645 (strlen(option) == 1))
|
646 kumpf 1.48 {
647 System::bindVerbose = true;
|
648 humberto 1.97 //l10n
649 //cout << "Unsupported debug option, BIND_VERBOSE, enabled."
650 //<< endl;
651 MessageLoaderParms parms("src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
652 "Unsupported debug option, BIND_VERBOSE, enabled.");
653 cout << MessageLoader::getMessage(parms) << endl;
|
654 kumpf 1.48 // remove the option from the command line
655 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
656 argc--;
657 }
658 #endif
|
659 mike 1.35 //
660 // Check to see if user asked for shutdown (-s option):
661 //
|
662 tony 1.82 else if (*option == OPTION_SHUTDOWN &&
663 (strlen(option) == 1))
|
664 mike 1.35 {
665 //
|
666 kumpf 1.52 // Check to see if shutdown has already been specified:
|
667 mike 1.35 //
|
668 kumpf 1.52 if (shutdownOption)
|
669 mike 1.35 {
|
670 humberto 1.97 //l10n
671 //cout << "Duplicate shutdown option specified." << endl;
672 MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
673 "Duplicate shutdown option specified.");
674
675 cout << MessageLoader::getMessage(parms) << endl;
|
676 mike 1.35 exit(0);
677 }
678
|
679 kumpf 1.52 shutdownOption = true;
|
680 mike 1.35
681 // remove the option from the command line
682 memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
683 argc--;
684 }
685 else
686 i++;
687 }
688 else
689 i++;
|
690 mike 1.32 }
|
691 mike 1.35
|
692 kumpf 1.38 //
693 // Set the value for pegasusHome property
694 //
695 ConfigManager::setPegasusHome(pegasusHome);
|
696 mike 1.32
|
697 mike 1.35 //
|
698 s.hills 1.117 // Do the plaform specific run
699 //
700
701 return platform_run( argc, argv, shutdownOption );
702 }
703
704
705 //
706 // The main, common, running code
707 //
708 // NOTE: Do NOT call exit(). Use return(), otherwise some platforms
709 // will fail to shutdown properly/cleanly.
710 //
711 // TODO: Current change minimal for platform "service" shutdown bug fixes.
712 // Perhpas further extract out common stuff and put into main(), put
713 // daemon stuff into platform specific platform_run(), etc.
714 // Note: make sure to not put error handling stuff that platform
715 // specific runs may need to deal with bettter (instead of exit(), etc).
716 //
717
718 int cimserver_run( int argc, char** argv, Boolean shutdownOption )
719 s.hills 1.117 {
720 String logsDirectory = String::EMPTY;
721 Boolean daemonOption = false;
722
723 //
|
724 mike 1.35 // Get an instance of the Config Manager.
725 //
726 configManager = ConfigManager::getInstance();
|
727 kumpf 1.136 configManager->useConfigFiles = true;
|
728 mike 1.35
|
729 lucier 1.130 #ifdef PEGASUS_OS_OS400
730 // In a special startup case for IBM OS400, when the server is
731 // automatically started when the machine starts up the config
732 // file cannot be read because of access restrictions for the
733 // user starting the server. In this case, we need to skip
734 // reading the config options and therefore any use of the config
735 // manager also. To make this determinations we will check to see
736 // if the daemon flag is set to true. If so, then there will be a
737 // series of checks to bracket all the calls to the configManager
738 // which would otherwise fail. All this will only be done for
739 // IBM OS400.
740
741 Boolean os400StartupOption = false;
742 // loop through args to check for daemon=true
743 for (int i=1; i < argc; i++)
744 if (strcmp(argv[i], "daemon=true") == 0)
745 {
746 os400StartupOption = true;
747 daemonOption = true;
748 }
749 #endif
750 lucier 1.130
|
751 mike 1.35 //
|
752 mike 1.32 // Get options (from command line and from configuration file); this
|
753 mike 1.35 // removes corresponding options and their arguments from the command
|
754 mike 1.32 // line.
|
755 mike 1.35 //
|
756 mike 1.32 try
757 {
|
758 lucier 1.130 #ifdef PEGASUS_OS_OS400
759 if (os400StartupOption == false)
760 #endif
|
761 s.hills 1.117 GetOptions(configManager, argc, argv);
|
762 mike 1.32 }
763 catch (Exception& e)
764 {
|
765 kumpf 1.127 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
766 "src.Server.cimserver.SERVER_NOT_STARTED",
767 "cimserver not started: $0", e.getMessage());
768
769 #if !defined(PEGASUS_OS_OS400)
770 MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
771 "cimserver not started: $0", e.getMessage());
772
773 PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
774 << PEGASUS_STD(endl);
|
775 david 1.85 #endif
|
776 kumpf 1.127
|
777 s.hills 1.117 return(1);
|
778 mike 1.32 }
779
|
780 chuck 1.94 // l10n
781 // Set the home directory, msg sub-dir, into the MessageLoader.
782 // This will be the default directory where the resource bundles
|
783 david 1.133 // are found.
784 MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
785 ConfigManager::getInstance()->getCurrentValue("messageDir")));
|
786 chuck 1.94
|
787 lucier 1.130 #ifdef PEGASUS_OS_OS400
788 // Still need to declare and set the connection variables.
789 // Will initialize to false since they are fixed at false for OS400.
790
791 // NOTE: OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down
792 // the test will not be compiled in. If OS400 ever turns off that
793 // define, then we will need to change this code path to insure that
794 // one of the variables is true.
795 Boolean enableHttpConnection = false;
796 Boolean enableHttpsConnection = false;
|
797 kumpf 1.135 Boolean enableSSLExportClientVerification = false;
|
798 lucier 1.130
799 if (os400StartupOption == false)
800 {
801 enableHttpConnection = String::equal(
802 configManager->getCurrentValue("enableHttpConnection"), "true");
803 enableHttpsConnection = String::equal(
804 configManager->getCurrentValue("enableHttpsConnection"), "true");
|
805 kumpf 1.135 enableSSLExportClientVerification = String::equal(
806 configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
|
807 lucier 1.130 }
808 #else
|
809 kumpf 1.87 Boolean enableHttpConnection = String::equal(
810 configManager->getCurrentValue("enableHttpConnection"), "true");
811 Boolean enableHttpsConnection = String::equal(
812 configManager->getCurrentValue("enableHttpsConnection"), "true");
|
813 kumpf 1.135 Boolean enableSSLExportClientVerification = String::equal(
814 configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
|
815 lucier 1.130 #endif
|
816 kumpf 1.86
817 // Make sure at least one connection is enabled
818 #ifndef PEGASUS_LOCAL_DOMAIN_SOCKET
819 if (!enableHttpConnection && !enableHttpsConnection)
820 {
|
821 humberto 1.97 //l10n
822 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
823 //"Neither HTTP nor HTTPS connection is enabled. "
824 //"CIMServer will not be started.");
825 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
826 "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
827 "Neither HTTP nor HTTPS connection is enabled. CIMServer will not be started.");
828 //cerr << "Neither HTTP nor HTTPS connection is enabled. "
829 //"CIMServer will not be started." << endl;
830 MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
831 "Neither HTTP nor HTTPS connection is enabled. CIMServer will not be started.");
832 cerr << MessageLoader::getMessage(parms) << endl;
|
833 s.hills 1.117 return(1);
|
834 kumpf 1.86 }
835 #endif
836
|
837 mike 1.35 try
|
838 mike 1.32 {
|
839 mike 1.35 //
840 // Check to see if we should Pegasus as a daemon
841 //
842
843 if (String::equal(configManager->getCurrentValue("daemon"), "true"))
844 {
845 daemonOption = true;
846 }
|
847 mday 1.62
|
848 lucier 1.130 #ifdef PEGASUS_OS_OS400
849 if (os400StartupOption == false)
850 {
851 #endif
|
852 kumpf 1.36 // Get the log file directory definition.
853 // We put String into Cstring because
854 // Directory functions only handle Cstring.
855 // ATTN-KS: create String based directory functions.
856
857 logsDirectory = configManager->getCurrentValue("logdir");
|
858 kumpf 1.38 logsDirectory =
859 ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
|
860 lucier 1.130 #ifdef PEGASUS_OS_OS400
861 } // end if (os400StartupOption == false)
862 #endif
|
863 kumpf 1.36
864 // Set up the Logger. This does not open the logs
865 // Might be more logical to clean before set.
866 // ATTN: Need tool to completely disable logging.
867
|
868 david 1.85 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
869 !defined(PEGASUS_OS_OS400)
|
870 kumpf 1.36 Logger::setHomeDirectory(logsDirectory);
|
871 kumpf 1.57 #endif
|
872 kumpf 1.36
873 //
|
874 mike 1.35 // Check to see if we need to shutdown CIMOM
875 //
876 if (shutdownOption)
877 {
|
878 kumpf 1.60 String configTimeout =
879 configManager->getCurrentValue("shutdownTimeout");
|
880 s.hills 1.117 Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
|
881 kumpf 1.60
|
882 kumpf 1.52 shutdownCIMOM(timeoutValue);
|
883 kumpf 1.45
|
884 david 1.85 #ifdef PEGASUS_OS_OS400
|
885 humberto 1.97 //l10n
886 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
887 //"CIM Server stopped.");
888 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
889 "src.Server.cimserver.SERVER_STOPPED",
|
890 humberto 1.103 "CIM Server stopped.");
|
891 s.hills 1.117 cimserver_exitRC(0);
|
892 david 1.85 #else
|
893 humberto 1.97 //l10n
894 //cout << "CIM Server stopped." << endl;
895 MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",
|
896 humberto 1.106 "CIM Server stopped.");
897
|
898 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
899 s.hills 1.117 return(0);
|
900 diane 1.81 #endif
|
901 mike 1.35 }
|
902 mike 1.32
|
903 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
904 kumpf 1.36 // Leave this in until people get familiar with the logs.
|
905 humberto 1.97 //l10n
906 //cout << "Logs Directory = " << logsDirectory << endl;
907 MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
908 "Logs Directory = ");
909 cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
|
910 kumpf 1.57 #endif
|
911 mike 1.32 }
|
912 kumpf 1.122 catch (UnrecognizedConfigProperty& e)
|
913 mike 1.32 {
|
914 david 1.85
915 #ifdef PEGASUS_OS_OS400
|
916 humberto 1.97 //l10n
917 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
918 //"Error: $0",e.getMessage());
919 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
920 "src.Server.cimserver.ERROR",
921 "Error: $0",e.getMessage());
|
922 david 1.85 #else
|
923 humberto 1.97 //l10n
924 //cout << "Error: " << e.getMessage() << endl;
925 MessageLoaderParms parms("src.Server.cimserver.ERROR",
926 "Error: $0",
927 e.getMessage());
928 cout << MessageLoader::getMessage(parms) << endl;
|
929 david 1.85 #endif
|
930 mike 1.32 }
931
|
932 w.otsuka 1.147 Uint32 portNumberHttps=0;
933 Uint32 portNumberHttp=0;
934 Uint32 portNumberExportHttps=0;
|
935 kumpf 1.53
|
936 kumpf 1.86 if (enableHttpsConnection)
|
937 kumpf 1.53 {
|
938 kumpf 1.86 String httpsPort = configManager->getCurrentValue("httpsPort");
|
939 kumpf 1.69 CString portString = httpsPort.getCString();
|
940 kumpf 1.86 char* end = 0;
941 Uint32 port = strtol(portString, &end, 10);
|
942 joyce.j 1.144 if(!(end != 0 && *end == '\0'))
943 {
944 PEGASUS_STD(cerr) << "Bad HTTPS Port Value" << PEGASUS_STD(endl);
945 exit(1);
946 }
947
|
948 kumpf 1.53
949 //
|
950 kumpf 1.86 // Look up the WBEM-HTTPS port number
|
951 kumpf 1.53 //
|
952 kumpf 1.86 portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
|
953 kumpf 1.53 }
|
954 kumpf 1.86
955 if (enableHttpConnection)
|
956 kumpf 1.53 {
|
957 kumpf 1.86 String httpPort = configManager->getCurrentValue("httpPort");
|
958 kumpf 1.69 CString portString = httpPort.getCString();
|
959 kumpf 1.86 char* end = 0;
960 Uint32 port = strtol(portString, &end, 10);
|
961 joyce.j 1.144 if(!(end != 0 && *end == '\0'))
962 {
963 PEGASUS_STD(cerr) << "Bad HTTP Port Value" << PEGASUS_STD(endl);
964 exit(1);
965 }
|
966 kumpf 1.53 //
|
967 kumpf 1.86 // Look up the WBEM-HTTP port number
|
968 kumpf 1.53 //
|
969 kumpf 1.86 portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
|
970 kumpf 1.53 }
|
971 mike 1.32
|
972 kumpf 1.135 if (enableSSLExportClientVerification)
973 {
974 //
975 // No config property is looked up to get the default port number.
976 // Lookup the port defined in /etc/services for the service name
977 // wbem-exp-https and bind to that port. If the service is not defined
978 // then log a warning message and do not start the cimserver.
979 //
980 Uint32 port = 0;
981
982 portNumberExportHttps = System::lookupPort(WBEM_EXPORT_HTTPS_SERVICE_NAME, port);
983
984 if (portNumberExportHttps == 0)
985 {
986 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
987 "src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
988 "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
989
990 MessageLoaderParms parms("src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
991 "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
992
993 kumpf 1.135 cerr << MessageLoader::getMessage(parms) << endl;
994
995 return(1);
996 }
997 }
|
998 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
999 mike 1.32 // Put out startup up message.
|
1000 kumpf 1.143 cout << PEGASUS_PRODUCT_NAME << " " << PEGASUS_PRODUCT_VERSION << endl;
|
1001 humberto 1.97 //l10n
1002 //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
1003 //cout <<"Starting..."
1004 MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
1005 "Built $0 $1\nStarting...",
1006 __DATE__,
1007 __TIME__);
1008 #endif
1009
1010 //l10n
1011 // reset message loading to NON-process locale
1012 MessageLoader::_useProcessLocale = false;
1013 //l10n
|
1014 mike 1.32
|
1015 kumpf 1.137 // Get the parent's PID before forking
1016 parentPid = System::getPID();
1017
|
1018 kumpf 1.63 // do we need to run as a daemon ?
1019 if (daemonOption)
1020 {
1021 if(-1 == cimserver_fork())
|
1022 diane 1.81 #ifndef PEGASUS_OS_OS400
|
1023 s.hills 1.117 {
1024 return(-1);
|
1025 david 1.85 }
|
1026 diane 1.81 #else
|
1027 david 1.85 {
1028 return(-1);
1029 }
|
1030 diane 1.81 else
|
1031 david 1.85 {
1032 return(0);
1033 }
|
1034 diane 1.81 #endif
|
1035 david 1.85
|
1036 kumpf 1.63 }
|
1037 chuck 1.66
|
1038 chuck 1.96 // l10n
1039 // Now we are after the fork...
1040 // Create a dummy Thread object that can be used to store the
1041 // AcceptLanguages object for CIM requests that are serviced
1042 // by this thread (initial thread of server). Need to do this
1043 // because this thread is not in a ThreadPool, but is used
1044 // to service CIM requests.
1045 // The run function for the dummy Thread should never be called,
1046 Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
|
1047 humberto 1.108 Thread::setCurrent(dummyInitialThread);
1048 AcceptLanguages default_al;
1049 try{
1050 default_al = AcceptLanguages::getDefaultAcceptLanguages();
|
1051 humberto 1.109 Thread::setLanguages(new AcceptLanguages(default_al));
|
1052 kumpf 1.122 }catch(InvalidAcceptLanguageHeader& e){
|
1053 humberto 1.108 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1054 "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
1055 "Could not convert the system process locale into a valid AcceptLanguage format.");
1056 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1057 e.getMessage());
1058 }
|
1059 humberto 1.109
|
1060 humberto 1.97
|
1061 chuck 1.96
|
1062 chuck 1.66 #ifdef PEGASUS_OS_OS400
1063 // Special server initialization code for OS/400.
1064 if (cimserver_initialize() != 0)
1065 {
|
1066 david 1.85 // do some logging here!
|
1067 humberto 1.97 //l10n
1068 //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1069 //"CIM Server failed to initialize");
1070 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1071 "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE",
1072 "CIM Server failed to initialize");
|
1073 s.hills 1.117 return(-1);
|
1074 chuck 1.66 }
1075 #endif
|
1076 chuck 1.96
|
1077 mday 1.62
|
1078 tony 1.128 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
|
1079 kumpf 1.63 umask(S_IWGRP|S_IWOTH);
|
1080 kumpf 1.79
1081 //
1082 // check if CIMServer is already running
1083 // if CIMServer is already running, print message and
1084 // notify parent process (if there is a parent process) to terminate
1085 //
1086 if(isCIMServerRunning())
1087 {
|
1088 humberto 1.97 //l10n
1089 //cout << "Unable to start CIMServer." << endl;
1090 //cout << "CIMServer is already running." << endl;
1091 MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
|
1092 humberto 1.103 "Unable to start CIMServer.\nCIMServer is already running.");
|
1093 kumpf 1.105 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
|
1094 kumpf 1.79
1095 //
1096 // notify parent process (if there is a parent process) to terminate
1097 //
1098 if (daemonOption)
|
1099 konrad.r 1.95 notify_parent(1);
|
1100 kumpf 1.79
|
1101 s.hills 1.117 return(1);
|
1102 kumpf 1.79 }
1103
|
1104 kumpf 1.63 #endif
|
1105 kumpf 1.51
|
1106 mike 1.32 // try loop to bind the address, and run the server
1107 try
1108 {
|
1109 mday 1.116
|
1110 mike 1.32
|
1111 mday 1.112
1112
1113
|
1114 kumpf 1.146 Monitor monitor;
|
1115 mday 1.114 CIMServer server(&monitor);
|
1116 mday 1.111
|
1117 s.hills 1.117 CimserverHolder cimserverHolder( &server );
|
1118 kumpf 1.41
|
1119 kumpf 1.86 if (enableHttpConnection)
1120 {
|
1121 kumpf 1.135 server.addAcceptor(false, portNumberHttp, false, false);
|
1122 humberto 1.97 //l10n
1123 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1124 //"Listening on HTTP port $0.", portNumberHttp);
1125
1126 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
1127 humberto 1.103 "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1128 "Listening on HTTP port $0.", portNumberHttp);
|
1129 kumpf 1.86 }
1130 if (enableHttpsConnection)
1131 {
|
1132 kumpf 1.135 server.addAcceptor(false, portNumberHttps, true, false);
|
1133 humberto 1.97 //l10n
1134 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1135 //"Listening on HTTPS port $0.", portNumberHttps);
1136 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
1137 humberto 1.103 "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1138 "Listening on HTTPS port $0.", portNumberHttps);
|
1139 kumpf 1.86 }
|
1140 kumpf 1.135 if (enableSSLExportClientVerification)
1141 {
1142 server.addAcceptor(false, portNumberExportHttps, true, true);
1143
1144 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1145 "src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1146 "Listening on Export HTTPS port $0.", portNumberExportHttps);
1147 }
1148
|
1149 kumpf 1.41 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
|
1150 kumpf 1.135 server.addAcceptor(true, 0, false, false);
|
1151 humberto 1.97 //l10n
1152 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1153 //"Listening on local connection socket.");
1154 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
|
1155 humberto 1.103 "src.Server.cimserver.LISTENING_ON_LOCAL",
1156 "Listening on local connection socket.");
|
1157 kumpf 1.41 #endif
|
1158 kumpf 1.86
|
1159 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
1160 kumpf 1.86 if (enableHttpConnection)
1161 {
|
1162 humberto 1.97 //l10n
1163 //cout << "Listening on HTTP port " << portNumberHttp << endl;
|
1164 humberto 1.103 MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1165 "Listening on HTTP port $0.", portNumberHttp);
|
1166 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
1167 kumpf 1.86 }
1168 if (enableHttpsConnection)
1169 {
|
1170 humberto 1.97 //l10n
1171 //cout << "Listening on HTTPS port " << portNumberHttps << endl;
|
1172 humberto 1.103 MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1173 "Listening on HTTPS port $0.", portNumberHttps);
|
1174 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
1175 kumpf 1.86 }
|
1176 kumpf 1.135 if (enableSSLExportClientVerification)
1177 {
1178 MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1179 "Listening on Export HTTPS port $0.", portNumberExportHttps);
1180
1181 cout << MessageLoader::getMessage(parms) << endl;
1182 }
1183
|
1184 kumpf 1.86 # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
|
1185 humberto 1.97 //l10n
1186 //cout << "Listening on local connection socket" << endl;
1187 MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",
|
1188 humberto 1.103 "Listening on local connection socket.");
|
1189 humberto 1.97 cout << MessageLoader::getMessage(parms) << endl;
|
1190 kumpf 1.86 # endif
|
1191 david 1.85 #endif
|
1192 mike 1.35
|
1193 kumpf 1.86 // bind throws an exception if the bind fails
1194 server.bind();
|
1195 kumpf 1.73
|
1196 dan 1.76 // notify parent process (if there is a parent process) to terminate
|
1197 konrad.r 1.95 // so user knows that there is cimserver ready to serve CIM requests.
|
1198 dan 1.76 if (daemonOption)
|
1199 konrad.r 1.95 notify_parent(0);
|
1200 mike 1.32
1201 time_t last = 0;
|
1202 mike 1.35
|
1203 kumpf 1.139 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
|
1204 kumpf 1.45 //
|
1205 kumpf 1.56 // create a file to indicate that the cimserver has started and
1206 // save the process id of the cimserver process in the file
|
1207 kumpf 1.45 //
|
1208 kumpf 1.56 // remove the old file if it exists
|
1209 kumpf 1.91 System::removeFile(CIMSERVER_START_FILE);
|
1210 kumpf 1.56
1211 // open the file
|
1212 kumpf 1.91 FILE *pid_file = fopen(CIMSERVER_START_FILE, "w");
1213
|
1214 kumpf 1.56 if (pid_file)
|
1215 kumpf 1.45 {
|
1216 kumpf 1.56 // save the pid in the file
1217 fprintf(pid_file, "%ld\n", (long)server_pid);
1218 fclose(pid_file);
|
1219 kumpf 1.45 }
1220 #endif
|
1221 kumpf 1.91
|
1222 kumpf 1.139 #if defined(PEGASUS_DEBUG)
|
1223 kumpf 1.54 cout << "Started. " << endl;
|
1224 kumpf 1.63 #endif
|
1225 mday 1.116
|
1226 kumpf 1.54 // Put server started message to the logger
|
1227 kumpf 1.143 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1228 Logger::INFORMATION,
1229 "src.Server.cimserver.STARTED_VERSION",
1230 "Started $0 version $1.",
1231 PEGASUS_PRODUCT_NAME, PEGASUS_PRODUCT_VERSION);
|
1232 kumpf 1.45
|
1233 mike 1.35 //
1234 // Loop to call CIMServer's runForever() method until CIMServer
1235 // has been shutdown
1236 //
1237 while( !server.terminated() )
|
1238 mike 1.32 {
|
1239 mday 1.116
|
1240 mike 1.32 server.runForever();
|
1241 mday 1.112
|
1242 mike 1.32 }
|
1243 mday 1.112 MessageQueueService::force_shutdown(true);
|
1244 kumpf 1.45 //
1245 // normal termination
|
1246 mike 1.34 //
|
1247 kumpf 1.143
|
1248 kumpf 1.54 // Put server shutdown message to the logger
|
1249 kumpf 1.143 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1250 Logger::INFORMATION, "src.Server.cimserver.STOPPED",
1251 "$0 stopped.", PEGASUS_PRODUCT_NAME);
|
1252 kumpf 1.45
|
1253 tony 1.128 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
|
1254 kumpf 1.45 //
|
1255 kumpf 1.56 // close the file created at startup time to indicate that the
1256 // cimserver has terminated normally.
|
1257 kumpf 1.45 //
|
1258 kumpf 1.91 FileSystem::removeFile(CIMSERVER_START_FILE);
|
1259 kumpf 1.45 #endif
|
1260 mike 1.32 }
1261 catch(Exception& e)
1262 {
|
1263 david 1.100
|
1264 humberto 1.97 //l10n
1265 //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1266 //"Error: $0", e.getMessage());
1267 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1268 "src.Server.cimserver.ERROR",
1269 "Error: $0", e.getMessage());
|
1270 konrad.r 1.95
1271 #ifndef PEGASUS_OS_OS400
|
1272 humberto 1.97 //l10n
1273 //PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1274 MessageLoaderParms parms("src.Server.cimserver.ERROR",
1275 "Error: $0", e.getMessage());
1276 PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
|
1277 david 1.100
|
1278 david 1.85 #endif
|
1279 kumpf 1.77
1280 //
1281 // notify parent process (if there is a parent process) to terminate
1282 //
1283 if (daemonOption)
|
1284 konrad.r 1.95 notify_parent(1);
|
1285 kumpf 1.77
|
1286 kumpf 1.54 return 1;
|
1287 mike 1.32 }
1288
1289 return 0;
1290 }
|
1291 tony 1.128
1292
1293
1294
|