(file) Return to cimserver.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / WMIMapper / WMIServer

  1 karl  1.23 //%2006////////////////////////////////////////////////////////////////////////
  2 kumpf 1.1  //
  3 karl  1.11 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 karl  1.4  // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.11 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 karl  1.14 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.23 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13 kumpf 1.1  //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15            // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18            // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20            // 
 21            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34 kumpf 1.1  
 35            //////////////////////////////////////////////////////////////////////
 36            //
 37            // Notes on deamon operation (Unix) and service operation (Win 32):
 38            //
 39            // To run pegasus as a daemon on Unix platforms: 
 40            //
 41            // cimserver
 42            //
 43            // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
 44            // property to false:
 45            //
 46            // cimserver daemon=false
 47            //
 48            // The daemon config property has no effect on windows operation. 
 49            //
 50            // To shutdown pegasus, use the -s option:
 51            // 
 52            // cimserver -s 
 53            //
 54            // To run pegasus as an NT service, there are FOUR  different possibilities:
 55 kumpf 1.1  //
 56            // To INSTALL the Pegasus service, 
 57            //
 58            // cimserver -install
 59            //
 60            // To REMOVE the Pegasus service, 
 61            //
 62            // cimserver -remove
 63            //
 64            // To START the Pegasus service, 
 65            //
 66            // net start cimserver
 67 mateus.baur 1.17 // or
 68                  // cimserver -start
 69 kumpf       1.1  //
 70                  // To STOP the Pegasus service, 
 71                  //
 72                  // net stop cimserver
 73 mateus.baur 1.17 // or
 74                  // cimserver -stop
 75 kumpf       1.1  //
 76                  // Alternatively, you can use the windows service manager. Pegasus shows up 
 77                  // in the service database as "Pegasus CIM Object Manager"
 78                  //
 79                  //////////////////////////////////////////////////////////////////////
 80                  
 81                  
 82                  #include <Pegasus/Common/Config.h>
 83                  #include <Pegasus/Common/Constants.h>
 84                  #include <iostream>
 85 jim.wunderlich 1.20 #include <Pegasus/Common/PegasusAssert.h>
 86 kumpf          1.1  #include <fstream>
 87                     #include <Pegasus/Common/FileSystem.h>
 88                     #include <Pegasus/Common/Monitor.h>
 89                     #include <Pegasus/Common/PegasusVersion.h>
 90                     #include <Pegasus/Common/Logger.h>
 91                     #include <Pegasus/Common/System.h>
 92                     #include <Pegasus/Common/Tracer.h>
 93 kumpf          1.21 #include <Pegasus/Common/LanguageParser.h>
 94 kumpf          1.1  #include <Pegasus/Config/ConfigManager.h>
 95                     #include <Pegasus/Client/CIMClient.h>
 96 mateus.baur    1.17 #include <Pegasus/Server/CIMServer.h>
 97                     #include <Service/ServerProcess.h>
 98 kumpf          1.30 #include <Service/ServerShutdownClient.h>
 99                     #include <Service/ServerRunStatus.h>
