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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2