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