(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 chuck      1.164 
 814                      if (!os400StartupOption)
 815                      {
 816                          // If this is the server job, then set the job
 817                          // to save the job log.
 818                          system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
 819                      }
 820 lucier     1.130 #endif    
 821                  
 822 mike       1.35      //
 823 mike       1.32      // Get options (from command line and from configuration file); this
 824 mike       1.35      // removes corresponding options and their arguments from the command
 825 mike       1.32      // line.
 826 mike       1.35      //
 827 mike       1.32      try
 828                      {
 829 lucier     1.130 #ifdef PEGASUS_OS_OS400
 830                      if (os400StartupOption == false)
 831                  #endif   
 832 s.hills    1.117         GetOptions(configManager, argc, argv);
 833 mike       1.32      }
 834                      catch (Exception& e)
 835                      {
 836 kumpf      1.127         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 837                              "src.Server.cimserver.SERVER_NOT_STARTED",
 838                              "cimserver not started:  $0", e.getMessage());
 839                  
 840                  #if !defined(PEGASUS_OS_OS400)
 841                          MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 842                              "cimserver not started: $0", e.getMessage());
 843                  
 844                          PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
 845                              << PEGASUS_STD(endl);
 846 david      1.85  #endif
 847 kumpf      1.127 
 848 s.hills    1.117         return(1);
 849 mike       1.32      }
 850                  
 851 chuck      1.94  // l10n
 852 h.sterling 1.153     // Set the home directory, msg sub-dir, into the MessageLoader.
 853                      // This will be the default directory where the resource bundles 
 854                      // are found.    
 855                      MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
 856                          ConfigManager::getInstance()->getCurrentValue("messageDir")));      
 857 chuck      1.94  
 858 lucier     1.130 #ifdef PEGASUS_OS_OS400
 859                      // Still need to declare and set the connection variables.
 860                      // Will initialize to false since they are fixed at false for OS400.
 861                  
 862                      // NOTE:  OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down
 863                      // the test will not be compiled in.  If OS400 ever turns off that
 864                      // define, then we will need to change this code path to insure that
 865                      // one of the variables is true.    
 866                      Boolean enableHttpConnection = false;
 867                      Boolean enableHttpsConnection = false;
 868 kumpf      1.135     Boolean enableSSLExportClientVerification = false;
 869 lucier     1.130 
 870                      if (os400StartupOption == false)
 871                      {
 872                        enableHttpConnection = String::equal(
 873                            configManager->getCurrentValue("enableHttpConnection"), "true");
 874                        enableHttpsConnection = String::equal(
 875                            configManager->getCurrentValue("enableHttpsConnection"), "true");
 876 kumpf      1.135       enableSSLExportClientVerification = String::equal(
 877                            configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
 878 lucier     1.130     }
 879                  #else
 880 kumpf      1.87      Boolean enableHttpConnection = String::equal(
 881                          configManager->getCurrentValue("enableHttpConnection"), "true");
 882                      Boolean enableHttpsConnection = String::equal(
 883                          configManager->getCurrentValue("enableHttpsConnection"), "true");
 884 kumpf      1.135     Boolean enableSSLExportClientVerification = String::equal(
 885                          configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
 886 lucier     1.130 #endif
 887 kumpf      1.86  
 888                      // Make sure at least one connection is enabled
 889 h.sterling 1.159 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
 890 kumpf      1.86      if (!enableHttpConnection && !enableHttpsConnection)
 891                      {
 892 humberto   1.97          //l10n
 893                          //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 894                              //"Neither HTTP nor HTTPS connection is enabled.  "
 895                              //"CIMServer will not be started.");
 896                          Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 897 h.sterling 1.153             "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 898 humberto   1.97              "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 899                          //cerr << "Neither HTTP nor HTTPS connection is enabled.  "
 900                              //"CIMServer will not be started." << endl;
 901                          MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 902 h.sterling 1.153                                  "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 903 humberto   1.97          cerr << MessageLoader::getMessage(parms) << endl;
 904 s.hills    1.117         return(1);
 905 kumpf      1.86      }
 906                  #endif
 907                  
 908 mike       1.35      try
 909 mike       1.32      {
 910 mike       1.35          //
 911                          // Check to see if we should Pegasus as a daemon
 912                          //
 913                  
 914                          if (String::equal(configManager->getCurrentValue("daemon"), "true"))
 915                          {
 916                              daemonOption = true;
 917                          }
 918 h.sterling 1.153     
 919 lucier     1.130 #ifdef PEGASUS_OS_OS400
 920                      if (os400StartupOption == false)
 921                      {
 922                  #endif            
 923 kumpf      1.36          // Get the log file directory definition.
 924                          // We put String into Cstring because
 925                          // Directory functions only handle Cstring.
 926                          // ATTN-KS: create String based directory functions.
 927 konrad.r   1.161 #if !defined(PEGASUS_USE_SYSLOGS)
 928                  		// When using syslog facility. No files anymore.
 929 kumpf      1.36          logsDirectory = configManager->getCurrentValue("logdir");
 930 kumpf      1.38          logsDirectory = 
 931 h.sterling 1.153         ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
 932 konrad.r   1.161 #endif
 933 lucier     1.130 #ifdef PEGASUS_OS_OS400
 934                      }  // end if (os400StartupOption == false)
 935                  #endif
 936 kumpf      1.36  
 937                          // Set up the Logger. This does not open the logs
 938                          // Might be more logical to clean before set.
 939                          // ATTN: Need tool to completely disable logging.
 940                  
 941 david      1.85  #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 942 konrad.r   1.161 !defined(PEGASUS_OS_OS400) && !defined(PEGASUS_USE_SYSLOGS)
 943 kumpf      1.36          Logger::setHomeDirectory(logsDirectory);
 944 kumpf      1.57  #endif
 945 kumpf      1.36  
 946                          //
 947 mike       1.35          // Check to see if we need to shutdown CIMOM 
 948                          //
 949                          if (shutdownOption)
 950                          {
 951 kumpf      1.60              String configTimeout = 
 952                                  configManager->getCurrentValue("shutdownTimeout");
 953 s.hills    1.117             Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
 954 kumpf      1.60              
 955 kumpf      1.52              shutdownCIMOM(timeoutValue);
 956 kumpf      1.45  
 957 david      1.85  #ifdef PEGASUS_OS_OS400
 958 h.sterling 1.153         //l10n
 959                          //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 960                              //"CIM Server stopped.");  
 961                          Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 962                              "src.Server.cimserver.SERVER_STOPPED",
 963                              "CIM Server stopped.");
 964 s.hills    1.117             cimserver_exitRC(0);
 965 david      1.85  #else
 966 h.sterling 1.153             //l10n
 967 humberto   1.97              //cout << "CIM Server stopped." << endl;
 968                              MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",
 969 h.sterling 1.153                                      "CIM Server stopped.");
 970 humberto   1.106 
 971 humberto   1.97              cout << MessageLoader::getMessage(parms) << endl;
 972 s.hills    1.117             return(0);
 973 diane      1.81  #endif
 974 mike       1.35          }
 975 mike       1.32  
 976 kumpf      1.139 #if defined(PEGASUS_DEBUG)
 977 kumpf      1.36          // Leave this in until people get familiar with the logs.
 978 humberto   1.97          //l10n
 979                          //cout << "Logs Directory = " << logsDirectory << endl;
 980 konrad.r   1.161 #if !defined(PEGASUS_USE_SYSLOGS)
 981 humberto   1.97          MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
 982 h.sterling 1.153                                  "Logs Directory = ");
 983 humberto   1.97          cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
 984 kumpf      1.57  #endif
 985 konrad.r   1.161 #endif
 986 mike       1.32      }
 987 kumpf      1.122     catch (UnrecognizedConfigProperty& e)
 988 mike       1.32      {
 989 david      1.85  
 990                  #ifdef PEGASUS_OS_OS400
 991 h.sterling 1.153     //l10n
 992                      //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 993                              //"Error: $0",e.getMessage());  
 994                      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 995                              "src.Server.cimserver.ERROR",
 996                              "Error: $0",e.getMessage()); 
 997 david      1.85  #else
 998 h.sterling 1.153     //l10n
 999                      //cout << "Error: " << e.getMessage() << endl;
