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