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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2