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