100 mateus.baur    1.17 
101                     PEGASUS_USING_PEGASUS;
102                     PEGASUS_USING_STD;
103 kumpf          1.1  
104 kumpf          1.30 #define PEGASUS_PROCESS_NAME "WMI Mapper"
105 kumpf          1.3  
106 mateus.baur    1.17 //Windows service variables are not defined elsewhere in the product
107                     //enable ability to override these
108                     #ifndef PEGASUS_SERVICE_NAME
109                     #define PEGASUS_SERVICE_NAME "Pegasus WMI Mapper";
110 kumpf          1.1  #endif
111 mateus.baur    1.17 #ifndef PEGASUS_SERVICE_DESCRIPTION
112                     #define PEGASUS_SERVICE_DESCRIPTION "Pegasus WMI Mapper Service";
113 kumpf          1.1  #endif
114                     
115 mateus.baur    1.17 class CIMServerProcess : public ServerProcess
116                     {
117                     public:
118                     
119                         CIMServerProcess(void)
120                         {
121                             cimserver_set_process(this);
122                         }
123                     
124                         virtual ~CIMServerProcess(void)
125                         {
126                         }
127                     
128                         //defined in PegasusVersion.h
129                         virtual const char* getProductName() const
130                         {
131                             return PEGASUS_PRODUCT_NAME;
132                         }
133                     
134                         virtual const char* getExtendedName() const
135                         {
136 mateus.baur    1.17         return PEGASUS_SERVICE_NAME;
137                         }
138                     
139                         virtual const char* getDescription() const
140                         {
141                             return PEGASUS_SERVICE_DESCRIPTION;
142                         }
143                         
144                         //defined in PegasusVersion.h
145                         virtual const char* getVersion() const
146                         {
147                             return PEGASUS_PRODUCT_VERSION;
148                         }
149                     
150                         virtual const char* getProcessName() const
151                         {
152                             return PEGASUS_PROCESS_NAME;
153                         }
154                     
155 mateus.baur    1.32     int cimserver_run(
156                             int argc,
157                             char** argv,
158                             Boolean shutdownOption,
159                             Boolean debugOutputOption);
160 mateus.baur    1.17 
161                         void cimserver_stop(void);
162                     };
163                     
164 kumpf          1.30 ServerRunStatus _serverRunStatus(
165                         PEGASUS_PROCESS_NAME, PEGASUS_CIMSERVER_START_FILE);
166 mateus.baur    1.17 AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
167                     static CIMServer* _cimServer = 0;
168 mateus.baur    1.18 static Monitor* _monitor = 0;
169 kumpf          1.1  
170                     //
171                     //  The command name.
172                     //
173                     static const char COMMAND_NAME []    = "cimserver";
174                     
175                     //
176                     //  The constant defining usage string.
177                     //
178                     static const char USAGE []           = "Usage: ";
179                     
180                     /**
181                     Constants representing the command line options.
182                     */
183                     static const char OPTION_VERSION     = 'v';
184                     
185                     static const char OPTION_HELP        = 'h';
186                     
187                     static const char OPTION_HOME        = 'D';
188                     
189                     static const char OPTION_SHUTDOWN    = 's';
190 kumpf          1.1  
191 mateus.baur    1.17 static const char   LONG_HELP []  = "help";
192 kumpf          1.3  
193 mateus.baur    1.17 static const char   LONG_VERSION []  = "version";
194 kumpf          1.3  
195 kumpf          1.1  #if defined(PEGASUS_OS_HPUX)
196                     static const char OPTION_BINDVERBOSE = 'X';
197                     #endif
198                     
199                     static const String PROPERTY_TIMEOUT = "shutdownTimeout";
200                     
201                     ConfigManager*    configManager;
202                     
203                     /** GetOptions function - This function defines the Options Table
204                         and sets up the options from that table using the config manager.
205 kumpf          1.30 
206                         Some possible exceptions:  NoSuchFile, FileNotReadable, CannotRenameFile,
207                         ConfigFileSyntaxError, UnrecognizedConfigProperty, InvalidPropertyValue,
208                         CannotOpenFile.
209 kumpf          1.1  */
210                     void GetOptions(
211                         ConfigManager* cm,
212                         int& argc,
213 mateus.baur    1.17     char** argv)
214 kumpf          1.1  {
215 kumpf          1.30     cm->mergeConfigFiles();
216                         cm->mergeCommandLine(argc, argv);
217 kumpf          1.1  }
218                     
219                     /* PrintHelp - This is temporary until we expand the options manager to allow
220                        options help to be defined with the OptionRow entries and presented from
221                        those entries.
222                     */
223                     void PrintHelp(const char* arg0)
224                     {
225                         String usage = String (USAGE);
226                         usage.append (COMMAND_NAME);
227                         usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
228                         usage.append ("  options\n");
229 mateus.baur    1.17     usage.append ("    -v, --version   - displays CIM Server version number\n");
230                         usage.append ("    -h, --help      - prints this help message\n");
231 kumpf          1.3      usage.append ("    -s              - shuts down CIM Server\n");
232 mateus.baur    1.17 #if !defined(PEGASUS_USE_RELEASE_DIRS)
233 kumpf          1.3      usage.append ("    -D [home]       - sets pegasus home directory\n");
234 kumpf          1.1  #endif
235                     #if defined(PEGASUS_OS_TYPE_WINDOWS)
236 mateus.baur    1.17     usage.append ("    -install [name] - installs pegasus as a Windows Service\n");
237 kumpf          1.3      usage.append ("                      [name] is optional and overrides the\n");
238                         usage.append ("                      default CIM Server Service Name\n");
239 mateus.baur    1.17     usage.append ("    -remove [name]  - removes pegasus as a Windows Service\n");
240 kumpf          1.3      usage.append ("                      [name] is optional and overrides the\n");
241                         usage.append ("                      default CIM Server Service Name\n");
242 mateus.baur    1.17     usage.append ("    -start [name]   - starts pegasus as a Windows Service\n");
243 kumpf          1.3      usage.append ("                      [name] is optional and overrides the\n");
244                         usage.append ("                      default CIM Server Service Name\n");
245 mateus.baur    1.17     usage.append ("    -stop [name]    - stops pegasus as a Windows Service\n");
246 kumpf          1.3      usage.append ("                      [name] is optional and overrides the\n");
247                         usage.append ("                      default CIM Server Service Name\n\n");
248 kumpf          1.1  #endif
249                         usage.append ("  configProperty=value\n");
250 kumpf          1.3      usage.append ("                    - sets CIM Server configuration property\n");
251 kumpf          1.1  
252                         cout << endl;
253 mateus.baur    1.17     cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;
254 kumpf          1.1      cout << endl;
255 mateus.baur    1.17     
256                     #if defined(PEGASUS_OS_TYPE_WINDOWS)
257                         MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
258                     #elif defined(PEGASUS_USE_RELEASE_DIRS)
259                         MessageLoaderParms parms("src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);
260                     #else
261                         MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
262                     #endif
263                         cout << MessageLoader::getMessage(parms) << endl;
264                     }
265                     
266                     //This needs to be called at various points in the code depending on the platform and error conditions.
267                     //We need to delete the _cimServer reference on exit in order for the destructors to get called.
268                     void deleteCIMServer()
269                     {
270                         if (_cimServer)
271                         {
272                             delete _cimServer;
273                             _cimServer = 0;
274                         }
275 mateus.baur    1.18 
276                     	if (_monitor)
277                     	{
278                     		delete _monitor;
279                     	}
280 kumpf          1.1  }
281                     
282 mateus.baur    1.17 // l10n
283 kumpf          1.3  //
284 mateus.baur    1.17 // Dummy function for the Thread object associated with the initial thread.
285                     // Since the initial thread is used to process CIM requests, this is
286                     // needed to localize the exceptions thrown during CIM request processing.
287                     // Note: This function should never be called! 
288                     // 
289 mike           1.26 ThreadReturnType PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
290 mateus.baur    1.17 {
291 mike           1.26    return((ThreadReturnType)0);    
292 kumpf          1.3  }
293                     
294 kumpf          1.1  
295                     /////////////////////////////////////////////////////////////////////////
296                     //  MAIN
297                     //////////////////////////////////////////////////////////////////////////
298                     int main(int argc, char** argv)
299                     {
300 kumpf          1.28     String pegasusHome;
301 kumpf          1.1      Boolean shutdownOption = false;
302 mateus.baur    1.32     Boolean debugOutputOption = false;
303 mateus.baur    1.17 
304                     //l10n
305                     // Set Message loading to process locale
306                     MessageLoader::_useProcessLocale = true; 
307                     //l10n
308                     
309                     //l10n
310                     #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
311                     setlocale(LC_ALL, "");
312                     #endif
313 kumpf          1.1  
314 kumpf          1.3  #ifndef PEGASUS_OS_TYPE_WINDOWS
315 kumpf          1.1      //
316                         // Get environment variables:
317                         //
318 mateus.baur    1.17   #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
319                         pegasusHome = AIX_RELEASE_PEGASUS_HOME;
320                       #elif !defined(PEGASUS_USE_RELEASE_DIRS)
321 kumpf          1.1      const char* tmp = getenv("PEGASUS_HOME");
322                     
323                         if (tmp)
324                         {
325                             pegasusHome = tmp;
326                         }
327 mateus.baur    1.17   #endif
328 kumpf          1.1  
329                         FileSystem::translateSlashes(pegasusHome);
330 kumpf          1.3  #else
331 kumpf          1.1  
332 kumpf          1.3    // windows only
333 mateus.baur    1.17   //setHome(pegasusHome);
334                       pegasusHome = _cimServerProcess->getHome();
335 kumpf          1.3  #endif
336 kumpf          1.1  
337                             // Get help, version, and shutdown options
338 kumpf          1.3  
339 kumpf          1.1          for (int i = 1; i < argc; )
340                             {
341                                 const char* arg = argv[i];
342 mateus.baur    1.17             if(String::equal(arg,"--help"))
343                                 {
344                                         PrintHelp(argv[0]);
345                                         exit(0);
346                                 }
347                                 else if(String::equal(arg,"--version"))
348                                 {
349                                     cout << _cimServerProcess->getVersion() << endl;
350                                     exit(0);
351                                 }
352 kumpf          1.1              // Check for -option
353 mateus.baur    1.17             else if (*arg == '-')
354 kumpf          1.1              {
355                                     // Get the option
356                                     const char* option = arg + 1;
357                     
358                                     //
359                                     // Check to see if user asked for the version (-v option):
360                                     //
361 kumpf          1.3                  if (*option == OPTION_VERSION &&
362                                         strlen(option) == 1)
363 kumpf          1.1                  {
364 mateus.baur    1.17                     cout << _cimServerProcess->getVersion() << endl;
365 kumpf          1.1                      exit(0);
366                                     }
367                                     //
368                                     // Check to see if user asked for help (-h option):
369                                     //
370 kumpf          1.3                  else if (*option == OPTION_HELP &&
371                                             (strlen(option) == 1))
372 kumpf          1.1                  {
373                                         PrintHelp(argv[0]);
374                                         exit(0);
375                                     }
376 mateus.baur    1.17 #if !defined(PEGASUS_USE_RELEASE_DIRS)
377 kumpf          1.3                  else if (*option == OPTION_HOME &&
378                                             (strlen(option) == 1))
379 kumpf          1.1                  {
380                                         if (i + 1 < argc)
381                                         {
382                                             pegasusHome.assign(argv[i + 1]);
383                                         }
384                                         else
385                                         {
386 mateus.baur    1.17                         //l10n
387                                             //cout << "Missing argument for option -" << option << endl;
388                                             String opt(option);
389                                             MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
390                                                              "Missing argument for option -$0",
391                                                              opt);
392                                             cout << MessageLoader::getMessage(parms) << endl;
393 kumpf          1.1                          exit(0);
394                                         }
395                     
396                                         memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
397                                         argc -= 2;
398                                     }
399                     #endif
400                     #if defined(PEGASUS_OS_HPUX)
401                                     //
402                                     // Check to see if user asked for the version (-X option):
403                                     //
404 kumpf          1.3                  if (*option == OPTION_BINDVERBOSE &&
405                                             (strlen(option) == 1))
406 kumpf          1.1                  {
407 h.sterling     1.16             System::bindVerbose = true;
408 mateus.baur    1.17                     //l10n
409                                         //cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
410                                              //<< endl;
411                                         MessageLoaderParms parms("src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
412                                                              "Unsupported debug option, BIND_VERBOSE, enabled.");
413                                         cout << MessageLoader::getMessage(parms) << endl;
414 kumpf          1.1                      // remove the option from the command line
415                                         memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
416                                         argc--;   
417                                     }
418                     #endif
419                                     //
420                                     // Check to see if user asked for shutdown (-s option):
421                                     //
422 kumpf          1.3                  else if (*option == OPTION_SHUTDOWN &&
423                                             (strlen(option) == 1))
424 kumpf          1.1                  {
425                                         //
426                                         // Check to see if shutdown has already been specified:
427                                         //
428                                         if (shutdownOption)
429                                         {
430 mateus.baur    1.17                         //l10n
431                                             //cout << "Duplicate shutdown option specified." << endl;
432                                             MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
433                                                                      "Duplicate shutdown option specified.");
434                                            
435                                             cout << MessageLoader::getMessage(parms) << endl;
436 kumpf          1.1                          exit(0);
437                                         }
438                     
439                                         shutdownOption = true;
440                      
441                                         // remove the option from the command line
442                                         memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
443                                         argc--;   
444                                     }
445                                     else
446 kumpf          1.3                      i++;
447 kumpf          1.1              }
448                                 else
449 kumpf          1.3                  i++;
450 kumpf          1.1          }
451                     
452                         //
453                         // Set the value for pegasusHome property
454                         //
455                         ConfigManager::setPegasusHome(pegasusHome);
456                     
457                         //
458 mateus.baur    1.17     // Do the plaform specific run
459                         //
460                     
461 mateus.baur    1.32     return _cimServerProcess->platform_run(
462                             argc, argv, shutdownOption, debugOutputOption);
463 mateus.baur    1.17 }
464                     
465                     void CIMServerProcess::cimserver_stop()
466                     {
467                         _cimServer->shutdownSignal();
468                     }
469                     
470                     //
471                     // The main, common, running code
472                     //
473                     // NOTE: Do NOT call exit().  Use return(), otherwise some platforms 
474                     // will fail to shutdown properly/cleanly.
475                     //
476                     // TODO: Current change minimal for platform "service" shutdown bug fixes.  
477                     // Perhpas further extract out common stuff and put into main(), put 
478                     // daemon stuff into platform specific platform_run(), etc.  
479                     // Note: make sure to not put error handling stuff that platform 
480                     // specific runs may need to deal with bettter (instead of exit(), etc).
481                     //
482                     
483 mateus.baur    1.32 int CIMServerProcess::cimserver_run(
484                         int argc,
485                         char** argv,
486                         Boolean shutdownOption,
487                         Boolean debugOutputOption)
488 mateus.baur    1.17 {
489 kumpf          1.28     String logsDirectory;
490 mateus.baur    1.17     Boolean daemonOption = false;
491                     
492                         //
493 kumpf          1.1      // Get an instance of the Config Manager.
494                         //
495                         configManager = ConfigManager::getInstance();
496 kumpf          1.10     configManager->useConfigFiles = true;
497 kumpf          1.1  
498                         //
499                         // Get options (from command line and from configuration file); this
500                         // removes corresponding options and their arguments from the command
501                         // line.
502                         //
503                         try
504 ouyang.jian    1.31     { 
505 mateus.baur    1.17         GetOptions(configManager, argc, argv);
506 kumpf          1.1      }
507                         catch (Exception& e)
508                         {
509 mateus.baur    1.17         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
510                                 "src.Server.cimserver.SERVER_NOT_STARTED",
511                                 "cimserver not started:  $0", e.getMessage());
512                     
513                             MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
514                                 "cimserver not started: $0", e.getMessage());
515                     
516                             PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
517                                 << PEGASUS_STD(endl);
518                     
519                             return(1);
520 kumpf          1.1      }
521                     
522 kumpf          1.3  // l10n
523 h.sterling     1.16     // Set the home directory, msg sub-dir, into the MessageLoader.
524                         // This will be the default directory where the resource bundles 
525 mateus.baur    1.17     // are found.    
526                         MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
527                             ConfigManager::getInstance()->getCurrentValue("messageDir")));      
528                     
529 kumpf          1.25     Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
530                             configManager->getCurrentValue("enableHttpConnection"));
531                         Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
532                             configManager->getCurrentValue("enableHttpsConnection"));
533 kumpf          1.2  
534                         // Make sure at least one connection is enabled
535 h.sterling     1.16 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
536 kumpf          1.2      if (!enableHttpConnection && !enableHttpsConnection)
537                         {
538 mateus.baur    1.17         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
539                                 "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
540 kumpf          1.33             "Neither HTTP nor HTTPS connection is enabled.");
541                             MessageLoaderParms parms(
542                                 "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
543                                 "Neither HTTP nor HTTPS connection is enabled.");
544 mateus.baur    1.17         cerr << MessageLoader::getMessage(parms) << endl;
545 kumpf          1.33         return 1;
546 kumpf          1.2      }
547                     #endif
548                     
549 kumpf          1.1      try
550                         {
551                             //
552                             // Check to see if we should Pegasus as a daemon
553                             //
554                     
555 kumpf          1.25         daemonOption = ConfigManager::parseBooleanValue(
556                                 configManager->getCurrentValue("daemon"));
557 ouyang.jian    1.31  
558 kumpf          1.3          logsDirectory = 
559 h.sterling     1.16         ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
560 kumpf          1.1  
561                             // Set up the Logger. This does not open the logs
562                             // Might be more logical to clean before set.
563                             // ATTN: Need tool to completely disable logging.
564                     
565 ouyang.jian    1.31 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
566 kumpf          1.1          Logger::setHomeDirectory(logsDirectory);
567                     #endif
568                     
569                             //
570                             // Check to see if we need to shutdown CIMOM 
571                             //
572                             if (shutdownOption)
573                             {
574                                 String configTimeout = 
575                                     configManager->getCurrentValue("shutdownTimeout");
576 mateus.baur    1.17             Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
577 kumpf          1.30 
578                                 ServerShutdownClient serverShutdownClient(&_serverRunStatus);
579                                 serverShutdownClient.shutdown(timeoutValue);
580 kumpf          1.1  
581 kumpf          1.30             MessageLoaderParms parms(
582                                     "src.Server.cimserver.SERVER_STOPPED",
583                                     "CIM Server stopped.");
584 mateus.baur    1.17 
585                                 cout << MessageLoader::getMessage(parms) << endl;
586                                 return(0);
587 kumpf          1.1          }
588                     
589 kumpf          1.30 #if defined(PEGASUS_DEBUG) && !defined(PEGASUS_USE_SYSLOGS)
590 kumpf          1.1          // Leave this in until people get familiar with the logs.
591 mateus.baur    1.17         MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
592                                                      "Logs Directory = ");
593                             cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
594 kumpf          1.1  #endif
595                         }
596 kumpf          1.5      catch (UnrecognizedConfigProperty& e)
597 kumpf          1.1      {
598 mateus.baur    1.17     //l10n
599                         //cout << "Error: " << e.getMessage() << endl;
600                         MessageLoaderParms parms("src.Server.cimserver.ERROR",
601                                                  "Error: $0",
602                                                  e.getMessage());
603                         cout << MessageLoader::getMessage(parms) << endl;
604 kumpf          1.1      }
605                     
606 mateus.baur    1.17     // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.
607                         // 1) If the user explicitly specified a port, use it.
608                         // 2) If the user did not specify a port, get the port from the services file.
609                         // 3) If no value is specified in the services file, use the IANA WBEM default port.
610                         // Note that 2 and 3 are done within the System::lookupPort method
611                         // An empty string from the ConfigManager implies that the user did not specify a port.
612                     
613                         Uint32 portNumberHttps=0;
614                         Uint32 portNumberHttp=0;
615                         Uint32 portNumberExportHttps=0;
616 kumpf          1.1  
617 kumpf          1.2      if (enableHttpsConnection)
618 kumpf          1.1      {
619 kumpf          1.2          String httpsPort = configManager->getCurrentValue("httpsPort");
620 mateus.baur    1.17         if (httpsPort == String::EMPTY)
621                             {
622                                 //
623                                 // Look up the WBEM-HTTPS port number
624                                 //
625                                 portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
626                     
627                             } else
628                             {        
629                                 //
630                                 // user-specified
631                                 //
632                                 CString portString = httpsPort.getCString();
633                                 char* end = 0;
634                                 portNumberHttps = strtol(portString, &end, 10);
635                                 if(!(end != 0 && *end == '\0'))
636                                 {
637 mateus.baur    1.18                 InvalidPropertyValue e("httpsPort", httpsPort);
638                                     cerr << e.getMessage() << endl;
639 mateus.baur    1.17                 exit(1);
640                                 }
641                             }
642 kumpf          1.1      }
643 kumpf          1.2  
644                         if (enableHttpConnection)
645 kumpf          1.1      {
646 kumpf          1.2          String httpPort = configManager->getCurrentValue("httpPort");
647 mateus.baur    1.17         if (httpPort == String::EMPTY)
648                             {
649                                 //
650                                 // Look up the WBEM-HTTP port number
651                                 //
652                                 portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
653 kumpf          1.1  
654 mateus.baur    1.17         } else
655                             {
656                                 //
657                                 // user-specified
658                                 //
659                                 CString portString = httpPort.getCString();
660                                 char* end = 0;
661                                 portNumberHttp = strtol(portString, &end, 10);
662                                 if(!(end != 0 && *end == '\0'))
663                                 {
664 mateus.baur    1.18                 InvalidPropertyValue e("httpPort", httpPort);
665                                     cerr << e.getMessage() << endl;
666 mateus.baur    1.17                 exit(1);
667                                 }
668                             }
669 kumpf          1.1      }
670                     
671 mateus.baur    1.17 #if defined(PEGASUS_DEBUG)
672 kumpf          1.1      // Put out startup up message.
673 kumpf          1.33     cout << _cimServerProcess->getProductName() << " " <<
674                             _cimServerProcess->getVersion() << endl;
675 mateus.baur    1.17 #endif
676                     
677 kumpf          1.33     // reset message loading to NON-process locale
678                         MessageLoader::_useProcessLocale = false; 
679 kumpf          1.3  
680 mateus.baur    1.17     // Get the parent's PID before forking
681 kumpf          1.30     _serverRunStatus.setParentPid(System::getPID());
682 mateus.baur    1.17     
683 kumpf          1.1      // do we need to run as a daemon ?
684                         if (daemonOption)
685                         {
686 mateus.baur    1.17         if(-1 == _cimServerProcess->cimserver_fork())
687                         {
688                             return(-1);
689 h.sterling     1.16     }
690 kumpf          1.1      }
691                     
692 mateus.baur    1.17 // l10n
693                         // Now we are after the fork...
694                         // Create a dummy Thread object that can be used to store the
695 kumpf          1.22     // AcceptLanguageList object for CIM requests that are serviced
696 mateus.baur    1.17     // by this thread (initial thread of server).  Need to do this
697                         // because this thread is not in a ThreadPool, but is used
698                         // to service CIM requests.
699                         // The run function for the dummy Thread should never be called,
700                         Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
701                         Thread::setCurrent(dummyInitialThread); 
702 kumpf          1.22     AcceptLanguageList default_al;
703 mateus.baur    1.17     try{
704 kumpf          1.21          default_al = LanguageParser::getDefaultAcceptLanguages();   
705 kumpf          1.22          Thread::setLanguages(new AcceptLanguageList(default_al));
706 mateus.baur    1.17     }catch(InvalidAcceptLanguageHeader& e){
707                               Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
708                                       "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
709                                       "Could not convert the system process locale into a valid AcceptLanguage format.");  
710                               Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
711                                                  e.getMessage()); 
712                         }
713                         
714                     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
715                     || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
716 jim.wunderlich 1.19 || defined(PEGASUS_OS_SOLARIS) || defined (PEGASUS_OS_VMS)
717 kumpf          1.1      umask(S_IWGRP|S_IWOTH);
718 kumpf          1.2  
719                         //
720                         // check if CIMServer is already running
721                         // if CIMServer is already running, print message and 
722                         // notify parent process (if there is a parent process) to terminate
723                         //
724 kumpf          1.30     if (_serverRunStatus.isServerRunning())
725 kumpf          1.2      {
726 kumpf          1.30         MessageLoaderParms parms(
727                                 "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
728                                 "Unable to start CIMServer.\nCIMServer is already running.");
729                             PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
730                                 PEGASUS_STD(endl);
731 kumpf          1.2  
732 kumpf          1.30         //
733 kumpf          1.2          // notify parent process (if there is a parent process) to terminate
734                             //
735                             if (daemonOption)
736 kumpf          1.30         {
737                                 _cimServerProcess->notify_parent(1);
738                             }
739 kumpf          1.2  
740 kumpf          1.30         return 1;
741 kumpf          1.2      }
742                          
743 kumpf          1.1  #endif
744                     
745                         // try loop to bind the address, and run the server
746                         try
747                         {
748 kumpf          1.30         _monitor  = new Monitor();
749                             _cimServer = new CIMServer(_monitor);
750 mateus.baur    1.17 
751 kumpf          1.2  
752                             if (enableHttpConnection)
753                             {
754 mateus.baur    1.32             _cimServer->addAcceptor(false, portNumberHttp, false);
755 kumpf          1.30 
756                                 Logger::put_l(
757                                     Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
758                                     "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
759                                     "Listening on HTTP port $0.", portNumberHttp);
760 kumpf          1.2          }
761 kumpf          1.30 
762 kumpf          1.2          if (enableHttpsConnection)
763                             {
764 mateus.baur    1.32             _cimServer->addAcceptor(false, portNumberHttps, true);
765 kumpf          1.30 
766                                 Logger::put_l(
767                                     Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
768                                     "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
769                                     "Listening on HTTPS port $0.", portNumberHttps);
770 mateus.baur    1.17         }
771 kumpf          1.9  
772 h.sterling     1.16 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
773 mateus.baur    1.17         _cimServer->addAcceptor(true, 0, false, false);
774 kumpf          1.30         Logger::put_l(
775                                 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
776                                 "src.Server.cimserver.LISTENING_ON_LOCAL",
777                                 "Listening on local connection socket.");
778 kumpf          1.1  #endif
779                     
780 mateus.baur    1.17 #if defined(PEGASUS_DEBUG)
781 kumpf          1.2          if (enableHttpConnection)
782                             {
783 kumpf          1.30             MessageLoaderParms parms(
784                                     "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
785                                     "Listening on HTTP port $0.", portNumberHttp);
786 mateus.baur    1.17             cout << MessageLoader::getMessage(parms) << endl;
787 kumpf          1.2          }
788                             if (enableHttpsConnection)
789                             {
790 kumpf          1.30             MessageLoaderParms parms(
791                                     "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
792                                     "Listening on HTTPS port $0.", portNumberHttps);
793 mateus.baur    1.17             cout << MessageLoader::getMessage(parms) << endl;
794                             }
795 kumpf          1.9  
796 h.sterling     1.16 # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
797 kumpf          1.30         MessageLoaderParms parms(
798                                 "src.Server.cimserver.LISTENING_ON_LOCAL",
799                                 "Listening on local connection socket.");
800 mateus.baur    1.17         cout << MessageLoader::getMessage(parms) << endl;
801 kumpf          1.3  # endif
802 kumpf          1.1  #endif
803                     
804 kumpf          1.3          // bind throws an exception if the bind fails
805 mateus.baur    1.18         try { 
806 kumpf          1.30             _cimServer->bind();
807                     	}
808                             catch (const BindFailedException &e)
809 mateus.baur    1.18 	{
810                     #ifdef PEGASUS_DEBUG
811                             MessageLoaderParms parms("src.Server.cimserver.BIND_FAILED",
812                                      "Could not bind: $0.", e.getMessage());
813                             cout << MessageLoader::getMessage(parms) << endl;
814                     #endif
815                             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
816                                 "src.Server.cimserver.BIND.FAILED",
817                                 "Could not bind:  $0", e.getMessage());
818 kumpf          1.1  
819 mateus.baur    1.18 	   deleteCIMServer();
820                     	   return 1;
821                     	}
822 kumpf          1.30         // notify parent process (if there is a parent process) to terminate 
823 kumpf          1.3          // so user knows that there is cimserver ready to serve CIM requests.
824 kumpf          1.30         if (daemonOption)
825                             {
826                                 _cimServerProcess->notify_parent(0);
827                             }
828 kumpf          1.2  
829 kumpf          1.30 #if defined(PEGASUS_OS_HPUX) || \
830                         defined(PEGASUS_OS_LINUX) || \
831                         defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || \
832                         defined(PEGASUS_OS_AIX) || \
833                         defined(PEGASUS_OS_SOLARIS) || \
834                         defined(PEGASUS_OS_VMS)
835 kumpf          1.1          //
836                             // create a file to indicate that the cimserver has started and
837                             // save the process id of the cimserver process in the file
838                             //
839 kumpf          1.30         _serverRunStatus.setServerRunning();
840 kumpf          1.1  #endif
841 kumpf          1.3  
842 mateus.baur    1.17 #if defined(PEGASUS_DEBUG)
843 h.sterling     1.16     cout << "Started. " << endl;
844 kumpf          1.1  #endif
845 mateus.baur    1.17     
846 kumpf          1.1          // Put server started message to the logger
847 mateus.baur    1.17         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
848                                 Logger::INFORMATION,
849                                 "src.Server.cimserver.STARTED_VERSION",
850                                 "Started $0 version $1.",
851                                 _cimServerProcess->getProductName(), _cimServerProcess->getVersion());
852 kumpf          1.1  
853 kumpf          1.3          //
854 kumpf          1.1          // Loop to call CIMServer's runForever() method until CIMServer
855                             // has been shutdown
856                             //
857 mateus.baur    1.17     while( !_cimServer->terminated() )
858 h.sterling     1.16     {
859 mateus.baur    1.17 
860                           _cimServer->runForever();
861                     
862 h.sterling     1.16     }
863 kumpf          1.1  
864                             //
865                             // normal termination
866 mateus.baur    1.17         //
867 kumpf          1.12 
868 kumpf          1.1          // Put server shutdown message to the logger
869 mateus.baur    1.17         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
870                                 Logger::INFORMATION, "src.Server.cimserver.STOPPED",
871                                 "$0 stopped.", _cimServerProcess->getProductName());
872 kumpf          1.1      }
873 kumpf          1.33     catch (Exception& e)
874 kumpf          1.1      {
875 kumpf          1.33         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
876 mateus.baur    1.17             "src.Server.cimserver.ERROR",
877                                 "Error: $0", e.getMessage());  
878 kumpf          1.2  
879 kumpf          1.33         MessageLoaderParms parms("src.Server.cimserver.ERROR",
880                                                      "Error: $0", e.getMessage());
881                             PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
882                                 PEGASUS_STD(endl);
883 mateus.baur    1.17 
884 kumpf          1.33         //
885 kumpf          1.3          // notify parent process (if there is a parent process) to terminate
886 kumpf          1.2          //
887                             if (daemonOption)
888 mateus.baur    1.17                 _cimServerProcess->notify_parent(1);
889 kumpf          1.2  
890 mateus.baur    1.17         deleteCIMServer();
891 kumpf          1.1          return 1;
892                         }
893                     
894 mateus.baur    1.17     deleteCIMServer();
895 kumpf          1.1      return 0;
896                     }
897 mateus.baur    1.17 

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2