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