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

   1 karl  1.14 //%2005////////////////////////////////////////////////////////////////////////
   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 kumpf 1.1  //
  12            // Permission is hereby granted, free of charge, to any person obtaining a copy
  13            // of this software and associated documentation files (the "Software"), to
  14            // deal in the Software without restriction, including without limitation the
  15            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  16            // sell copies of the Software, and to permit persons to whom the Software is
  17            // furnished to do so, subject to the following conditions:
  18            // 
  19            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  20            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  21            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  22            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  23            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  24            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  25            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27            //
  28            //==============================================================================
  29            //
  30            // Author: Mike Brasher (mbrasher@bmc.com)
  31            //
  32 kumpf 1.1  // Modified By: Mike Day (mdday@us.ibm.com) 
  33            //
  34 h.sterling 1.16 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
  35 kumpf      1.1  //
  36                 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
  37                 //
  38                 // Modified By: Jenny Yu (jenny_yu@hp.com)
  39                 //
  40                 // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
  41 kumpf      1.2  //              Carol Ann Krug Graves, Hewlett-Packard Company
  42                 //                (carolann_graves@hp.com)
  43 h.sterling 1.16 //      Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
  44 kumpf      1.1  //
  45 kumpf      1.3  // Modified By: Dave Rosckes (rosckes@us.ibm.com)
  46                 //
  47                 // Modified By: Humberto Rivero (hurivero@us.ibm.com)
  48                 //
  49 mateus.baur 1.17 // Modified By: Steve Hills (steve.hills@ncr.com)
  50                  //              Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com)
  51                  //
  52                  // Modified By: Amit K Arora, IBM (amitarora@in.ibm.com) - pep 167
  53                  //
  54                  // Modified By: Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2555
  55                  //
  56                  // Modified By: Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2032
  57                  //
  58                  // Modified By: Heather Sterling, IBM (hsterl@us.ibm.com) - PEP#222
  59 kumpf       1.3  //
  60 kumpf       1.1  //%/////////////////////////////////////////////////////////////////////////////
  61                  
  62                  
  63                  //////////////////////////////////////////////////////////////////////
  64                  //
  65                  // Notes on deamon operation (Unix) and service operation (Win 32):
  66                  //
  67                  // To run pegasus as a daemon on Unix platforms: 
  68                  //
  69                  // cimserver
  70                  //
  71                  // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
  72                  // property to false:
  73                  //
  74                  // cimserver daemon=false
  75                  //
  76                  // The daemon config property has no effect on windows operation. 
  77                  //
  78                  // To shutdown pegasus, use the -s option:
  79                  // 
  80                  // cimserver -s 
  81 kumpf       1.1  //
  82                  // To run pegasus as an NT service, there are FOUR  different possibilities:
  83                  //
  84                  // To INSTALL the Pegasus service, 
  85                  //
  86                  // cimserver -install
  87                  //
  88                  // To REMOVE the Pegasus service, 
  89                  //
  90                  // cimserver -remove
  91                  //
  92                  // To START the Pegasus service, 
  93                  //
  94                  // net start cimserver
  95 mateus.baur 1.17 // or
  96                  // cimserver -start
  97 kumpf       1.1  //
  98                  // To STOP the Pegasus service, 
  99                  //
 100                  // net stop cimserver
 101 mateus.baur 1.17 // or
 102                  // cimserver -stop
 103 kumpf       1.1  //
 104                  // Alternatively, you can use the windows service manager. Pegasus shows up 
 105                  // in the service database as "Pegasus CIM Object Manager"
 106                  //
 107                  // Mike Day, mdday@us.ibm.com
 108                  // 
 109                  //////////////////////////////////////////////////////////////////////
 110                  
 111                  
 112                  #include <Pegasus/Common/Config.h>
 113                  #include <Pegasus/Common/Constants.h>
 114                  #include <iostream>
 115                  #include <cassert>
 116                  #include <cstdlib>
 117                  #include <fstream>
 118                  #include <Pegasus/Common/FileSystem.h>
 119                  #include <Pegasus/Common/Monitor.h>
 120                  #include <Pegasus/Common/PegasusVersion.h>
 121                  #include <Pegasus/Common/Logger.h>
 122                  #include <Pegasus/Common/System.h>
 123                  #include <Pegasus/Common/Tracer.h>
 124 kumpf       1.1  #include <Pegasus/Config/ConfigManager.h>
 125                  #include <Pegasus/Client/CIMClient.h>
 126                  #include <Pegasus/Server/ShutdownService.h>
 127 mateus.baur 1.17 #include <Pegasus/Server/CIMServer.h>
 128                  #include <Service/ServerProcess.h>
 129                  
 130                  #if defined(PEGASUS_OS_OS400)
 131                  #  include "vfyptrs.cinc"
 132                  #  include "OS400ConvertChar.h"
 133                  #endif
 134                  
 135                  PEGASUS_USING_PEGASUS;
 136                  PEGASUS_USING_STD;
 137 kumpf       1.1  
 138 mateus.baur 1.17 #define PEGASUS_PROCESS_NAME "WMI Mapper";
 139 kumpf       1.3  
 140 mateus.baur 1.17 //Windows service variables are not defined elsewhere in the product
 141                  //enable ability to override these
 142                  #ifndef PEGASUS_SERVICE_NAME
 143                  #define PEGASUS_SERVICE_NAME "Pegasus WMI Mapper";
 144 kumpf       1.1  #endif
 145 mateus.baur 1.17 #ifndef PEGASUS_SERVICE_DESCRIPTION
 146                  #define PEGASUS_SERVICE_DESCRIPTION "Pegasus WMI Mapper Service";
 147 kumpf       1.1  #endif
 148                  
 149 mateus.baur 1.17 class CIMServerProcess : public ServerProcess
 150                  {
 151                  public:
 152                  
 153                      CIMServerProcess(void)
 154                      {
 155                          cimserver_set_process(this);
 156                      }
 157                  
 158                      virtual ~CIMServerProcess(void)
 159                      {
 160                      }
 161                  
 162                      //defined in PegasusVersion.h
 163                      virtual const char* getProductName() const
 164                      {
 165                          return PEGASUS_PRODUCT_NAME;
 166                      }
 167                  
 168                      virtual const char* getExtendedName() const
 169                      {
 170 mateus.baur 1.17         return PEGASUS_SERVICE_NAME;
 171                      }
 172                  
 173                      virtual const char* getDescription() const
 174                      {
 175                          return PEGASUS_SERVICE_DESCRIPTION;
 176                      }
 177                      
 178                      //defined in PegasusVersion.h
 179                      virtual const char* getVersion() const
 180                      {
 181                          return PEGASUS_PRODUCT_VERSION;
 182                      }
 183                  
 184                      virtual const char* getProcessName() const
 185                      {
 186                          return PEGASUS_PROCESS_NAME;
 187                      }
 188                  
 189                      //defined in ConfigFileDir.h
 190                      virtual const char* getPIDFileName() const
 191 mateus.baur 1.17     {
 192                          return CIMSERVER_START_FILE;
 193                      }
 194                  
 195                      int cimserver_run(int argc, char** argv, bool shutdownOption);
 196                  
 197                      void cimserver_stop(void);
 198                  };
 199                  
 200                  AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
 201                  static CIMServer* _cimServer = 0;
 202 mateus.baur 1.18 static Monitor* _monitor = 0;
 203 kumpf       1.1  
 204                  //
 205                  //  The command name.
 206                  //
 207                  static const char COMMAND_NAME []    = "cimserver";
 208                  
 209                  //
 210                  //  The constant defining usage string.
 211                  //
 212                  static const char USAGE []           = "Usage: ";
 213                  
 214                  /**
 215                  Constants representing the command line options.
 216                  */
 217                  static const char OPTION_VERSION     = 'v';
 218                  
 219                  static const char OPTION_HELP        = 'h';
 220                  
 221                  static const char OPTION_HOME        = 'D';
 222                  
 223                  static const char OPTION_SHUTDOWN    = 's';
 224 kumpf       1.1  
 225 mateus.baur 1.17 static const char   LONG_HELP []  = "help";
 226 kumpf       1.3  
 227 mateus.baur 1.17 static const char   LONG_VERSION []  = "version";
 228 kumpf       1.3  
 229 kumpf       1.1  #if defined(PEGASUS_OS_HPUX)
 230                  static const char OPTION_BINDVERBOSE = 'X';
 231                  #endif
 232                  
 233                  static const String PROPERTY_TIMEOUT = "shutdownTimeout";
 234                  
 235                  ConfigManager*    configManager;
 236                  
 237                  /** GetOptions function - This function defines the Options Table
 238                      and sets up the options from that table using the config manager.
 239                  */
 240                  void GetOptions(
 241                      ConfigManager* cm,
 242                      int& argc,
 243 mateus.baur 1.17     char** argv)
 244 kumpf       1.1  {
 245                      try
 246                      {
 247                          cm->mergeConfigFiles();
 248                  
 249                          cm->mergeCommandLine(argc, argv);
 250                      }
 251 kumpf       1.5      catch (NoSuchFile&)
 252 kumpf       1.1      {
 253 kumpf       1.5          throw;
 254 kumpf       1.1      }
 255 kumpf       1.5      catch (FileNotReadable&)
 256 kumpf       1.1      {
 257 kumpf       1.5          throw;
 258 kumpf       1.1      }
 259 kumpf       1.5      catch (CannotRenameFile&)
 260 kumpf       1.1      {
 261 kumpf       1.5          throw;
 262 kumpf       1.1      }
 263 kumpf       1.5      catch (ConfigFileSyntaxError&)
 264 kumpf       1.1      {
 265 kumpf       1.5          throw;
 266 kumpf       1.1      }
 267 kumpf       1.5      catch(UnrecognizedConfigProperty&)
 268 kumpf       1.1      {
 269 kumpf       1.5          throw;
 270 kumpf       1.1      }
 271 kumpf       1.5      catch(InvalidPropertyValue&)
 272 kumpf       1.1      {
 273 kumpf       1.5          throw;
 274 kumpf       1.1      }
 275 mateus.baur 1.17     catch (CannotOpenFile&)
 276                      {
 277                          throw;
 278                      }
 279 kumpf       1.1  }
 280                  
 281                  /* PrintHelp - This is temporary until we expand the options manager to allow
 282                     options help to be defined with the OptionRow entries and presented from
 283                     those entries.
 284                  */
 285                  void PrintHelp(const char* arg0)
 286                  {
 287                      String usage = String (USAGE);
 288                      usage.append (COMMAND_NAME);
 289                      usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
 290                      usage.append ("  options\n");
 291 mateus.baur 1.17     usage.append ("    -v, --version   - displays CIM Server version number\n");
 292                      usage.append ("    -h, --help      - prints this help message\n");
 293 kumpf       1.3      usage.append ("    -s              - shuts down CIM Server\n");
 294 mateus.baur 1.17 #if !defined(PEGASUS_USE_RELEASE_DIRS)
 295 kumpf       1.3      usage.append ("    -D [home]       - sets pegasus home directory\n");
 296 kumpf       1.1  #endif
 297                  #if defined(PEGASUS_OS_TYPE_WINDOWS)
 298 mateus.baur 1.17     usage.append ("    -install [name] - installs pegasus as a Windows Service\n");
 299 kumpf       1.3      usage.append ("                      [name] is optional and overrides the\n");
 300                      usage.append ("                      default CIM Server Service Name\n");
 301 mateus.baur 1.17     usage.append ("    -remove [name]  - removes pegasus as a Windows Service\n");
 302 kumpf       1.3      usage.append ("                      [name] is optional and overrides the\n");
 303                      usage.append ("                      default CIM Server Service Name\n");
 304 mateus.baur 1.17     usage.append ("    -start [name]   - starts pegasus as a Windows Service\n");
 305 kumpf       1.3      usage.append ("                      [name] is optional and overrides the\n");
 306                      usage.append ("                      default CIM Server Service Name\n");
 307 mateus.baur 1.17     usage.append ("    -stop [name]    - stops pegasus as a Windows Service\n");
 308 kumpf       1.3      usage.append ("                      [name] is optional and overrides the\n");
 309                      usage.append ("                      default CIM Server Service Name\n\n");
 310 kumpf       1.1  #endif
 311                      usage.append ("  configProperty=value\n");
 312 kumpf       1.3      usage.append ("                    - sets CIM Server configuration property\n");
 313 kumpf       1.1  
 314                      cout << endl;
 315 mateus.baur 1.17     cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;
 316 kumpf       1.1      cout << endl;
 317 mateus.baur 1.17     
 318                  #if defined(PEGASUS_OS_TYPE_WINDOWS)
 319                      MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
 320                  #elif defined(PEGASUS_USE_RELEASE_DIRS)
 321                      MessageLoaderParms parms("src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);
 322                  #else
 323                      MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
 324                  #endif
 325                      cout << MessageLoader::getMessage(parms) << endl;
 326                  }
 327                  
 328                  //This needs to be called at various points in the code depending on the platform and error conditions.
 329                  //We need to delete the _cimServer reference on exit in order for the destructors to get called.
 330                  void deleteCIMServer()
 331                  {
 332                      if (_cimServer)
 333                      {
 334                          delete _cimServer;
 335                          _cimServer = 0;
 336                      }
 337 mateus.baur 1.18 
 338                  	if (_monitor)
 339                  	{
 340                  		delete _monitor;
 341                  	}
 342 kumpf       1.1  }
 343                  
 344 mateus.baur 1.17 // l10n
 345 kumpf       1.3  //
 346 mateus.baur 1.17 // Dummy function for the Thread object associated with the initial thread.
 347                  // Since the initial thread is used to process CIM requests, this is
 348                  // needed to localize the exceptions thrown during CIM request processing.
 349                  // Note: This function should never be called! 
 350                  // 
 351                  PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
 352                  {
 353                     return((PEGASUS_THREAD_RETURN)0);    
 354 kumpf       1.3  }
 355                  
 356 kumpf       1.1  void shutdownCIMOM(Uint32 timeoutValue)
 357                  {
 358                      //
 359                      // Create CIMClient object
 360                      //
 361                      CIMClient client;
 362                  
 363                      //
 364                      // Get local host name
 365                      //
 366                      String hostStr = System::getHostName();
 367                  
 368                      //
 369                      // open connection to CIMOM 
 370                      //
 371                      try
 372                      {
 373                          client.connectLocal();
 374                  
 375                          //
 376                          // set client timeout to 2 seconds
 377 kumpf       1.1          //
 378                          client.setTimeout(2000);
 379                      }
 380 mateus.baur 1.17     catch(Exception&)
 381 kumpf       1.1      {
 382 kumpf       1.3  #ifdef PEGASUS_OS_OS400
 383 mateus.baur 1.17     //l10n
 384                      //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 385                              //"Unable to connect to CIM Server.  CIM Server may not be running." );
 386                      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 387                              "src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
 388 h.sterling  1.16             "Unable to connect to CIM Server.  CIM Server may not be running." );
 389                      // The server job may still be active but not responding.
 390                      // Kill the job if it exists.
 391 mateus.baur 1.17     if(_cimServerProcess->cimserver_kill(0) == -1)
 392                         _cimServerProcess->cimserver_exitRC(2);
 393                      _cimServerProcess->cimserver_exitRC(1);
 394 kumpf       1.3  #else
 395 mateus.baur 1.17         //l10n
 396                          //PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
 397                          //PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
 398                          MessageLoaderParms parms("src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
 399                                                                           "Unable to connect to CIM Server.\nCIM Server may not be running.\n");
 400                          PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
 401                          exit(1);
 402 kumpf       1.1  #endif
 403                      }
 404                  
 405                      try
 406                      {
 407                          //
 408                          // construct CIMObjectPath
 409                          //
 410                          String referenceStr = "//";
 411                          referenceStr.append(hostStr);
 412 kumpf       1.2          referenceStr.append("/");  
 413                          referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
 414 kumpf       1.1          referenceStr.append(":");
 415 kumpf       1.2          referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
 416 kumpf       1.1          CIMObjectPath reference(referenceStr);
 417                  
 418                          //
 419                          // issue the invokeMethod request on the shutdown method
 420                          //
 421                          Array<CIMParamValue> inParams;
 422                          Array<CIMParamValue> outParams;
 423                  
 424                          // set force option to true for now
 425                          inParams.append(CIMParamValue("force",
 426                              CIMValue(Boolean(true))));
 427                  
 428                          inParams.append(CIMParamValue("timeout",
 429                              CIMValue(Uint32(timeoutValue))));
 430                  
 431                          CIMValue retValue = client.invokeMethod(
 432                              PEGASUS_NAMESPACENAME_SHUTDOWN,
 433                              reference,
 434                              "shutdown",
 435                              inParams,
 436                              outParams);
 437 kumpf       1.1      }
 438                      catch(CIMException& e)
 439                      {
 440 kumpf       1.3  #ifdef PEGASUS_OS_OS400
 441                  
 442 h.sterling  1.16     if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 443                      {
 444 mateus.baur 1.17         //l10n
 445                          //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 446                              //"Failed to shutdown server: $0", "The repository may be empty.");
 447                          Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 448                              "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
 449                              "Error in server shutdown: The repository may be empty.");
 450 h.sterling  1.16     }
 451                      else
 452                      {
 453 mateus.baur 1.17         //l10n
 454                          //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 455                              //"Failed to shutdown server: $0", e.getMessage());
 456                          Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 457                              "src.Server.cimserver.SHUTDOWN_FAILED",
 458                              "Error in server shutdown: $0", e.getMessage());
 459 h.sterling  1.16     }
 460                      // Kill the server job.
 461 mateus.baur 1.17     if(_cimServerProcess->cimserver_kill(0) == -1)
 462                         _cimServerProcess->cimserver_exitRC(2);
 463 kumpf       1.3  #else
 464 mateus.baur 1.17         //l10n - TODO
 465                          MessageLoaderParms parms("src.Server.cimserver.SHUTDOWN_FAILED",
 466                                                   "Error in server shutdown: ");
 467                          PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
 468 kumpf       1.1          if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 469                          {
 470 mateus.baur 1.17             //
 471                              // Repository may be empty.  
 472                              //
 473                              //l10n - TODO
 474                              Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 475                                  "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
 476                                  "Error in server shutdown: The repository may be empty.");
 477                              MessageLoaderParms parms("src.Server.cimserver.REPOSITORY_EMPTY",
 478                                                       "The repository may be empty.");
 479                              PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
 480 kumpf       1.1          }
 481                          else
 482                          {
 483 mateus.baur 1.17             //l10n - TODO
 484                              Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 485                                  "src.Server.cimserver.SHUTDOWN_FAILED",
 486                                  "Error in server shutdown: $0", e.getMessage());
 487 kumpf       1.1              PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
 488                          }
 489 mateus.baur 1.17 
 490                      // Kill the cimserver process 
 491                      if (_cimServerProcess->cimserver_kill(0) == 0)
 492                          {
 493                              //l10n - TODO
 494                              Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 495                                  "src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
 496                              "Forced shutdown initiated.");
 497                              MessageLoaderParms parms("src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
 498                                                       "Forced shutdown initiated.");
 499                              PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
 500                          }
 501                          exit(1);
 502 kumpf       1.1  #endif
 503                      }
 504 mateus.baur 1.17     catch(Exception&)
 505 kumpf       1.1      {
 506                          //
 507 kumpf       1.3          // This may mean that the CIM Server has terminated, causing this
 508                          // client to get a "Empty HTTP response message" exception.  It may
 509                          // also mean that the CIM Server is taking longer than 2 seconds 
 510                          // (client timeout value) to terminate, causing this client to 
 511                          // timeout with a "connection timeout" exception.
 512 kumpf       1.1          //
 513 kumpf       1.3          // Check to see if CIM Server is still running.  If CIM Server
 514 kumpf       1.1          // is still running and the shutdown timeout has not expired,
 515 kumpf       1.3          // loop and wait one second until either the CIM Server is
 516                          // terminated or timeout expires.  If timeout expires and
 517                          // the CIM Server is still running, kill the CIMServer process.
 518                          // 
 519 kumpf       1.1          Uint32 maxWaitTime = timeoutValue - 2;
 520 mateus.baur 1.17         Boolean running = _cimServerProcess->isCIMServerRunning();
 521 kumpf       1.1          while ( running && maxWaitTime > 0 )
 522                          {
 523                              System::sleep(1);
 524 mateus.baur 1.17             running = _cimServerProcess->isCIMServerRunning();
 525 kumpf       1.1              maxWaitTime = maxWaitTime - 1;
 526                          }
 527                  
 528                          if (running)
 529                          {
 530 mateus.baur 1.17        int kill_rc = _cimServerProcess->cimserver_kill(0);
 531                         
 532 kumpf       1.3  #ifdef PEGASUS_OS_OS400
 533 h.sterling  1.16         if(kill_rc == -1)
 534 mateus.baur 1.17         _cimServerProcess->cimserver_exitRC(2);
 535                          _cimServerProcess->cimserver_exitRC(1);
 536 kumpf       1.3  #endif
 537                  
 538 mateus.baur 1.17 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
 539                  || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) \
 540                  || defined (PEGASUS_OS_VMS)
 541 h.sterling  1.16         if (kill_rc != -1)
 542 kumpf       1.3              {
 543 mateus.baur 1.17                 //l10n - TODO
 544                                  Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 545                                      "src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 546                                      "Shutdown timeout expired.  Forced shutdown initiated.");
 547                                  MessageLoaderParms parms("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 548                                      "Shutdown timeout expired.  Forced shutdown initiated.");
 549                                  cout << MessageLoader::getMessage(parms) << endl;
 550 kumpf       1.3                  exit(0);
 551                              }
 552                  #endif
 553 kumpf       1.1          }
 554                      }
 555                  
 556                      return;
 557                  }
 558                  
 559                  
 560                  /////////////////////////////////////////////////////////////////////////
 561                  //  MAIN
 562                  //////////////////////////////////////////////////////////////////////////
 563                  int main(int argc, char** argv)
 564                  {
 565                      String pegasusHome  = String::EMPTY;
 566                      Boolean shutdownOption = false;
 567 mateus.baur 1.17 
 568                  //l10n
 569                  // Set Message loading to process locale
 570                  MessageLoader::_useProcessLocale = true; 
 571                  //l10n
 572                  
 573                  //l10n
 574                  #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
 575                  setlocale(LC_ALL, "");
 576                  #endif
 577 kumpf       1.1  
 578                  #ifdef PEGASUS_OS_OS400
 579 mateus.baur 1.17 
 580                    VFYPTRS_INCDCL;               // VFYPTRS local variables
 581                  
 582                    // verify pointers
 583                    #pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\
 584                      0,_C2_MH_ESCAPE)
 585                      for( int arg_index = 1; arg_index < argc; arg_index++ ){
 586                      VFYPTRS(VERIFY_SPP_NULL(argv[arg_index]));
 587                      }
 588                    #pragma disable_handler
 589                  
 590                      // Convert the args to ASCII
 591                      for(Uint32 i = 0;i< argc;++i)
 592                      {
 593                      EtoA(argv[i]);
 594                      }
 595                  
 596 kumpf       1.1      // Initialize Pegasus home to the shipped OS/400 directory.
 597                      pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
 598                  #endif
 599                  
 600 mateus.baur 1.17 
 601 kumpf       1.3  #ifndef PEGASUS_OS_TYPE_WINDOWS
 602 kumpf       1.1      //
 603                      // Get environment variables:
 604                      //
 605 mateus.baur 1.17 #ifdef PEGASUS_OS_OS400
 606                  #pragma convert(37)
 607                      const char* tmp = getenv("PEGASUS_HOME");
 608                  #pragma convert(0)
 609                      char home[256] = {0};
 610                      if (tmp && strlen(tmp) < 256)
 611                      {
 612                      strcpy(home, tmp);
 613                      EtoA(home);
 614                      pegasusHome = home;
 615                      }
 616                  #else
 617                    #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
 618                      pegasusHome = AIX_RELEASE_PEGASUS_HOME;
 619                    #elif !defined(PEGASUS_USE_RELEASE_DIRS)
 620 kumpf       1.1      const char* tmp = getenv("PEGASUS_HOME");
 621                  
 622                      if (tmp)
 623                      {
 624                          pegasusHome = tmp;
 625                      }
 626 mateus.baur 1.17   #endif
 627                  #endif
 628 kumpf       1.1  
 629                      FileSystem::translateSlashes(pegasusHome);
 630 kumpf       1.3  #else
 631 kumpf       1.1  
 632 kumpf       1.3    // windows only
 633 mateus.baur 1.17   //setHome(pegasusHome);
 634                    pegasusHome = _cimServerProcess->getHome();
 635 kumpf       1.3  #endif
 636 kumpf       1.1  
 637                          // Get help, version, and shutdown options
 638 kumpf       1.3  
 639 kumpf       1.1          for (int i = 1; i < argc; )
 640                          {
 641                              const char* arg = argv[i];
 642 mateus.baur 1.17             if(String::equal(arg,"--help"))
 643                              {
 644                                      PrintHelp(argv[0]);
 645                                      exit(0);
 646                              }
 647                              else if(String::equal(arg,"--version"))
 648                              {
 649                                  cout << _cimServerProcess->getVersion() << endl;
 650                                  exit(0);
 651                              }
 652 kumpf       1.1              // Check for -option
 653 mateus.baur 1.17             else if (*arg == '-')
 654 kumpf       1.1              {
 655                                  // Get the option
 656                                  const char* option = arg + 1;
 657                  
 658                                  //
 659                                  // Check to see if user asked for the version (-v option):
 660                                  //
 661 kumpf       1.3                  if (*option == OPTION_VERSION &&
 662                                      strlen(option) == 1)
 663 kumpf       1.1                  {
 664 mateus.baur 1.17                     cout << _cimServerProcess->getVersion() << endl;
 665 kumpf       1.1                      exit(0);
 666                                  }
 667                                  //
 668                                  // Check to see if user asked for help (-h option):
 669                                  //
 670 kumpf       1.3                  else if (*option == OPTION_HELP &&
 671                                          (strlen(option) == 1))
 672 kumpf       1.1                  {
 673                                      PrintHelp(argv[0]);
 674                                      exit(0);
 675                                  }
 676 mateus.baur 1.17 #if !defined(PEGASUS_USE_RELEASE_DIRS)
 677 kumpf       1.3                  else if (*option == OPTION_HOME &&
 678                                          (strlen(option) == 1))
 679 kumpf       1.1                  {
 680                                      if (i + 1 < argc)
 681                                      {
 682                                          pegasusHome.assign(argv[i + 1]);
 683                                      }
 684                                      else
 685                                      {
 686 mateus.baur 1.17                         //l10n
 687                                          //cout << "Missing argument for option -" << option << endl;
 688                                          String opt(option);
 689                                          MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
 690                                                           "Missing argument for option -$0",
 691                                                           opt);
 692                                          cout << MessageLoader::getMessage(parms) << endl;
 693 kumpf       1.1                          exit(0);
 694                                      }
 695                  
 696                                      memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 697                                      argc -= 2;
 698                                  }
 699                  #endif
 700                  #if defined(PEGASUS_OS_HPUX)
 701                                  //
 702                                  // Check to see if user asked for the version (-X option):
 703                                  //
 704 kumpf       1.3                  if (*option == OPTION_BINDVERBOSE &&
 705                                          (strlen(option) == 1))
 706 kumpf       1.1                  {
 707 h.sterling  1.16             System::bindVerbose = true;
 708 mateus.baur 1.17                     //l10n
 709                                      //cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
 710                                           //<< endl;
 711                                      MessageLoaderParms parms("src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
 712                                                           "Unsupported debug option, BIND_VERBOSE, enabled.");
 713                                      cout << MessageLoader::getMessage(parms) << endl;
 714 kumpf       1.1                      // remove the option from the command line
 715                                      memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 716                                      argc--;   
 717                                  }
 718                  #endif
 719                                  //
 720                                  // Check to see if user asked for shutdown (-s option):
 721                                  //
 722 kumpf       1.3                  else if (*option == OPTION_SHUTDOWN &&
 723                                          (strlen(option) == 1))
 724 kumpf       1.1                  {
 725                                      //
 726                                      // Check to see if shutdown has already been specified:
 727                                      //
 728                                      if (shutdownOption)
 729                                      {
 730 mateus.baur 1.17                         //l10n
 731                                          //cout << "Duplicate shutdown option specified." << endl;
 732                                          MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
 733                                                                   "Duplicate shutdown option specified.");
 734                                         
 735                                          cout << MessageLoader::getMessage(parms) << endl;
 736 kumpf       1.1                          exit(0);
 737                                      }
 738                  
 739                                      shutdownOption = true;
 740                   
 741                                      // remove the option from the command line
 742                                      memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 743                                      argc--;   
 744                                  }
 745                                  else
 746 kumpf       1.3                      i++;
 747 kumpf       1.1              }
 748                              else
 749 kumpf       1.3                  i++;
 750 kumpf       1.1          }
 751                  
 752                      //
 753                      // Set the value for pegasusHome property
 754                      //
 755                      ConfigManager::setPegasusHome(pegasusHome);
 756                  
 757                      //
 758 mateus.baur 1.17     // Do the plaform specific run
 759                      //
 760                  
 761                      return _cimServerProcess->platform_run( argc, argv, shutdownOption );
 762                  }
 763                  
 764                  void CIMServerProcess::cimserver_stop()
 765                  {
 766                      _cimServer->shutdownSignal();
 767                  }
 768                  
 769                  //
 770                  // The main, common, running code
 771                  //
 772                  // NOTE: Do NOT call exit().  Use return(), otherwise some platforms 
 773                  // will fail to shutdown properly/cleanly.
 774                  //
 775                  // TODO: Current change minimal for platform "service" shutdown bug fixes.  
 776                  // Perhpas further extract out common stuff and put into main(), put 
 777                  // daemon stuff into platform specific platform_run(), etc.  
 778                  // Note: make sure to not put error handling stuff that platform 
 779 mateus.baur 1.17 // specific runs may need to deal with bettter (instead of exit(), etc).
 780                  //
 781                  
 782                  int CIMServerProcess::cimserver_run( int argc, char** argv, Boolean shutdownOption )
 783                  {
 784                      String logsDirectory = String::EMPTY;
 785                      Boolean daemonOption = false;
 786                  
 787                      //
 788 kumpf       1.1      // Get an instance of the Config Manager.
 789                      //
 790                      configManager = ConfigManager::getInstance();
 791 kumpf       1.10     configManager->useConfigFiles = true;
 792 kumpf       1.1  
 793 mateus.baur 1.17 #ifdef PEGASUS_OS_OS400
 794                      // In a special startup case for IBM OS400, when the server is
 795                      // automatically started when the machine starts up the config
 796                      // file cannot be read because of access restrictions for the
 797                      // user starting the server.  In this case, we need to skip
 798                      // reading the config options and therefore any use of the config
 799                      // manager also.  To make this determinations we will check to see
 800                      // if the daemon flag is set to true.  If so, then there will be a
 801                      // series of checks to bracket all the calls to the configManager
 802                      // which would otherwise fail.  All this will only be done for
 803                      // IBM OS400.
 804                  
 805                      Boolean os400StartupOption = false;
 806                      // loop through args to check for daemon=true
 807                      for (int i=1; i < argc; i++)
 808                        if (strcmp(argv[i], "daemon=true") == 0)
 809                        {
 810                          os400StartupOption = true;
 811                          daemonOption = true;
 812                        }
 813                  #endif    
 814 mateus.baur 1.17 
 815 kumpf       1.1      //
 816                      // Get options (from command line and from configuration file); this
 817                      // removes corresponding options and their arguments from the command
 818                      // line.
 819                      //
 820                      try
 821                      {
 822 mateus.baur 1.17 #ifdef PEGASUS_OS_OS400
 823                      if (os400StartupOption == false)
 824                  #endif   
 825                          GetOptions(configManager, argc, argv);
 826 kumpf       1.1      }
 827                      catch (Exception& e)
 828                      {
 829 mateus.baur 1.17         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 830                              "src.Server.cimserver.SERVER_NOT_STARTED",
 831                              "cimserver not started:  $0", e.getMessage());
 832                  
 833                  #if !defined(PEGASUS_OS_OS400)
 834                          MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 835                              "cimserver not started: $0", e.getMessage());
 836                  
 837                          PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
 838                              << PEGASUS_STD(endl);
 839 kumpf       1.3  #endif
 840 mateus.baur 1.17 
 841                          return(1);
 842 kumpf       1.1      }
 843                  
 844 kumpf       1.3  // l10n
 845 h.sterling  1.16     // Set the home directory, msg sub-dir, into the MessageLoader.
 846                      // This will be the default directory where the resource bundles 
 847 mateus.baur 1.17     // are found.    
 848                      MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
 849                          ConfigManager::getInstance()->getCurrentValue("messageDir")));      
 850                  
 851                  #ifdef PEGASUS_OS_OS400
 852                      // Still need to declare and set the connection variables.
 853                      // Will initialize to false since they are fixed at false for OS400.
 854                  
 855                      // NOTE:  OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down
 856                      // the test will not be compiled in.  If OS400 ever turns off that
 857                      // define, then we will need to change this code path to insure that
 858                      // one of the variables is true.    
 859                      Boolean enableHttpConnection = false;
 860                      Boolean enableHttpsConnection = false;
 861                      Boolean enableSSLExportClientVerification = false;
 862                  
 863                      if (os400StartupOption == false)
 864                      {
 865                        enableHttpConnection = String::equal(
 866                            configManager->getCurrentValue("enableHttpConnection"), "true");
 867                        enableHttpsConnection = String::equal(
 868 mateus.baur 1.17           configManager->getCurrentValue("enableHttpsConnection"), "true");
 869                        enableSSLExportClientVerification = String::equal(
 870                            configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
 871                      }
 872 kumpf       1.3  #else
 873 kumpf       1.2      Boolean enableHttpConnection = String::equal(
 874 kumpf       1.3          configManager->getCurrentValue("enableHttpConnection"), "true");
 875                      Boolean enableHttpsConnection = String::equal(
 876                          configManager->getCurrentValue("enableHttpsConnection"), "true");
 877 mateus.baur 1.17     Boolean enableSSLExportClientVerification = String::equal(
 878 kumpf       1.9          configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
 879 mateus.baur 1.17 #endif
 880 kumpf       1.2  
 881                      // Make sure at least one connection is enabled
 882 h.sterling  1.16 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
 883 kumpf       1.2      if (!enableHttpConnection && !enableHttpsConnection)
 884                      {
 885 mateus.baur 1.17         //l10n
 886                          //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 887                              //"Neither HTTP nor HTTPS connection is enabled.  "
 888                              //"CIMServer will not be started.");
 889                          Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 890                              "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 891                              "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 892                          //cerr << "Neither HTTP nor HTTPS connection is enabled.  "
 893                              //"CIMServer will not be started." << endl;
 894                          MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 895                                                   "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 896                          cerr << MessageLoader::getMessage(parms) << endl;
 897                          return(1);
 898 kumpf       1.2      }
 899                  #endif
 900                  
 901 kumpf       1.1      try
 902                      {
 903                          //
 904                          // Check to see if we should Pegasus as a daemon
 905                          //
 906                  
 907                          if (String::equal(configManager->getCurrentValue("daemon"), "true"))
 908                          {
 909                              daemonOption = true;
 910                          }
 911 h.sterling  1.16     
 912 mateus.baur 1.17 #ifdef PEGASUS_OS_OS400
 913                      if (os400StartupOption == false)
 914                      {
 915                  #endif            
 916 kumpf       1.1          // Get the log file directory definition.
 917                          // We put String into Cstring because
 918                          // Directory functions only handle Cstring.
 919                          // ATTN-KS: create String based directory functions.
 920                  
 921                          logsDirectory = configManager->getCurrentValue("logdir");
 922 kumpf       1.3          logsDirectory = 
 923 h.sterling  1.16         ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
 924 mateus.baur 1.17 #ifdef PEGASUS_OS_OS400
 925                      }  // end if (os400StartupOption == false)
 926                  #endif
 927 kumpf       1.1  
 928                          // Set up the Logger. This does not open the logs
 929                          // Might be more logical to clean before set.
 930                          // ATTN: Need tool to completely disable logging.
 931                  
 932 kumpf       1.3  #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 933                  !defined(PEGASUS_OS_OS400)
 934 kumpf       1.1          Logger::setHomeDirectory(logsDirectory);
 935                  #endif
 936                  
 937                          //
 938                          // Check to see if we need to shutdown CIMOM 
 939                          //
 940                          if (shutdownOption)
 941                          {
 942                              String configTimeout = 
 943                                  configManager->getCurrentValue("shutdownTimeout");
 944 mateus.baur 1.17             Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
 945 kumpf       1.1              
 946                              shutdownCIMOM(timeoutValue);
 947                  
 948 kumpf       1.3  #ifdef PEGASUS_OS_OS400
 949 mateus.baur 1.17         //l10n
 950                          //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 951                              //"CIM Server stopped.");  
 952                          Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 953                              "src.Server.cimserver.SERVER_STOPPED",
 954                              "CIM Server stopped.");
 955                              cimserver_exitRC(0);
 956 kumpf       1.3  #else
 957 mateus.baur 1.17             //l10n
 958                              //cout << "CIM Server stopped." << endl;
 959                              MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",
 960                                                       "CIM Server stopped.");
 961                  
 962                              cout << MessageLoader::getMessage(parms) << endl;
 963                              return(0);
 964 kumpf       1.2  #endif
 965 kumpf       1.1          }
 966                  
 967 mateus.baur 1.17 #if defined(PEGASUS_DEBUG)
 968 kumpf       1.1          // Leave this in until people get familiar with the logs.
 969 mateus.baur 1.17         //l10n
 970                          //cout << "Logs Directory = " << logsDirectory << endl;
 971                          MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
 972                                                   "Logs Directory = ");
 973                          cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
 974 kumpf       1.1  #endif
 975                      }
 976 kumpf       1.5      catch (UnrecognizedConfigProperty& e)
 977 kumpf       1.1      {
 978 kumpf       1.3  
 979                  #ifdef PEGASUS_OS_OS400
 980 mateus.baur 1.17     //l10n
 981                      //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 982                              //"Error: $0",e.getMessage());  
 983                      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 984                              "src.Server.cimserver.ERROR",
 985                              "Error: $0",e.getMessage()); 
 986 kumpf       1.3  #else
 987 mateus.baur 1.17     //l10n
 988                      //cout << "Error: " << e.getMessage() << endl;
 989                      MessageLoaderParms parms("src.Server.cimserver.ERROR",
 990                                               "Error: $0",
 991                                               e.getMessage());
 992                      cout << MessageLoader::getMessage(parms) << endl;
 993 kumpf       1.3  #endif
 994 kumpf       1.1      }
 995                  
 996 mateus.baur 1.17     // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.
 997                      // 1) If the user explicitly specified a port, use it.
 998                      // 2) If the user did not specify a port, get the port from the services file.
 999                      // 3) If no value is specified in the services file, use the IANA WBEM default port.
