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