(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 konrad.r   1.161          PEGASUS_STD(cerr) << "Exit! " << endl;
 498 s.hills    1.117         exit(1);
 499 chuck      1.66  #endif
 500 kumpf      1.46      }
 501 s.hills    1.117     catch(Exception&)
 502 kumpf      1.45      {
 503                          //
 504 kumpf      1.91          // This may mean that the CIM Server has terminated, causing this
 505                          // client to get a "Empty HTTP response message" exception.  It may
 506                          // also mean that the CIM Server is taking longer than 2 seconds 
 507                          // (client timeout value) to terminate, causing this client to 
 508                          // timeout with a "connection timeout" exception.
 509 kumpf      1.45          //
 510 kumpf      1.91          // Check to see if CIM Server is still running.  If CIM Server
 511 kumpf      1.63          // is still running and the shutdown timeout has not expired,
 512 kumpf      1.91          // loop and wait one second until either the CIM Server is
 513                          // terminated or timeout expires.  If timeout expires and
 514                          // the CIM Server is still running, kill the CIMServer process.
 515                          // 
 516 kumpf      1.63          Uint32 maxWaitTime = timeoutValue - 2;
 517 h.sterling 1.153         Boolean running = _cimServerProcess->isCIMServerRunning();
 518 kumpf      1.63          while ( running && maxWaitTime > 0 )
 519                          {
 520                              System::sleep(1);
 521 h.sterling 1.153             running = _cimServerProcess->isCIMServerRunning();
 522 kumpf      1.63              maxWaitTime = maxWaitTime - 1;
 523                          }
 524                  
 525                          if (running)
 526                          {
 527 h.sterling 1.153        int kill_rc = _cimServerProcess->cimserver_kill(0);
 528                         
 529 humberto   1.90  #ifdef PEGASUS_OS_OS400
 530 h.sterling 1.153         if(kill_rc == -1)
 531                          _cimServerProcess->cimserver_exitRC(2);
 532                          _cimServerProcess->cimserver_exitRC(1);
 533 humberto   1.90  #endif
 534 kumpf      1.91  
 535 gs.keenan  1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
 536                  || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) \
 537                  || defined (PEGASUS_OS_VMS)
 538 h.sterling 1.153         if (kill_rc != -1)
 539 kumpf      1.91              {
 540 kumpf      1.105                 //l10n - TODO
 541                                  Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 542                                      "src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 543                                      "Shutdown timeout expired.  Forced shutdown initiated.");
 544 humberto   1.97                  MessageLoaderParms parms("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 545 kumpf      1.105                     "Shutdown timeout expired.  Forced shutdown initiated.");
 546 humberto   1.97                  cout << MessageLoader::getMessage(parms) << endl;
 547 kumpf      1.91                  exit(0);
 548                              }
 549                  #endif
 550 kumpf      1.63          }
 551 kumpf      1.43      }
 552 mike       1.35  
 553                      return;
 554 mike       1.32  }
 555                  
 556 mike       1.35  
 557 mike       1.33  /////////////////////////////////////////////////////////////////////////
 558 mike       1.32  //  MAIN
 559                  //////////////////////////////////////////////////////////////////////////
 560                  int main(int argc, char** argv)
 561                  {
 562 mike       1.35      String pegasusHome  = String::EMPTY;
 563                      Boolean shutdownOption = false;
 564 mday       1.47  
 565 humberto   1.97  //l10n
 566                  // Set Message loading to process locale
 567                  MessageLoader::_useProcessLocale = true; 
 568                  //l10n
 569                  
 570 kv.le      1.140 //l10n
 571                  #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
 572                  setlocale(LC_ALL, "");
 573                  #endif
 574                  
 575 chuck      1.66  #ifdef PEGASUS_OS_OS400
 576 david      1.120 
 577                    VFYPTRS_INCDCL;               // VFYPTRS local variables
 578                  
 579                    // verify pointers
 580                    #pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\
 581                      0,_C2_MH_ESCAPE)
 582                      for( int arg_index = 1; arg_index < argc; arg_index++ ){
 583 h.sterling 1.153     VFYPTRS(VERIFY_SPP_NULL(argv[arg_index]));
 584 david      1.120     }
 585                    #pragma disable_handler
 586                  
 587 david      1.100     // Convert the args to ASCII
 588                      for(Uint32 i = 0;i< argc;++i)
 589                      {
 590 h.sterling 1.153     EtoA(argv[i]);
 591 david      1.100     }
 592                  
 593 chuck      1.66      // Initialize Pegasus home to the shipped OS/400 directory.
 594                      pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
 595                  #endif
 596                  
 597 kv.le      1.134 
 598 tony       1.82  #ifndef PEGASUS_OS_TYPE_WINDOWS
 599 kumpf      1.38      //
 600                      // Get environment variables:
 601                      //
 602 david      1.100 #ifdef PEGASUS_OS_OS400
 603                  #pragma convert(37)
 604                      const char* tmp = getenv("PEGASUS_HOME");
 605                  #pragma convert(0)
 606                      char home[256] = {0};
 607                      if (tmp && strlen(tmp) < 256)
 608                      {
 609 h.sterling 1.153     strcpy(home, tmp);
 610                      EtoA(home);
 611                      pegasusHome = home;
 612 david      1.100     }
 613                  #else
 614 kv.le      1.134   #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
 615                      pegasusHome = AIX_RELEASE_PEGASUS_HOME;
 616 kumpf      1.138   #elif !defined(PEGASUS_USE_RELEASE_DIRS)
 617 kumpf      1.38      const char* tmp = getenv("PEGASUS_HOME");
 618                  
 619                      if (tmp)
 620                      {
 621                          pegasusHome = tmp;
 622                      }
 623 kv.le      1.134   #endif
 624 david      1.100 #endif
 625 kumpf      1.38  
 626                      FileSystem::translateSlashes(pegasusHome);
 627 tony       1.82  #else
 628 kumpf      1.38  
 629 tony       1.82    // windows only
 630 h.sterling 1.153   //setHome(pegasusHome);
 631                    pegasusHome = _cimServerProcess->getHome();
 632 tony       1.82  #endif
 633 mike       1.32  
 634 kumpf      1.60          // Get help, version, and shutdown options
 635 mike       1.35  
 636                          for (int i = 1; i < argc; )
 637                          {
 638                              const char* arg = argv[i];
 639 a.arora    1.142             if(String::equal(arg,"--help"))
 640                              {
 641                                      PrintHelp(argv[0]);
 642                                      exit(0);
 643                              }
 644                              else if(String::equal(arg,"--version"))
 645                              {
 646 h.sterling 1.153                 cout << _cimServerProcess->getVersion() << endl;
 647 a.arora    1.142                 exit(0);
 648                              }
 649 mike       1.35              // Check for -option
 650 a.arora    1.142             else if (*arg == '-')
 651 mike       1.35              {
 652                                  // Get the option
 653                                  const char* option = arg + 1;
 654                  
 655                                  //
 656                                  // Check to see if user asked for the version (-v option):
 657                                  //
 658 tony       1.83                  if (*option == OPTION_VERSION &&
 659                                      strlen(option) == 1)
 660 mike       1.35                  {
 661 h.sterling 1.153                     cout << _cimServerProcess->getVersion() << endl;
 662 mike       1.35                      exit(0);
 663                                  }
 664                                  //
 665                                  // Check to see if user asked for help (-h option):
 666                                  //
 667 tony       1.83                  else if (*option == OPTION_HELP &&
 668                                          (strlen(option) == 1))
 669 mike       1.35                  {
 670                                      PrintHelp(argv[0]);
 671                                      exit(0);
 672                                  }
 673 kumpf      1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
 674 tony       1.83                  else if (*option == OPTION_HOME &&
 675                                          (strlen(option) == 1))
 676 mike       1.35                  {
 677 kumpf      1.60                      if (i + 1 < argc)
 678 mike       1.35                      {
 679                                          pegasusHome.assign(argv[i + 1]);
 680                                      }
 681                                      else
 682                                      {
 683 humberto   1.97                          //l10n
 684                                          //cout << "Missing argument for option -" << option << endl;
 685 humberto   1.99                          String opt(option);
 686 humberto   1.97                          MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
 687 h.sterling 1.153                                          "Missing argument for option -$0",
 688                                                           opt);
 689                                          cout << MessageLoader::getMessage(parms) << endl;
 690 mike       1.35                          exit(0);
 691                                      }
 692                  
 693                                      memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 694                                      argc -= 2;
 695                                  }
 696 kumpf      1.63  #endif
 697 kumpf      1.48  #if defined(PEGASUS_OS_HPUX)
 698                                  //
 699 kumpf      1.49                  // Check to see if user asked for the version (-X option):
 700 kumpf      1.48                  //
 701 tony       1.83                  if (*option == OPTION_BINDVERBOSE &&
 702                                          (strlen(option) == 1))
 703 kumpf      1.48                  {
 704 h.sterling 1.153             System::bindVerbose = true;
 705 humberto   1.97                      //l10n
 706                                      //cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
 707                                           //<< endl;
 708                                      MessageLoaderParms parms("src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
 709 h.sterling 1.153                                          "Unsupported debug option, BIND_VERBOSE, enabled.");
 710                                      cout << MessageLoader::getMessage(parms) << endl;
 711 kumpf      1.48                      // remove the option from the command line
 712                                      memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 713                                      argc--;   
 714                                  }
 715                  #endif
 716 mike       1.35                  //
 717                                  // Check to see if user asked for shutdown (-s option):
 718                                  //
 719 tony       1.82                  else if (*option == OPTION_SHUTDOWN &&
 720                                          (strlen(option) == 1))
 721 mike       1.35                  {
 722                                      //
 723 kumpf      1.52                      // Check to see if shutdown has already been specified:
 724 mike       1.35                      //
 725 kumpf      1.52                      if (shutdownOption)
 726 mike       1.35                      {
 727 humberto   1.97                          //l10n
 728                                          //cout << "Duplicate shutdown option specified." << endl;
 729                                          MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
 730 h.sterling 1.153                                                  "Duplicate shutdown option specified.");
 731 humberto   1.97                         
 732                                          cout << MessageLoader::getMessage(parms) << endl;
 733 mike       1.35                          exit(0);
 734                                      }
 735                  
 736 kumpf      1.52                      shutdownOption = true;
 737 mike       1.35   
 738                                      // remove the option from the command line
 739                                      memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 740                                      argc--;   
 741                                  }
 742                                  else
 743                                      i++;
 744                              }
 745                              else
 746                                  i++;
 747 mike       1.32          }
 748 mike       1.35  
 749 kumpf      1.38      //
 750                      // Set the value for pegasusHome property
 751                      //
 752                      ConfigManager::setPegasusHome(pegasusHome);
 753 mike       1.32  
 754 mike       1.35      //
 755 s.hills    1.117     // Do the plaform specific run
 756                      //
 757                  
 758 h.sterling 1.153     return _cimServerProcess->platform_run( argc, argv, shutdownOption );
 759 s.hills    1.117 }
 760                  
 761 h.sterling 1.153 void CIMServerProcess::cimserver_stop()
 762                  {
 763                      _cimServer->shutdownSignal();
 764                  }
 765 s.hills    1.117 
 766                  //
 767                  // The main, common, running code
 768                  //
 769                  // NOTE: Do NOT call exit().  Use return(), otherwise some platforms 
 770                  // will fail to shutdown properly/cleanly.
 771                  //
 772                  // TODO: Current change minimal for platform "service" shutdown bug fixes.  
 773                  // Perhpas further extract out common stuff and put into main(), put 
 774                  // daemon stuff into platform specific platform_run(), etc.  
 775                  // Note: make sure to not put error handling stuff that platform 
 776                  // specific runs may need to deal with bettter (instead of exit(), etc).
 777                  //
 778                  
 779 h.sterling 1.153 int CIMServerProcess::cimserver_run( int argc, char** argv, Boolean shutdownOption )
 780 s.hills    1.117 {
 781                      String logsDirectory = String::EMPTY;
 782                      Boolean daemonOption = false;
 783                  
 784                      //
 785 mike       1.35      // Get an instance of the Config Manager.
 786                      //
 787                      configManager = ConfigManager::getInstance();
 788 kumpf      1.136     configManager->useConfigFiles = true;
 789 mike       1.35  
 790 lucier     1.130 #ifdef PEGASUS_OS_OS400
 791                      // In a special startup case for IBM OS400, when the server is
 792                      // automatically started when the machine starts up the config
 793                      // file cannot be read because of access restrictions for the
 794                      // user starting the server.  In this case, we need to skip
 795                      // reading the config options and therefore any use of the config
 796                      // manager also.  To make this determinations we will check to see
 797                      // if the daemon flag is set to true.  If so, then there will be a
 798                      // series of checks to bracket all the calls to the configManager
 799                      // which would otherwise fail.  All this will only be done for
 800                      // IBM OS400.
 801                  
 802                      Boolean os400StartupOption = false;
 803                      // loop through args to check for daemon=true
 804                      for (int i=1; i < argc; i++)
 805                        if (strcmp(argv[i], "daemon=true") == 0)
 806                        {
 807                          os400StartupOption = true;
 808                          daemonOption = true;
 809                        }
 810                  #endif    
 811 lucier     1.130 
 812 mike       1.35      //
 813 mike       1.32      // Get options (from command line and from configuration file); this
 814 mike       1.35      // removes corresponding options and their arguments from the command
 815 mike       1.32      // line.
 816 mike       1.35      //
 817 mike       1.32      try
 818                      {
 819 lucier     1.130 #ifdef PEGASUS_OS_OS400
 820                      if (os400StartupOption == false)
 821                  #endif   
 822 s.hills    1.117         GetOptions(configManager, argc, argv);
 823 mike       1.32      }
 824                      catch (Exception& e)
 825                      {
 826 kumpf      1.127         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 827                              "src.Server.cimserver.SERVER_NOT_STARTED",
 828                              "cimserver not started:  $0", e.getMessage());
 829                  
 830                  #if !defined(PEGASUS_OS_OS400)
 831                          MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 832                              "cimserver not started: $0", e.getMessage());
 833                  
 834                          PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
 835                              << PEGASUS_STD(endl);
 836 david      1.85  #endif
 837 kumpf      1.127 
 838 s.hills    1.117         return(1);
 839 mike       1.32      }
 840                  
 841 chuck      1.94  // l10n
 842 h.sterling 1.153     // Set the home directory, msg sub-dir, into the MessageLoader.
 843                      // This will be the default directory where the resource bundles 
 844                      // are found.    
 845                      MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
 846                          ConfigManager::getInstance()->getCurrentValue("messageDir")));      
 847 chuck      1.94  
 848 lucier     1.130 #ifdef PEGASUS_OS_OS400
 849                      // Still need to declare and set the connection variables.
 850                      // Will initialize to false since they are fixed at false for OS400.
 851                  
 852                      // NOTE:  OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down
 853                      // the test will not be compiled in.  If OS400 ever turns off that
 854                      // define, then we will need to change this code path to insure that
 855                      // one of the variables is true.    
 856                      Boolean enableHttpConnection = false;
 857                      Boolean enableHttpsConnection = false;
 858 kumpf      1.135     Boolean enableSSLExportClientVerification = false;
 859 lucier     1.130 
 860                      if (os400StartupOption == false)
 861                      {
 862                        enableHttpConnection = String::equal(
 863                            configManager->getCurrentValue("enableHttpConnection"), "true");
 864                        enableHttpsConnection = String::equal(
 865                            configManager->getCurrentValue("enableHttpsConnection"), "true");
 866 kumpf      1.135       enableSSLExportClientVerification = String::equal(
 867                            configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
 868 lucier     1.130     }
 869                  #else
 870 kumpf      1.87      Boolean enableHttpConnection = String::equal(
 871                          configManager->getCurrentValue("enableHttpConnection"), "true");
 872                      Boolean enableHttpsConnection = String::equal(
 873                          configManager->getCurrentValue("enableHttpsConnection"), "true");
 874 kumpf      1.135     Boolean enableSSLExportClientVerification = String::equal(
 875                          configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
 876 lucier     1.130 #endif
 877 kumpf      1.86  
 878                      // Make sure at least one connection is enabled
 879 h.sterling 1.159 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
 880 kumpf      1.86      if (!enableHttpConnection && !enableHttpsConnection)
 881                      {
 882 humberto   1.97          //l10n
 883                          //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 884                              //"Neither HTTP nor HTTPS connection is enabled.  "
 885                              //"CIMServer will not be started.");
 886                          Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 887 h.sterling 1.153             "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 888 humberto   1.97              "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 889                          //cerr << "Neither HTTP nor HTTPS connection is enabled.  "
 890                              //"CIMServer will not be started." << endl;
 891                          MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 892 h.sterling 1.153                                  "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 893 humberto   1.97          cerr << MessageLoader::getMessage(parms) << endl;
 894 s.hills    1.117         return(1);
 895 kumpf      1.86      }
 896                  #endif
 897                  
 898 mike       1.35      try
 899 mike       1.32      {
 900 mike       1.35          //
 901                          // Check to see if we should Pegasus as a daemon
 902                          //
 903                  
 904                          if (String::equal(configManager->getCurrentValue("daemon"), "true"))
 905                          {
 906                              daemonOption = true;
 907                          }
 908 h.sterling 1.153     
 909 lucier     1.130 #ifdef PEGASUS_OS_OS400
 910                      if (os400StartupOption == false)
 911                      {
 912                  #endif            
 913 kumpf      1.36          // Get the log file directory definition.
 914                          // We put String into Cstring because
 915                          // Directory functions only handle Cstring.
 916                          // ATTN-KS: create String based directory functions.
 917 konrad.r   1.161 #if !defined(PEGASUS_USE_SYSLOGS)
 918                  		// When using syslog facility. No files anymore.
 919 kumpf      1.36          logsDirectory = configManager->getCurrentValue("logdir");
 920 kumpf      1.38          logsDirectory = 
 921 h.sterling 1.153         ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
 922 konrad.r   1.161 #endif
 923 lucier     1.130 #ifdef PEGASUS_OS_OS400
 924                      }  // end if (os400StartupOption == false)
 925                  #endif
 926 kumpf      1.36  
 927                          // Set up the Logger. This does not open the logs
 928                          // Might be more logical to clean before set.
 929                          // ATTN: Need tool to completely disable logging.
 930                  
 931 david      1.85  #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 932 konrad.r   1.161 !defined(PEGASUS_OS_OS400) && !defined(PEGASUS_USE_SYSLOGS)
 933 kumpf      1.36          Logger::setHomeDirectory(logsDirectory);
 934 kumpf      1.57  #endif
 935 kumpf      1.36  
 936                          //
 937 mike       1.35          // Check to see if we need to shutdown CIMOM 
 938                          //
 939                          if (shutdownOption)
 940                          {
 941 kumpf      1.60              String configTimeout = 
 942                                  configManager->getCurrentValue("shutdownTimeout");
 943 s.hills    1.117             Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
 944 kumpf      1.60              
 945 kumpf      1.52              shutdownCIMOM(timeoutValue);
 946 kumpf      1.45  
 947 david      1.85  #ifdef PEGASUS_OS_OS400
 948 h.sterling 1.153         //l10n
 949                          //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 950                              //"CIM Server stopped.");  
 951                          Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 952                              "src.Server.cimserver.SERVER_STOPPED",
 953                              "CIM Server stopped.");
 954 s.hills    1.117             cimserver_exitRC(0);
 955 david      1.85  #else
 956 h.sterling 1.153             //l10n
 957 humberto   1.97              //cout << "CIM Server stopped." << endl;
 958                              MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",
 959 h.sterling 1.153                                      "CIM Server stopped.");
 960 humberto   1.106 
 961 humberto   1.97              cout << MessageLoader::getMessage(parms) << endl;
 962 s.hills    1.117             return(0);
 963 diane      1.81  #endif
 964 mike       1.35          }
 965 mike       1.32  
 966 kumpf      1.139 #if defined(PEGASUS_DEBUG)
 967 kumpf      1.36          // Leave this in until people get familiar with the logs.
 968 humberto   1.97          //l10n
 969                          //cout << "Logs Directory = " << logsDirectory << endl;
 970 konrad.r   1.161 #if !defined(PEGASUS_USE_SYSLOGS)
 971 humberto   1.97          MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
 972 h.sterling 1.153                                  "Logs Directory = ");
 973 humberto   1.97          cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
 974 kumpf      1.57  #endif
 975 konrad.r   1.161 #endif
 976 mike       1.32      }
 977 kumpf      1.122     catch (UnrecognizedConfigProperty& e)
 978 mike       1.32      {
 979 david      1.85  
 980                  #ifdef PEGASUS_OS_OS400
 981 h.sterling 1.153     //l10n
 982                      //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 983                              //"Error: $0",e.getMessage());  
 984                      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 985                              "src.Server.cimserver.ERROR",
 986                              "Error: $0",e.getMessage()); 
 987 david      1.85  #else
 988 h.sterling 1.153     //l10n
 989                      //cout << "Error: " << e.getMessage() << endl;
 990                      MessageLoaderParms parms("src.Server.cimserver.ERROR",
 991                                               "Error: $0",
 992                                               e.getMessage());
 993                      cout << MessageLoader::getMessage(parms) << endl;
 994 david      1.85  #endif
 995 mike       1.32      }
 996                  
 997 h.sterling 1.158     // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.
 998                      // 1) If the user explicitly specified a port, use it.
 999                      // 2) If the user did not specify a port, get the port from the services file.
