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