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