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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2