1000                      // Note that 2 and 3 are done within the System::lookupPort method
1001                      // An empty string from the ConfigManager implies that the user did not specify a port.
1002                  
1003                      Uint32 portNumberHttps=0;
1004                      Uint32 portNumberHttp=0;
1005                      Uint32 portNumberExportHttps=0;
1006 kumpf       1.1  
1007 kumpf       1.2      if (enableHttpsConnection)
1008 kumpf       1.1      {
1009 kumpf       1.2          String httpsPort = configManager->getCurrentValue("httpsPort");
1010 mateus.baur 1.17         if (httpsPort == String::EMPTY)
1011                          {
1012                              //
1013                              // Look up the WBEM-HTTPS port number
1014                              //
1015                              portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
1016                  
1017                          } else
1018                          {        
1019                              //
1020                              // user-specified
1021                              //
1022                              CString portString = httpsPort.getCString();
1023                              char* end = 0;
1024                              portNumberHttps = strtol(portString, &end, 10);
1025                              if(!(end != 0 && *end == '\0'))
1026                              {
1027 mateus.baur 1.18                 InvalidPropertyValue e("httpsPort", httpsPort);
1028                                  cerr << e.getMessage() << endl;
1029 mateus.baur 1.17                 exit(1);
1030                              }
1031                          }
1032 kumpf       1.1      }
1033 kumpf       1.2  
1034                      if (enableHttpConnection)
1035 kumpf       1.1      {
1036 kumpf       1.2          String httpPort = configManager->getCurrentValue("httpPort");
1037 mateus.baur 1.17         if (httpPort == String::EMPTY)
1038                          {
1039                              //
1040                              // Look up the WBEM-HTTP port number
1041                              //
1042                              portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
1043 kumpf       1.1  
1044 mateus.baur 1.17         } else
1045                          {
1046                              //
1047                              // user-specified
1048                              //
1049                              CString portString = httpPort.getCString();
1050                              char* end = 0;
1051                              portNumberHttp = strtol(portString, &end, 10);
1052                              if(!(end != 0 && *end == '\0'))
1053                              {
1054 mateus.baur 1.18                 InvalidPropertyValue e("httpPort", httpPort);
1055                                  cerr << e.getMessage() << endl;
1056 mateus.baur 1.17                 exit(1);
1057                              }
1058                          }
1059 kumpf       1.1      }
1060                  
1061 kumpf       1.9  
1062 mateus.baur 1.17     if (enableSSLExportClientVerification)
1063                      {
1064                          //
1065                          // No config property is looked up to get the default port number.
1066                          // Lookup the port defined in /etc/services for the service name
1067                          // wbem-exp-https and bind to that port. If the service is  not defined
1068                          // then log a warning message and do not start the cimserver.
1069                          //
1070                          Uint32 port = 0;
1071 kumpf       1.9  
1072 mateus.baur 1.17         portNumberExportHttps = System::lookupPort(WBEM_EXPORT_HTTPS_SERVICE_NAME, port);
1073 kumpf       1.9  
1074 mateus.baur 1.17         if (portNumberExportHttps == 0)
1075                          {
1076                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1077                                  "src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
1078                                  "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
1079 kumpf       1.9  
1080 mateus.baur 1.17             MessageLoaderParms parms("src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
1081                                  "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
1082 kumpf       1.9  
1083 mateus.baur 1.17             cerr << MessageLoader::getMessage(parms) << endl;
1084 kumpf       1.9  
1085 mateus.baur 1.17             return(1);
1086                          }
1087                      }
1088                  #if defined(PEGASUS_DEBUG)
1089 kumpf       1.1      // Put out startup up message.
1090 mateus.baur 1.17     cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;
1091                      //l10n
1092                      //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
1093                      //cout <<"Starting..."
1094                      MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
1095                                               "Built $0 $1\nStarting...",
1096                                               __DATE__,
1097                                               __TIME__);
1098                  #endif
1099                  
1100                  //l10n
1101                  // reset message loading to NON-process locale
1102                  MessageLoader::_useProcessLocale = false; 
1103                  //l10n
1104 kumpf       1.3  
1105 mateus.baur 1.17     // Get the parent's PID before forking
1106                      _cimServerProcess->set_parent_pid(System::getPID());
1107                      
1108 kumpf       1.1      // do we need to run as a daemon ?
1109                      if (daemonOption)
1110                      {
1111 mateus.baur 1.17         if(-1 == _cimServerProcess->cimserver_fork())
1112 kumpf       1.2  #ifndef PEGASUS_OS_OS400
1113 mateus.baur 1.17     {
1114                          return(-1);
1115 h.sterling  1.16     }
1116 kumpf       1.2  #else
1117 h.sterling  1.16     {
1118 kumpf       1.3              return(-1);
1119 h.sterling  1.16     }
1120                      else
1121                      {
1122                          return(0);
1123                      }
1124 kumpf       1.2  #endif
1125 h.sterling  1.16     
1126 kumpf       1.1      }
1127                  
1128 mateus.baur 1.17 // l10n
1129                      // Now we are after the fork...
1130                      // Create a dummy Thread object that can be used to store the
1131                      // AcceptLanguages object for CIM requests that are serviced
1132                      // by this thread (initial thread of server).  Need to do this
1133                      // because this thread is not in a ThreadPool, but is used
1134                      // to service CIM requests.
1135                      // The run function for the dummy Thread should never be called,
1136                      Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
1137                      Thread::setCurrent(dummyInitialThread); 
1138                      AcceptLanguages default_al;
1139                      try{
1140                           default_al = AcceptLanguages::getDefaultAcceptLanguages();   
1141                           Thread::setLanguages(new AcceptLanguages(default_al));
1142                      }catch(InvalidAcceptLanguageHeader& e){
1143                            Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1144                                    "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
1145                                    "Could not convert the system process locale into a valid AcceptLanguage format.");  
1146                            Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1147                                               e.getMessage()); 
1148                      }
1149 mateus.baur 1.17     
1150                      
1151                  
1152 kumpf       1.1  #ifdef PEGASUS_OS_OS400
1153                      // Special server initialization code for OS/400.
1154                      if (cimserver_initialize() != 0)
1155                      {
1156 h.sterling  1.16     // do some logging here!
1157 mateus.baur 1.17     //l10n
1158                      //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1159                              //"CIM Server failed to initialize"); 
1160                      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1161                                    "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE",
1162                                    "CIM Server failed to initialize");  
1163                      return(-1);
1164 kumpf       1.1      } 
1165                  #endif
1166                  
1167 mateus.baur 1.17 
1168                  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1169                  || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1170                  || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || defined (PEGASUS_OS_VMS)
1171 kumpf       1.1      umask(S_IWGRP|S_IWOTH);
1172 kumpf       1.2  
1173                      //
1174                      // check if CIMServer is already running
1175                      // if CIMServer is already running, print message and 
1176                      // notify parent process (if there is a parent process) to terminate
1177                      //
1178 mateus.baur 1.17     if(_cimServerProcess->isCIMServerRunning())
1179 kumpf       1.2      {
1180 mateus.baur 1.17     //l10n
1181                          //cout << "Unable to start CIMServer." << endl;
1182                          //cout << "CIMServer is already running." << endl;
1183                          MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
1184                                       "Unable to start CIMServer.\nCIMServer is already running.");
1185                      PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1186 kumpf       1.2  
1187 h.sterling  1.16     //
1188 kumpf       1.2          // notify parent process (if there is a parent process) to terminate
1189                          //
1190                          if (daemonOption)
1191 mateus.baur 1.17                 _cimServerProcess->notify_parent(1);
1192 kumpf       1.2  
1193 mateus.baur 1.17         return(1);
1194 kumpf       1.2      }
1195                       
1196 kumpf       1.1  #endif
1197                  
1198                      // try loop to bind the address, and run the server
1199                      try
1200                      {
1201 mateus.baur 1.17 
1202 mateus.baur 1.18     _monitor  = new Monitor();
1203 mateus.baur 1.17     //PEP#222
1204                      //CIMServer server(&monitor);
1205                      //CimserverHolder cimserverHolder( &server );
1206 mateus.baur 1.18     _cimServer = new CIMServer(_monitor);
1207 mateus.baur 1.17 
1208 kumpf       1.2  
1209                          if (enableHttpConnection)
1210                          {
1211 mateus.baur 1.17             _cimServer->addAcceptor(false, portNumberHttp, false, false);
1212                              //l10n
1213                              //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1214                                          //"Listening on HTTP port $0.", portNumberHttp);
1215                                          
1216                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1217                                              "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1218                                              "Listening on HTTP port $0.", portNumberHttp);
1219 kumpf       1.2          }
1220                          if (enableHttpsConnection)
1221                          {
1222 mateus.baur 1.17             _cimServer->addAcceptor(false, portNumberHttps, true, false);
1223                              //l10n
1224                              //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1225                                          //"Listening on HTTPS port $0.", portNumberHttps);
1226                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1227                                              "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1228                                              "Listening on HTTPS port $0.", portNumberHttps);
1229                          }
1230                          if (enableSSLExportClientVerification)
1231                          {
1232                              _cimServer->addAcceptor(false, portNumberExportHttps, true, true);
1233                  
1234                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1235                                  "src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1236                                  "Listening on Export HTTPS port $0.", portNumberExportHttps);
1237                          }
1238 kumpf       1.9  
1239 h.sterling  1.16 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1240 mateus.baur 1.17         _cimServer->addAcceptor(true, 0, false, false);
1241                          //l10n
1242                          //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1243                                      //"Listening on local connection socket.");
1244                          Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1245                                "src.Server.cimserver.LISTENING_ON_LOCAL",
1246                                "Listening on local connection socket.");
1247 kumpf       1.1  #endif
1248                  
1249 mateus.baur 1.17 #if defined(PEGASUS_DEBUG)
1250 kumpf       1.2          if (enableHttpConnection)
1251                          {
1252 mateus.baur 1.17             //l10n
1253                              //cout << "Listening on HTTP port " << portNumberHttp << endl;
1254                        MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1255                                     "Listening on HTTP port $0.", portNumberHttp);
1256                              cout << MessageLoader::getMessage(parms) << endl;
1257 kumpf       1.2          }
1258                          if (enableHttpsConnection)
1259                          {
1260 mateus.baur 1.17             //l10n
1261                              //cout << "Listening on HTTPS port " << portNumberHttps << endl;
1262                              MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1263                                       "Listening on HTTPS port $0.", portNumberHttps);
1264                              cout << MessageLoader::getMessage(parms) << endl;
1265                          }
1266                          if (enableSSLExportClientVerification)
1267                          {
1268                              MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1269                                  "Listening on Export HTTPS port $0.", portNumberExportHttps);
1270                  
1271                              cout << MessageLoader::getMessage(parms) << endl;
1272 kumpf       1.2          }
1273 kumpf       1.9  
1274 h.sterling  1.16 # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1275 mateus.baur 1.17         //l10n
1276                          //cout << "Listening on local connection socket" << endl;
1277                          MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",
1278                                   "Listening on local connection socket.");
1279                          cout << MessageLoader::getMessage(parms) << endl;
1280 kumpf       1.3  # endif
1281 kumpf       1.1  #endif
1282                  
1283 kumpf       1.3          // bind throws an exception if the bind fails
1284 mateus.baur 1.18         try { 
1285                             _cimServer->bind();
1286                  	} catch (const BindFailedException &e)
1287                  	{
1288                  #ifdef PEGASUS_DEBUG
1289                          MessageLoaderParms parms("src.Server.cimserver.BIND_FAILED",
1290                                   "Could not bind: $0.", e.getMessage());
1291                          cout << MessageLoader::getMessage(parms) << endl;
1292                  #endif
1293                          Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1294                              "src.Server.cimserver.BIND.FAILED",
1295                              "Could not bind:  $0", e.getMessage());
1296 kumpf       1.1  
1297 mateus.baur 1.18 	   deleteCIMServer();
1298                  	   return 1;
1299                  	}
1300 h.sterling  1.16     // notify parent process (if there is a parent process) to terminate 
1301 kumpf       1.3          // so user knows that there is cimserver ready to serve CIM requests.
1302 h.sterling  1.16     if (daemonOption)
1303 mateus.baur 1.17         _cimServerProcess->notify_parent(0);
1304 kumpf       1.2  
1305 h.sterling  1.16     time_t last = 0;
1306 kumpf       1.1  
1307 mateus.baur 1.17 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \
1308                      || defined(PEGASUS_OS_AIX) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) \
1309                      || defined(PEGASUS_OS_VMS)
1310 kumpf       1.1          //
1311                          // create a file to indicate that the cimserver has started and
1312                          // save the process id of the cimserver process in the file
1313                          //
1314                          // remove the old file if it exists
1315 mateus.baur 1.17         System::removeFile(_cimServerProcess->getPIDFileName());
1316 kumpf       1.1  
1317                          // open the file
1318 mateus.baur 1.17         FILE *pid_file = fopen(_cimServerProcess->getPIDFileName(), "w");
1319 kumpf       1.3  
1320 kumpf       1.1          if (pid_file)
1321                          {
1322                              // save the pid in the file
1323 mateus.baur 1.17             fprintf(pid_file, "%ld\n", _cimServerProcess->get_server_pid());
1324 kumpf       1.1              fclose(pid_file);
1325                          }
1326                  #endif
1327 kumpf       1.3  
1328 mateus.baur 1.17 #if defined(PEGASUS_DEBUG)
1329 h.sterling  1.16     cout << "Started. " << endl;
1330 kumpf       1.1  #endif
1331 mateus.baur 1.17     
1332 kumpf       1.1          // Put server started message to the logger
1333 mateus.baur 1.17         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1334                              Logger::INFORMATION,
1335                              "src.Server.cimserver.STARTED_VERSION",
1336                              "Started $0 version $1.",
1337                              _cimServerProcess->getProductName(), _cimServerProcess->getVersion());
1338 kumpf       1.1  
1339 kumpf       1.3          //
1340 kumpf       1.1          // Loop to call CIMServer's runForever() method until CIMServer
1341                          // has been shutdown
1342                          //
1343 mateus.baur 1.17     while( !_cimServer->terminated() )
1344 h.sterling  1.16     {
1345 mateus.baur 1.17 
1346                        _cimServer->runForever();
1347                  
1348 h.sterling  1.16     }
1349 kumpf       1.1  
1350                          //
1351                          // normal termination
1352 mateus.baur 1.17         //
1353 kumpf       1.12 
1354 kumpf       1.1          // Put server shutdown message to the logger
1355 mateus.baur 1.17         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1356                              Logger::INFORMATION, "src.Server.cimserver.STOPPED",
1357                              "$0 stopped.", _cimServerProcess->getProductName());
1358                  
1359                  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1360                  || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1361                  || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || defined(PEGASUS_OS_VMS)
1362 kumpf       1.1          //
1363                          // close the file created at startup time to indicate that the 
1364                          // cimserver has terminated normally.
1365                          //
1366 mateus.baur 1.17         FileSystem::removeFile(_cimServerProcess->getPIDFileName());
1367 kumpf       1.1  #endif
1368                      }
1369                      catch(Exception& e)
1370                      {
1371 mateus.baur 1.17 
1372                      //l10n
1373                      //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1374                              //"Error: $0", e.getMessage()); 
1375                      Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1376                              "src.Server.cimserver.ERROR",
1377                              "Error: $0", e.getMessage());  
1378 kumpf       1.2  
1379 kumpf       1.3  #ifndef PEGASUS_OS_OS400
1380 mateus.baur 1.17     //l10n
1381                      //PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1382                      MessageLoaderParms parms("src.Server.cimserver.ERROR",
1383                                               "Error: $0", e.getMessage());
1384                      PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1385                  
1386 kumpf       1.3  #endif
1387                  
1388 h.sterling  1.16     //
1389 kumpf       1.3          // notify parent process (if there is a parent process) to terminate
1390 kumpf       1.2          //
1391                          if (daemonOption)
1392 mateus.baur 1.17                 _cimServerProcess->notify_parent(1);
1393 kumpf       1.2  
1394 mateus.baur 1.17         deleteCIMServer();
1395 kumpf       1.1          return 1;
1396                      }
1397                  
1398 mateus.baur 1.17     deleteCIMServer();
1399 kumpf       1.1      return 0;
1400                  }
1401 mateus.baur 1.17 
1402                  
1403                  
1404                  

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2