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