1000                      // 3) If no value is specified in the services file, use the IANA WBEM default port.
1001                      // Note that 2 and 3 are done within the System::lookupPort method
1002                      // An empty string from the ConfigManager implies that the user did not specify a port.
1003                  
1004 w.otsuka   1.147     Uint32 portNumberHttps=0;
1005                      Uint32 portNumberHttp=0;
1006                      Uint32 portNumberExportHttps=0;
1007 kumpf      1.53  
1008 kumpf      1.86      if (enableHttpsConnection)
1009 kumpf      1.53      {
1010 kumpf      1.86          String httpsPort = configManager->getCurrentValue("httpsPort");
1011 h.sterling 1.158         if (httpsPort == String::EMPTY)
1012 joyce.j    1.144         {
1013 h.sterling 1.158             //
1014                              // Look up the WBEM-HTTPS port number
1015                              //
1016                              portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
1017                  
1018                          } else
1019                          {        
1020                              //
1021                              // user-specified
1022                              //
1023                              CString portString = httpsPort.getCString();
1024                              char* end = 0;
1025                              portNumberHttps = strtol(portString, &end, 10);
1026                              if(!(end != 0 && *end == '\0'))
1027                              {
1028 joyce.j    1.160                 InvalidPropertyValue e("httpsPort", httpsPort);
1029                                  cerr << e.getMessage() << endl;
1030 h.sterling 1.158                 exit(1);
1031                              }
1032 joyce.j    1.144         }
1033 kumpf      1.53      }
1034 kumpf      1.86  
1035                      if (enableHttpConnection)
1036 kumpf      1.53      {
1037 kumpf      1.86          String httpPort = configManager->getCurrentValue("httpPort");
1038 h.sterling 1.158         if (httpPort == String::EMPTY)
1039 joyce.j    1.144         {
1040 h.sterling 1.158             //
1041                              // Look up the WBEM-HTTP port number
1042                              //
1043                              portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
1044                  
1045                          } else
1046                          {
1047                              //
1048                              // user-specified
1049                              //
1050                              CString portString = httpPort.getCString();
1051                              char* end = 0;
1052                              portNumberHttp = strtol(portString, &end, 10);
1053                              if(!(end != 0 && *end == '\0'))
1054                              {
1055 joyce.j    1.160                 InvalidPropertyValue e("httpPort", httpPort);
1056                                  cerr << e.getMessage() << endl;
1057 h.sterling 1.158                 exit(1);
1058                              }
1059 joyce.j    1.144         }
1060 kumpf      1.53      }
1061 mike       1.32  
1062 h.sterling 1.158 
1063 kumpf      1.135     if (enableSSLExportClientVerification)
1064                      {
1065                          //
1066                          // No config property is looked up to get the default port number.
1067                          // Lookup the port defined in /etc/services for the service name
1068                          // wbem-exp-https and bind to that port. If the service is  not defined
1069                          // then log a warning message and do not start the cimserver.
1070                          //
1071                          Uint32 port = 0;
1072                  
1073                          portNumberExportHttps = System::lookupPort(WBEM_EXPORT_HTTPS_SERVICE_NAME, port);
1074                  
1075                          if (portNumberExportHttps == 0)
1076                          {
1077                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1078                                  "src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
1079                                  "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
1080                  
1081                              MessageLoaderParms parms("src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
1082                                  "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
1083                  
1084 kumpf      1.135             cerr << MessageLoader::getMessage(parms) << endl;
1085                  
1086                              return(1);
1087                          }
1088                      }
1089 kumpf      1.139 #if defined(PEGASUS_DEBUG)
1090 mike       1.32      // Put out startup up message.
1091 h.sterling 1.153     cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;
1092 humberto   1.97      //l10n
1093                      //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
1094                      //cout <<"Starting..."
1095                      MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
1096 h.sterling 1.153                              "Built $0 $1\nStarting...",
1097                                               __DATE__,
1098                                               __TIME__);
1099 humberto   1.97  #endif
1100                  
1101                  //l10n
1102                  // reset message loading to NON-process locale
1103                  MessageLoader::_useProcessLocale = false; 
1104                  //l10n
1105 mike       1.32  
1106 kumpf      1.137     // Get the parent's PID before forking
1107 h.sterling 1.154     _cimServerProcess->set_parent_pid(System::getPID());
1108                      
1109 kumpf      1.63      // do we need to run as a daemon ?
1110                      if (daemonOption)
1111                      {
1112 h.sterling 1.153         if(-1 == _cimServerProcess->cimserver_fork())
1113 diane      1.81  #ifndef PEGASUS_OS_OS400
1114 h.sterling 1.153     {
1115                          return(-1);
1116                      }
1117 diane      1.81  #else
1118 h.sterling 1.153     {
1119 david      1.85              return(-1);
1120 h.sterling 1.153     }
1121                      else
1122                      {
1123                          return(0);
1124                      }
1125 diane      1.81  #endif
1126 h.sterling 1.153     
1127 kumpf      1.63      }
1128 chuck      1.66  
1129 chuck      1.96  // l10n
1130                      // Now we are after the fork...
1131                      // Create a dummy Thread object that can be used to store the
1132                      // AcceptLanguages object for CIM requests that are serviced
1133                      // by this thread (initial thread of server).  Need to do this
1134                      // because this thread is not in a ThreadPool, but is used
1135                      // to service CIM requests.
1136                      // The run function for the dummy Thread should never be called,
1137                      Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
1138 humberto   1.108     Thread::setCurrent(dummyInitialThread); 
1139                      AcceptLanguages default_al;
1140                      try{
1141 h.sterling 1.153          default_al = AcceptLanguages::getDefaultAcceptLanguages();   
1142                           Thread::setLanguages(new AcceptLanguages(default_al));
1143 kumpf      1.122     }catch(InvalidAcceptLanguageHeader& e){
1144 h.sterling 1.153           Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1145                                    "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
1146                                    "Could not convert the system process locale into a valid AcceptLanguage format.");  
1147                            Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1148                                               e.getMessage()); 
1149 humberto   1.108     }
1150 humberto   1.109     
1151 humberto   1.97      
1152 chuck      1.96  
1153 chuck      1.66  #ifdef PEGASUS_OS_OS400
1154                      // Special server initialization code for OS/400.
1155                      if (cimserver_initialize() != 0)
1156                      {
1157 h.sterling 1.153     // do some logging here!
1158                      //l10n
1159                      //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1160                              //"CIM Server failed to initialize"); 
1161                      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1162                                    "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE",
1163                                    "CIM Server failed to initialize");  
1164                      return(-1);
1165 chuck      1.66      } 
1166                  #endif
1167 chuck      1.96  
1168 mday       1.62  
1169 gs.keenan  1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1170                  || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1171                  || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || defined (PEGASUS_OS_VMS)
1172 kumpf      1.63      umask(S_IWGRP|S_IWOTH);
1173 kumpf      1.79  
1174                      //
1175                      // check if CIMServer is already running
1176                      // if CIMServer is already running, print message and 
1177                      // notify parent process (if there is a parent process) to terminate
1178                      //
1179 h.sterling 1.153     if(_cimServerProcess->isCIMServerRunning())
1180 kumpf      1.79      {
1181 h.sterling 1.153     //l10n
1182                          //cout << "Unable to start CIMServer." << endl;
1183                          //cout << "CIMServer is already running." << endl;
1184                          MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
1185                                       "Unable to start CIMServer.\nCIMServer is already running.");
1186                      PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1187 kumpf      1.79  
1188 h.sterling 1.153     //
1189 kumpf      1.79          // notify parent process (if there is a parent process) to terminate
1190                          //
1191                          if (daemonOption)
1192 h.sterling 1.153                 _cimServerProcess->notify_parent(1);
1193 kumpf      1.79  
1194 s.hills    1.117         return(1);
1195 kumpf      1.79      }
1196                       
1197 kumpf      1.63  #endif
1198 kumpf      1.51  
1199 mike       1.32      // try loop to bind the address, and run the server
1200                      try
1201                      {
1202 mday       1.116 
1203 h.sterling 1.153     Monitor monitor;
1204                      //PEP#222
1205                      //CIMServer server(&monitor);
1206                      //CimserverHolder cimserverHolder( &server );
1207                      _cimServer = new CIMServer(&monitor);
1208 mday       1.111 
1209 kumpf      1.41  
1210 kumpf      1.86          if (enableHttpConnection)
1211                          {
1212 h.sterling 1.153             _cimServer->addAcceptor(false, portNumberHttp, false, false);
1213 humberto   1.97              //l10n
1214                              //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1215                                          //"Listening on HTTP port $0.", portNumberHttp);
1216                                          
1217                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1218 h.sterling 1.153                             "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1219                                              "Listening on HTTP port $0.", portNumberHttp);
1220 kumpf      1.86          }
1221                          if (enableHttpsConnection)
1222                          {
1223 h.sterling 1.153             _cimServer->addAcceptor(false, portNumberHttps, true, false);
1224 humberto   1.97              //l10n
1225                              //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1226                                          //"Listening on HTTPS port $0.", portNumberHttps);
1227                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1228 h.sterling 1.153                             "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1229                                              "Listening on HTTPS port $0.", portNumberHttps);
1230 kumpf      1.86          }
1231 kumpf      1.135         if (enableSSLExportClientVerification)
1232                          {
1233 h.sterling 1.153             _cimServer->addAcceptor(false, portNumberExportHttps, true, true);
1234 kumpf      1.135 
1235                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1236                                  "src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1237                                  "Listening on Export HTTPS port $0.", portNumberExportHttps);
1238                          }
1239                  
1240 h.sterling 1.159 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1241 h.sterling 1.153         _cimServer->addAcceptor(true, 0, false, false);
1242 humberto   1.97          //l10n
1243                          //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1244                                      //"Listening on local connection socket.");
1245                          Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1246 h.sterling 1.153               "src.Server.cimserver.LISTENING_ON_LOCAL",
1247                                "Listening on local connection socket.");
1248 kumpf      1.41  #endif
1249 kumpf      1.86  
1250 kumpf      1.139 #if defined(PEGASUS_DEBUG)
1251 kumpf      1.86          if (enableHttpConnection)
1252                          {
1253 humberto   1.97              //l10n
1254                              //cout << "Listening on HTTP port " << portNumberHttp << endl;
1255 h.sterling 1.153       MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1256                                     "Listening on HTTP port $0.", portNumberHttp);
1257                              cout << MessageLoader::getMessage(parms) << endl;
1258 kumpf      1.86          }
1259                          if (enableHttpsConnection)
1260                          {
1261 humberto   1.97              //l10n
1262                              //cout << "Listening on HTTPS port " << portNumberHttps << endl;
1263 humberto   1.103             MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1264 h.sterling 1.153                      "Listening on HTTPS port $0.", portNumberHttps);
1265                              cout << MessageLoader::getMessage(parms) << endl;
1266 kumpf      1.86          }
1267 kumpf      1.135         if (enableSSLExportClientVerification)
1268                          {
1269                              MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1270                                  "Listening on Export HTTPS port $0.", portNumberExportHttps);
1271                  
1272                              cout << MessageLoader::getMessage(parms) << endl;
1273                          }
1274                  
1275 h.sterling 1.159 # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1276 humberto   1.97          //l10n
1277                          //cout << "Listening on local connection socket" << endl;
1278                          MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",
1279 h.sterling 1.153                  "Listening on local connection socket.");
1280 humberto   1.97          cout << MessageLoader::getMessage(parms) << endl;
1281 kumpf      1.86  # endif
1282 david      1.85  #endif
1283 mike       1.35  
1284 kumpf      1.86          // bind throws an exception if the bind fails
1285 h.sterling 1.153         _cimServer->bind();
1286 kumpf      1.73  
1287 h.sterling 1.153     // notify parent process (if there is a parent process) to terminate 
1288 konrad.r   1.95          // so user knows that there is cimserver ready to serve CIM requests.
1289 h.sterling 1.153     if (daemonOption)
1290                          _cimServerProcess->notify_parent(0);
1291 mike       1.32  
1292 h.sterling 1.153     time_t last = 0;
1293 mike       1.35  
1294 gs.keenan  1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \
1295                      || defined(PEGASUS_OS_AIX) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) \
1296                      || defined(PEGASUS_OS_VMS)
1297 kumpf      1.45          //
1298 kumpf      1.56          // create a file to indicate that the cimserver has started and
1299                          // save the process id of the cimserver process in the file
1300 kumpf      1.45          //
1301 kumpf      1.56          // remove the old file if it exists
1302 h.sterling 1.153         System::removeFile(_cimServerProcess->getPIDFileName());
1303 kumpf      1.56  
1304                          // open the file
1305 h.sterling 1.153         FILE *pid_file = fopen(_cimServerProcess->getPIDFileName(), "w");
1306 kumpf      1.91  
1307 kumpf      1.56          if (pid_file)
1308 kumpf      1.45          {
1309 kumpf      1.56              // save the pid in the file
1310 h.sterling 1.153             fprintf(pid_file, "%ld\n", _cimServerProcess->get_server_pid());
1311 kumpf      1.56              fclose(pid_file);
1312 kumpf      1.45          }
1313                  #endif
1314 kumpf      1.91  
1315 kumpf      1.139 #if defined(PEGASUS_DEBUG)
1316 h.sterling 1.153     cout << "Started. " << endl;
1317 kumpf      1.63  #endif
1318 h.sterling 1.153     
1319 kumpf      1.54          // Put server started message to the logger
1320 kumpf      1.143         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1321                              Logger::INFORMATION,
1322                              "src.Server.cimserver.STARTED_VERSION",
1323                              "Started $0 version $1.",
1324 h.sterling 1.153             _cimServerProcess->getProductName(), _cimServerProcess->getVersion());
1325 kumpf      1.45  
1326 mike       1.35          //
1327                          // Loop to call CIMServer's runForever() method until CIMServer
1328                          // has been shutdown
1329                          //
1330 h.sterling 1.153     while( !_cimServer->terminated() )
1331                      {
1332 mday       1.116 
1333 h.sterling 1.153       _cimServer->runForever();
1334 mday       1.112 
1335 h.sterling 1.153     }
1336 carson.hovey 1.157 
1337 kumpf        1.45          //
1338                            // normal termination
1339 carson.hovey 1.157         //
1340 kumpf        1.143 
1341 kumpf        1.54          // Put server shutdown message to the logger
1342 kumpf        1.143         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1343                                Logger::INFORMATION, "src.Server.cimserver.STOPPED",
1344 h.sterling   1.153             "$0 stopped.", _cimServerProcess->getProductName());
1345 kumpf        1.45  
1346 gs.keenan    1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1347                    || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1348                    || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || defined(PEGASUS_OS_VMS)
1349 kumpf        1.45          //
1350 kumpf        1.56          // close the file created at startup time to indicate that the 
1351                            // cimserver has terminated normally.
1352 kumpf        1.45          //
1353 h.sterling   1.153         FileSystem::removeFile(_cimServerProcess->getPIDFileName());
1354 kumpf        1.45  #endif
1355 mike         1.32      }
1356                        catch(Exception& e)
1357                        {
1358 david        1.100 
1359 h.sterling   1.153     //l10n
1360                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1361                                //"Error: $0", e.getMessage()); 
1362                        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1363                                "src.Server.cimserver.ERROR",
1364                                "Error: $0", e.getMessage());  
1365 konrad.r     1.95  
1366                    #ifndef PEGASUS_OS_OS400
1367 h.sterling   1.153     //l10n
1368                        //PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1369                        MessageLoaderParms parms("src.Server.cimserver.ERROR",
1370                                                 "Error: $0", e.getMessage());
1371                        PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1372 david        1.100 
1373 david        1.85  #endif
1374 kumpf        1.77  
1375 h.sterling   1.153     //
1376 kumpf        1.77          // notify parent process (if there is a parent process) to terminate
1377                            //
1378                            if (daemonOption)
1379 h.sterling   1.153                 _cimServerProcess->notify_parent(1);
1380 kumpf        1.77  
1381 h.sterling   1.156         deleteCIMServer();
1382 kumpf        1.54          return 1;
1383 mike         1.32      }
1384                    
1385 h.sterling   1.156     deleteCIMServer();
1386 mike         1.32      return 0;
1387                    }
1388 tony         1.128 
1389                    
1390                    
1391                    

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2