1000                      MessageLoaderParms parms("src.Server.cimserver.ERROR",
1001                                               "Error: $0",
1002                                               e.getMessage());
1003                      cout << MessageLoader::getMessage(parms) << endl;
1004 david      1.85  #endif
1005 mike       1.32      }
1006                  
1007 h.sterling 1.158     // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.
1008                      // 1) If the user explicitly specified a port, use it.
1009                      // 2) If the user did not specify a port, get the port from the services file.
1010                      // 3) If no value is specified in the services file, use the IANA WBEM default port.
1011                      // Note that 2 and 3 are done within the System::lookupPort method
1012                      // An empty string from the ConfigManager implies that the user did not specify a port.
1013                  
1014 w.otsuka   1.147     Uint32 portNumberHttps=0;
1015                      Uint32 portNumberHttp=0;
1016                      Uint32 portNumberExportHttps=0;
1017 kumpf      1.53  
1018 kumpf      1.86      if (enableHttpsConnection)
1019 kumpf      1.53      {
1020 kumpf      1.86          String httpsPort = configManager->getCurrentValue("httpsPort");
1021 h.sterling 1.158         if (httpsPort == String::EMPTY)
1022 joyce.j    1.144         {
1023 h.sterling 1.158             //
1024                              // Look up the WBEM-HTTPS port number
1025                              //
1026                              portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
1027                  
1028                          } else
1029                          {        
1030                              //
1031                              // user-specified
1032                              //
1033                              CString portString = httpsPort.getCString();
1034                              char* end = 0;
1035                              portNumberHttps = strtol(portString, &end, 10);
1036                              if(!(end != 0 && *end == '\0'))
1037                              {
1038 joyce.j    1.160                 InvalidPropertyValue e("httpsPort", httpsPort);
1039                                  cerr << e.getMessage() << endl;
1040 h.sterling 1.158                 exit(1);
1041                              }
1042 joyce.j    1.144         }
1043 kumpf      1.53      }
1044 kumpf      1.86  
1045                      if (enableHttpConnection)
1046 kumpf      1.53      {
1047 kumpf      1.86          String httpPort = configManager->getCurrentValue("httpPort");
1048 h.sterling 1.158         if (httpPort == String::EMPTY)
1049 joyce.j    1.144         {
1050 h.sterling 1.158             //
1051                              // Look up the WBEM-HTTP port number
1052                              //
1053                              portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
1054                  
1055                          } else
1056                          {
1057                              //
1058                              // user-specified
1059                              //
1060                              CString portString = httpPort.getCString();
1061                              char* end = 0;
1062                              portNumberHttp = strtol(portString, &end, 10);
1063                              if(!(end != 0 && *end == '\0'))
1064                              {
1065 joyce.j    1.160                 InvalidPropertyValue e("httpPort", httpPort);
1066                                  cerr << e.getMessage() << endl;
1067 h.sterling 1.158                 exit(1);
1068                              }
1069 joyce.j    1.144         }
1070 kumpf      1.53      }
1071 mike       1.32  
1072 h.sterling 1.158 
1073 kumpf      1.135     if (enableSSLExportClientVerification)
1074                      {
1075                          //
1076                          // No config property is looked up to get the default port number.
1077                          // Lookup the port defined in /etc/services for the service name
1078                          // wbem-exp-https and bind to that port. If the service is  not defined
1079                          // then log a warning message and do not start the cimserver.
1080                          //
1081                          Uint32 port = 0;
1082                  
1083                          portNumberExportHttps = System::lookupPort(WBEM_EXPORT_HTTPS_SERVICE_NAME, port);
1084                  
1085                          if (portNumberExportHttps == 0)
1086                          {
1087                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1088                                  "src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
1089                                  "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
1090                  
1091                              MessageLoaderParms parms("src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED",
1092                                  "Port not defined for the service wbem-exp-https. CIMServer will not be started.");
1093                  
1094 kumpf      1.135             cerr << MessageLoader::getMessage(parms) << endl;
1095                  
1096                              return(1);
1097                          }
1098                      }
1099 kumpf      1.139 #if defined(PEGASUS_DEBUG)
1100 mike       1.32      // Put out startup up message.
1101 h.sterling 1.153     cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getVersion() << endl;
1102 humberto   1.97      //l10n
1103                      //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
1104                      //cout <<"Starting..."
1105                      MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
1106 h.sterling 1.153                              "Built $0 $1\nStarting...",
1107                                               __DATE__,
1108                                               __TIME__);
1109 humberto   1.97  #endif
1110                  
1111                  //l10n
1112                  // reset message loading to NON-process locale
1113                  MessageLoader::_useProcessLocale = false; 
1114                  //l10n
1115 mike       1.32  
1116 kumpf      1.137     // Get the parent's PID before forking
1117 h.sterling 1.154     _cimServerProcess->set_parent_pid(System::getPID());
1118                      
1119 kumpf      1.63      // do we need to run as a daemon ?
1120                      if (daemonOption)
1121                      {
1122 h.sterling 1.153         if(-1 == _cimServerProcess->cimserver_fork())
1123 diane      1.81  #ifndef PEGASUS_OS_OS400
1124 h.sterling 1.153     {
1125                          return(-1);
1126                      }
1127 diane      1.81  #else
1128 h.sterling 1.153     {
1129 david      1.85              return(-1);
1130 h.sterling 1.153     }
1131                      else
1132                      {
1133                          return(0);
1134                      }
1135 diane      1.81  #endif
1136 h.sterling 1.153     
1137 kumpf      1.63      }
1138 chuck      1.66  
1139 chuck      1.96  // l10n
1140                      // Now we are after the fork...
1141                      // Create a dummy Thread object that can be used to store the
1142                      // AcceptLanguages object for CIM requests that are serviced
1143                      // by this thread (initial thread of server).  Need to do this
1144                      // because this thread is not in a ThreadPool, but is used
1145                      // to service CIM requests.
1146                      // The run function for the dummy Thread should never be called,
1147                      Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
1148 humberto   1.108     Thread::setCurrent(dummyInitialThread); 
1149                      AcceptLanguages default_al;
1150                      try{
1151 h.sterling 1.153          default_al = AcceptLanguages::getDefaultAcceptLanguages();   
1152                           Thread::setLanguages(new AcceptLanguages(default_al));
1153 kumpf      1.122     }catch(InvalidAcceptLanguageHeader& e){
1154 h.sterling 1.153           Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1155                                    "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
1156                                    "Could not convert the system process locale into a valid AcceptLanguage format.");  
1157                            Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1158                                               e.getMessage()); 
1159 humberto   1.108     }
1160 humberto   1.109     
1161 humberto   1.97      
1162 chuck      1.96  
1163 chuck      1.66  #ifdef PEGASUS_OS_OS400
1164                      // Special server initialization code for OS/400.
1165                      if (cimserver_initialize() != 0)
1166                      {
1167 h.sterling 1.153     // do some logging here!
1168                      //l10n
1169                      //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1170                              //"CIM Server failed to initialize"); 
1171                      Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1172                                    "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE",
1173                                    "CIM Server failed to initialize");  
1174                      return(-1);
1175 chuck      1.66      } 
1176                  #endif
1177 chuck      1.96  
1178 mday       1.62  
1179 gs.keenan  1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1180                  || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1181                  || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || defined (PEGASUS_OS_VMS)
1182 kumpf      1.63      umask(S_IWGRP|S_IWOTH);
1183 kumpf      1.79  
1184                      //
1185                      // check if CIMServer is already running
1186                      // if CIMServer is already running, print message and 
1187                      // notify parent process (if there is a parent process) to terminate
1188                      //
1189 h.sterling 1.153     if(_cimServerProcess->isCIMServerRunning())
1190 kumpf      1.79      {
1191 h.sterling 1.153     //l10n
1192                          //cout << "Unable to start CIMServer." << endl;
1193                          //cout << "CIMServer is already running." << endl;
1194                          MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
1195                                       "Unable to start CIMServer.\nCIMServer is already running.");
1196                      PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1197 kumpf      1.79  
1198 h.sterling 1.153     //
1199 kumpf      1.79          // notify parent process (if there is a parent process) to terminate
1200                          //
1201                          if (daemonOption)
1202 h.sterling 1.153                 _cimServerProcess->notify_parent(1);
1203 kumpf      1.79  
1204 s.hills    1.117         return(1);
1205 kumpf      1.79      }
1206                       
1207 kumpf      1.63  #endif
1208 kumpf      1.51  
1209 mike       1.32      // try loop to bind the address, and run the server
1210                      try
1211                      {
1212 mday       1.116 
1213 konrad.r   1.163     _monitor  = new Monitor();
1214 h.sterling 1.153     //PEP#222
1215                      //CIMServer server(&monitor);
1216                      //CimserverHolder cimserverHolder( &server );
1217 konrad.r   1.163     _cimServer = new CIMServer(_monitor);
1218 mday       1.111 
1219 kumpf      1.41  
1220 kumpf      1.86          if (enableHttpConnection)
1221                          {
1222 h.sterling 1.153             _cimServer->addAcceptor(false, portNumberHttp, false, false);
1223 humberto   1.97              //l10n
1224                              //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1225                                          //"Listening on HTTP port $0.", portNumberHttp);
1226                                          
1227                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1228 h.sterling 1.153                             "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1229                                              "Listening on HTTP port $0.", portNumberHttp);
1230 kumpf      1.86          }
1231                          if (enableHttpsConnection)
1232                          {
1233 h.sterling 1.153             _cimServer->addAcceptor(false, portNumberHttps, true, false);
1234 humberto   1.97              //l10n
1235                              //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1236                                          //"Listening on HTTPS port $0.", portNumberHttps);
1237                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1238 h.sterling 1.153                             "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1239                                              "Listening on HTTPS port $0.", portNumberHttps);
1240 kumpf      1.86          }
1241 kumpf      1.135         if (enableSSLExportClientVerification)
1242                          {
1243 h.sterling 1.153             _cimServer->addAcceptor(false, portNumberExportHttps, true, true);
1244 kumpf      1.135 
1245                              Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1246                                  "src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1247                                  "Listening on Export HTTPS port $0.", portNumberExportHttps);
1248                          }
1249                  
1250 h.sterling 1.159 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1251 h.sterling 1.153         _cimServer->addAcceptor(true, 0, false, false);
1252 humberto   1.97          //l10n
1253                          //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1254                                      //"Listening on local connection socket.");
1255                          Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1256 h.sterling 1.153               "src.Server.cimserver.LISTENING_ON_LOCAL",
1257                                "Listening on local connection socket.");
1258 kumpf      1.41  #endif
1259 kumpf      1.86  
1260 kumpf      1.139 #if defined(PEGASUS_DEBUG)
1261 kumpf      1.86          if (enableHttpConnection)
1262                          {
1263 humberto   1.97              //l10n
1264                              //cout << "Listening on HTTP port " << portNumberHttp << endl;
1265 h.sterling 1.153       MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1266                                     "Listening on HTTP port $0.", portNumberHttp);
1267                              cout << MessageLoader::getMessage(parms) << endl;
1268 kumpf      1.86          }
1269                          if (enableHttpsConnection)
1270                          {
1271 humberto   1.97              //l10n
1272                              //cout << "Listening on HTTPS port " << portNumberHttps << endl;
1273 humberto   1.103             MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1274 h.sterling 1.153                      "Listening on HTTPS port $0.", portNumberHttps);
1275                              cout << MessageLoader::getMessage(parms) << endl;
1276 kumpf      1.86          }
1277 kumpf      1.135         if (enableSSLExportClientVerification)
1278                          {
1279                              MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1280                                  "Listening on Export HTTPS port $0.", portNumberExportHttps);
1281                  
1282                              cout << MessageLoader::getMessage(parms) << endl;
1283                          }
1284                  
1285 h.sterling 1.159 # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1286 humberto   1.97          //l10n
1287                          //cout << "Listening on local connection socket" << endl;
1288                          MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",
1289 h.sterling 1.153                  "Listening on local connection socket.");
1290 humberto   1.97          cout << MessageLoader::getMessage(parms) << endl;
1291 kumpf      1.86  # endif
1292 david      1.85  #endif
1293 mike       1.35  
1294 kumpf      1.86          // bind throws an exception if the bind fails
1295 konrad.r   1.163 	try { 
1296                             _cimServer->bind();
1297                  	} catch (const BindFailedException &e)
1298                  	{
1299                  #ifdef PEGASUS_DEBUG
1300                          MessageLoaderParms parms("src.Server.cimserver.BIND_FAILED",
1301                                   "Could not bind: $0.", e.getMessage());
1302                          cout << MessageLoader::getMessage(parms) << endl;
1303                  #endif
1304                          Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1305                              "src.Server.cimserver.BIND.FAILED",
1306                              "Could not bind:  $0", e.getMessage());
1307 kumpf      1.73  
1308 konrad.r   1.163 	   deleteCIMServer();
1309                  	   return 1;
1310                  	}
1311 h.sterling 1.153     // notify parent process (if there is a parent process) to terminate 
1312 konrad.r   1.95          // so user knows that there is cimserver ready to serve CIM requests.
1313 h.sterling 1.153     if (daemonOption)
1314                          _cimServerProcess->notify_parent(0);
1315 mike       1.32  
1316 h.sterling 1.153     time_t last = 0;
1317 mike       1.35  
1318 gs.keenan  1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \
1319                      || defined(PEGASUS_OS_AIX) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) \
1320                      || defined(PEGASUS_OS_VMS)
1321 kumpf      1.45          //
1322 kumpf      1.56          // create a file to indicate that the cimserver has started and
1323                          // save the process id of the cimserver process in the file
1324 kumpf      1.45          //
1325 kumpf      1.56          // remove the old file if it exists
1326 h.sterling 1.153         System::removeFile(_cimServerProcess->getPIDFileName());
1327 kumpf      1.56  
1328                          // open the file
1329 h.sterling 1.153         FILE *pid_file = fopen(_cimServerProcess->getPIDFileName(), "w");
1330 kumpf      1.91  
1331 kumpf      1.56          if (pid_file)
1332 kumpf      1.45          {
1333 kumpf      1.56              // save the pid in the file
1334 h.sterling 1.153             fprintf(pid_file, "%ld\n", _cimServerProcess->get_server_pid());
1335 kumpf      1.56              fclose(pid_file);
1336 kumpf      1.45          }
1337                  #endif
1338 kumpf      1.91  
1339 kumpf      1.139 #if defined(PEGASUS_DEBUG)
1340 h.sterling 1.153     cout << "Started. " << endl;
1341 kumpf      1.63  #endif
1342 h.sterling 1.153     
1343 kumpf      1.54          // Put server started message to the logger
1344 kumpf      1.143         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1345                              Logger::INFORMATION,
1346                              "src.Server.cimserver.STARTED_VERSION",
1347                              "Started $0 version $1.",
1348 h.sterling 1.153             _cimServerProcess->getProductName(), _cimServerProcess->getVersion());
1349 kumpf      1.45  
1350 mike       1.35          //
1351                          // Loop to call CIMServer's runForever() method until CIMServer
1352                          // has been shutdown
1353                          //
1354 h.sterling 1.153     while( !_cimServer->terminated() )
1355                      {
1356 mday       1.116 
1357 h.sterling 1.153       _cimServer->runForever();
1358 mday       1.112 
1359 h.sterling 1.153     }
1360 carson.hovey 1.157 
1361 kumpf        1.45          //
1362                            // normal termination
1363 carson.hovey 1.157         //
1364 kumpf        1.143 
1365 kumpf        1.54          // Put server shutdown message to the logger
1366 kumpf        1.143         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1367                                Logger::INFORMATION, "src.Server.cimserver.STOPPED",
1368 h.sterling   1.153             "$0 stopped.", _cimServerProcess->getProductName());
1369 kumpf        1.45  
1370 gs.keenan    1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1371                    || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1372                    || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || defined(PEGASUS_OS_VMS)
1373 kumpf        1.45          //
1374 kumpf        1.56          // close the file created at startup time to indicate that the 
1375                            // cimserver has terminated normally.
1376 kumpf        1.45          //
1377 h.sterling   1.153         FileSystem::removeFile(_cimServerProcess->getPIDFileName());
1378 kumpf        1.45  #endif
1379 mike         1.32      }
1380                        catch(Exception& e)
1381                        {
1382 david        1.100 
1383 h.sterling   1.153     //l10n
1384                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1385                                //"Error: $0", e.getMessage()); 
1386                        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1387                                "src.Server.cimserver.ERROR",
1388                                "Error: $0", e.getMessage());  
1389 konrad.r     1.95  
1390                    #ifndef PEGASUS_OS_OS400
1391 h.sterling   1.153     //l10n
1392                        //PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1393                        MessageLoaderParms parms("src.Server.cimserver.ERROR",
1394                                                 "Error: $0", e.getMessage());
1395                        PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1396 david        1.100 
1397 david        1.85  #endif
1398 kumpf        1.77  
1399 h.sterling   1.153     //
1400 kumpf        1.77          // notify parent process (if there is a parent process) to terminate
1401                            //
1402                            if (daemonOption)
1403 h.sterling   1.153                 _cimServerProcess->notify_parent(1);
1404 kumpf        1.77  
1405 h.sterling   1.156         deleteCIMServer();
1406 kumpf        1.54          return 1;
1407 mike         1.32      }
1408                    
1409 h.sterling   1.156     deleteCIMServer();
1410 mike         1.32      return 0;
1411                    }
1412 tony         1.128 
1413                    
1414                    
1415                    

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2