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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2