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