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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2