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