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

   1 karl  1.4 //%2003////////////////////////////////////////////////////////////////////////
   2 kumpf 1.1 //
   3 karl  1.4 // 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           // IBM Corp.; EMC Corporation, The Open Group.
   7 kumpf 1.1 //
   8           // Permission is hereby granted, free of charge, to any person obtaining a copy
   9           // of this software and associated documentation files (the "Software"), to
  10           // deal in the Software without restriction, including without limitation the
  11           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  12           // sell copies of the Software, and to permit persons to whom the Software is
  13           // furnished to do so, subject to the following conditions:
  14           // 
  15           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  16           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  17           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  18           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  19           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  20           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  21           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23           //
  24           //==============================================================================
  25           //
  26           // Author: Mike Brasher (mbrasher@bmc.com)
  27           //
  28 kumpf 1.1 // Modified By: Mike Day (mdday@us.ibm.com) 
  29           //
  30           // Modified By:	Karl Schopmeyer (k.schopmeyer@opengroup.org)
  31           //
  32           // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
  33           //
  34           // Modified By: Jenny Yu (jenny_yu@hp.com)
  35           //
  36           // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
  37 kumpf 1.2 //              Carol Ann Krug Graves, Hewlett-Packard Company
  38           //                (carolann_graves@hp.com)
  39           //		Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
  40 kumpf 1.1 //
  41 kumpf 1.3 // Modified By: Dave Rosckes (rosckes@us.ibm.com)
  42           //
  43           // Modified By: Humberto Rivero (hurivero@us.ibm.com)
  44           //
  45           // Modified By: Jair Santos, Hewlett-Packard Company (jair.santos@hp.com)
  46           //
  47 dj.gorey 1.7 // Modified By: Dan Gorey (djgorey@us.ibm.com)
  48 kumpf    1.1 //%/////////////////////////////////////////////////////////////////////////////
  49              
  50              
  51              //////////////////////////////////////////////////////////////////////
  52              //
  53              // Notes on deamon operation (Unix) and service operation (Win 32):
  54              //
  55              // To run pegasus as a daemon on Unix platforms: 
  56              //
  57              // cimserver
  58              //
  59              // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
  60              // property to false:
  61              //
  62              // cimserver daemon=false
  63              //
  64              // The daemon config property has no effect on windows operation. 
  65              //
  66              // To shutdown pegasus, use the -s option:
  67              // 
  68              // cimserver -s 
  69 kumpf    1.1 //
  70              // To run pegasus as an NT service, there are FOUR  different possibilities:
  71              //
  72              // To INSTALL the Pegasus service, 
  73              //
  74              // cimserver -install
  75              //
  76              // To REMOVE the Pegasus service, 
  77              //
  78              // cimserver -remove
  79              //
  80              // To START the Pegasus service, 
  81              //
  82              // net start cimserver
  83              //
  84              // To STOP the Pegasus service, 
  85              //
  86              // net stop cimserver
  87              //
  88              // Alternatively, you can use the windows service manager. Pegasus shows up 
  89              // in the service database as "Pegasus CIM Object Manager"
  90 kumpf    1.1 //
  91              // Mike Day, mdday@us.ibm.com
  92              // 
  93              //////////////////////////////////////////////////////////////////////
  94              
  95              
  96              #include <Pegasus/Common/Config.h>
  97              #include <Pegasus/Common/Constants.h>
  98              #include <iostream>
  99              #include <cassert>
 100              #include <cstdlib>
 101              #include <fstream>
 102              #include <Pegasus/Common/FileSystem.h>
 103              #include <Pegasus/Common/Monitor.h>
 104              #include <WMIMapper/PegServer/CIMServer.h>
 105              #include <Pegasus/Common/PegasusVersion.h>
 106              #include <Pegasus/Common/Logger.h>
 107              #include <Pegasus/Common/System.h>
 108              #include <Pegasus/Common/Tracer.h>
 109              #include <Pegasus/Config/ConfigManager.h>
 110              #include <Pegasus/Client/CIMClient.h>
 111 kumpf    1.1 #include <Pegasus/Server/ShutdownService.h>
 112              
 113 kumpf    1.3 
 114 kumpf    1.1 #if defined(PEGASUS_OS_TYPE_WINDOWS)
 115              # include "cimserver_windows.cpp"
 116              #elif defined(PEGASUS_OS_TYPE_UNIX)
 117              # if defined(PEGASUS_OS_OS400)
 118              #  include "cimserver_os400.cpp"
 119              # else
 120              #  include "cimserver_unix.cpp"
 121              #endif
 122              #else
 123              # error "Unsupported platform"
 124              #endif
 125              
 126              PEGASUS_USING_PEGASUS;
 127              PEGASUS_USING_STD;
 128              
 129              //
 130              //  The command name.
 131              //
 132              static const char COMMAND_NAME []    = "cimserver";
 133              
 134              //
 135 kumpf    1.1 //  The constant defining usage string.
 136              //
 137              static const char USAGE []           = "Usage: ";
 138              
 139              /**
 140              Constants representing the command line options.
 141              */
 142              static const char OPTION_VERSION     = 'v';
 143              
 144              static const char OPTION_HELP        = 'h';
 145              
 146              static const char OPTION_HOME        = 'D';
 147              
 148              static const char OPTION_SHUTDOWN    = 's';
 149              
 150 kumpf    1.3 static const char OPTION_INSTALL[]   = "install";
 151              
 152              static const char OPTION_REMOVE[]   = "remove";
 153              
 154              static const char OPTION_START[]   = "start";
 155              
 156              static const char OPTION_STOP[]   = "stop";
 157              
 158 kumpf    1.1 #if defined(PEGASUS_OS_HPUX)
 159              static const char OPTION_BINDVERBOSE = 'X';
 160              #endif
 161              
 162              static const String PROPERTY_TIMEOUT = "shutdownTimeout";
 163              
 164              ConfigManager*    configManager;
 165              
 166              /** GetOptions function - This function defines the Options Table
 167                  and sets up the options from that table using the config manager.
 168              */
 169              void GetOptions(
 170                  ConfigManager* cm,
 171                  int& argc,
 172                  char** argv,
 173                  const String& pegasusHome)
 174              {
 175                  try
 176                  {
 177                      cm->mergeConfigFiles();
 178              
 179 kumpf    1.1         cm->mergeCommandLine(argc, argv);
 180                  }
 181 kumpf    1.5     catch (NoSuchFile&)
 182 kumpf    1.1     {
 183 kumpf    1.5         throw;
 184 kumpf    1.1     }
 185 kumpf    1.5     catch (FileNotReadable&)
 186 kumpf    1.1     {
 187 kumpf    1.5         throw;
 188 kumpf    1.1     }
 189 kumpf    1.5     catch (CannotRenameFile&)
 190 kumpf    1.1     {
 191 kumpf    1.5         throw;
 192 kumpf    1.1     }
 193 kumpf    1.5     catch (ConfigFileSyntaxError&)
 194 kumpf    1.1     {
 195 kumpf    1.5         throw;
 196 kumpf    1.1     }
 197 kumpf    1.5     catch(UnrecognizedConfigProperty&)
 198 kumpf    1.1     {
 199 kumpf    1.5         throw;
 200 kumpf    1.1     }
 201 kumpf    1.5     catch(InvalidPropertyValue&)
 202 kumpf    1.1     {
 203 kumpf    1.5         throw;
 204 kumpf    1.1     }
 205              }
 206              
 207              /* PrintHelp - This is temporary until we expand the options manager to allow
 208                 options help to be defined with the OptionRow entries and presented from
 209                 those entries.
 210              */
 211              void PrintHelp(const char* arg0)
 212              {
 213                  /**
 214                      Build the usage string for the config command.
 215                  */
 216                  String usage = String (USAGE);
 217                  usage.append (COMMAND_NAME);
 218                  usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
 219                  usage.append ("  options\n");
 220 kumpf    1.3     usage.append ("    -v              - displays CIM Server version number\n");
 221                  usage.append ("    -h              - prints this help message\n");
 222                  usage.append ("    -s              - shuts down CIM Server\n");
 223 kumpf    1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 224 kumpf    1.3     usage.append ("    -D [home]       - sets pegasus home directory\n");
 225 kumpf    1.1 #endif
 226              #if defined(PEGASUS_OS_TYPE_WINDOWS)
 227 kumpf    1.3     usage.append ("    -install [name] - installs pegasus as a Windows NT Service\n");
 228                  usage.append ("                      [name] is optional and overrides the\n");
 229                  usage.append ("                      default CIM Server Service Name\n");
 230                  usage.append ("    -remove [name]  - removes pegasus as a Windows NT Service\n");
 231                  usage.append ("                      [name] is optional and overrides the\n");
 232                  usage.append ("                      default CIM Server Service Name\n");
 233                  usage.append ("    -start [name]   - starts pegasus as a Windows NT Service\n");
 234                  usage.append ("                      [name] is optional and overrides the\n");
 235                  usage.append ("                      default CIM Server Service Name\n");
 236                  usage.append ("    -stop [name]    - stops pegasus as a Windows NT Service\n");
 237                  usage.append ("                      [name] is optional and overrides the\n");
 238                  usage.append ("                      default CIM Server Service Name\n\n");
 239 kumpf    1.1 #endif
 240                  usage.append ("  configProperty=value\n");
 241 kumpf    1.3     usage.append ("                    - sets CIM Server configuration property\n");
 242 kumpf    1.1 
 243                  cout << endl;
 244 kumpf    1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 245 kumpf    1.1     cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
 246              #else
 247                  cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
 248              #endif
 249                  cout << endl;
 250                  cout << usage << endl;
 251              }
 252              
 253 kumpf    1.3 //
 254              // cimserver_exit: platform specific exit routine calls
 255              //         
 256              void cimserver_exit( int rc ){
 257              #ifdef PEGASUS_OS_OS400
 258                  cimserver_exitRC(rc);
 259              #endif
 260                  exit(rc);
 261              }
 262              
 263 kumpf    1.1 void shutdownCIMOM(Uint32 timeoutValue)
 264              {
 265                  //
 266                  // Create CIMClient object
 267                  //
 268                  CIMClient client;
 269              
 270                  //
 271                  // Get local host name
 272                  //
 273                  String hostStr = System::getHostName();
 274              
 275                  //
 276                  // open connection to CIMOM 
 277                  //
 278                  try
 279                  {
 280                      client.connectLocal();
 281              
 282                      //
 283                      // set client timeout to 2 seconds
 284 kumpf    1.1         //
 285                      client.setTimeout(2000);
 286                  }
 287                  catch(Exception& e)
 288                  {
 289 kumpf    1.3 #ifdef PEGASUS_OS_OS400
 290              	Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 291              		    "Unable to connect to CIM Server.  CIM Server may not be running." );
 292              	// The server job may still be active but not responding.
 293              	// Kill the job if it exists.
 294              	if(cimserver_kill() == -1)
 295              	   cimserver_exit(2);
 296              	cimserver_exit(1);
 297              #else
 298 kumpf    1.1         PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
 299                      PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
 300              #endif
 301 kumpf    1.3         cimserver_exit(1);
 302 kumpf    1.1     }
 303              
 304                  try
 305                  {
 306                      //
 307                      // construct CIMObjectPath
 308                      //
 309                      String referenceStr = "//";
 310                      referenceStr.append(hostStr);
 311 kumpf    1.2         referenceStr.append("/");  
 312                      referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
 313 kumpf    1.1         referenceStr.append(":");
 314 kumpf    1.2         referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
 315 kumpf    1.1         CIMObjectPath reference(referenceStr);
 316              
 317                      //
 318                      // issue the invokeMethod request on the shutdown method
 319                      //
 320                      Array<CIMParamValue> inParams;
 321                      Array<CIMParamValue> outParams;
 322              
 323                      // set force option to true for now
 324                      inParams.append(CIMParamValue("force",
 325                          CIMValue(Boolean(true))));
 326              
 327                      inParams.append(CIMParamValue("timeout",
 328                          CIMValue(Uint32(timeoutValue))));
 329              
 330                      CIMValue retValue = client.invokeMethod(
 331                          PEGASUS_NAMESPACENAME_SHUTDOWN,
 332                          reference,
 333                          "shutdown",
 334                          inParams,
 335                          outParams);
 336 kumpf    1.1     }
 337                  catch(CIMException& e)
 338                  {
 339 kumpf    1.3 #ifdef PEGASUS_OS_OS400
 340              
 341              	if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 342              	{
 343              	    Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 344              		    "Failed to shutdown server: $0", "The repository may be empty.");
 345              	}
 346              	else
 347              	{
 348              	    Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 349              			"Failed to shutdown server: $0", e.getMessage());
 350              	}
 351              	// Kill the server job.
 352              	if(cimserver_kill() == -1)
 353              	   cimserver_exit(2);
 354              #else
 355 kumpf    1.1         PEGASUS_STD(cerr) << "Failed to shutdown server: ";
 356                      if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 357                      {
 358                          PEGASUS_STD(cerr) << "The repository may be empty.";
 359                          PEGASUS_STD(cerr) << PEGASUS_STD(endl);
 360                      }
 361                      else
 362                      {
 363                          PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
 364                      }
 365              #endif
 366 kumpf    1.3         cimserver_exit(1);
 367              
 368 kumpf    1.1     }
 369                  catch(Exception& e)
 370                  {
 371                      //
 372 kumpf    1.3         // This may mean that the CIM Server has terminated, causing this
 373                      // client to get a "Empty HTTP response message" exception.  It may
 374                      // also mean that the CIM Server is taking longer than 2 seconds 
 375                      // (client timeout value) to terminate, causing this client to 
 376                      // timeout with a "connection timeout" exception.
 377 kumpf    1.1         //
 378 kumpf    1.3         // Check to see if CIM Server is still running.  If CIM Server
 379 kumpf    1.1         // is still running and the shutdown timeout has not expired,
 380 kumpf    1.3         // loop and wait one second until either the CIM Server is
 381                      // terminated or timeout expires.  If timeout expires and
 382                      // the CIM Server is still running, kill the CIMServer process.
 383                      // 
 384 kumpf    1.1         Uint32 maxWaitTime = timeoutValue - 2;
 385                      Boolean running = isCIMServerRunning();
 386                      while ( running && maxWaitTime > 0 )
 387                      {
 388                          System::sleep(1);
 389                          running = isCIMServerRunning();
 390                          maxWaitTime = maxWaitTime - 1;
 391                      }
 392              
 393                      if (running)
 394                      {
 395 kumpf    1.3             int kill_rc = cimserver_kill();
 396              #ifdef PEGASUS_OS_OS400
 397              	    if(kill_rc == -1)
 398              		cimserver_exit(2);
 399              	    cimserver_exit(1);
 400              #endif
 401              
 402              #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 403              	    if (kill_rc != -1)
 404                          {
 405                              cout << "Shutdown timeout expired.  CIM Server process killed." << endl;
 406                              exit(0);
 407                          }
 408              #endif
 409 kumpf    1.1         }
 410                  }
 411              
 412                  return;
 413              }
 414              
 415              
 416              /////////////////////////////////////////////////////////////////////////
 417              //  MAIN
 418              //////////////////////////////////////////////////////////////////////////
 419              int main(int argc, char** argv)
 420              {
 421                  String pegasusHome  = String::EMPTY;
 422                  String logsDirectory = String::EMPTY;
 423                  Boolean useSLP = false;
 424                  Boolean daemonOption = false;
 425                  Boolean shutdownOption = false;
 426                  Uint32 timeoutValue  = 0;
 427              
 428              #ifdef PEGASUS_OS_OS400
 429                  // Initialize Pegasus home to the shipped OS/400 directory.
 430 kumpf    1.1     pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
 431              #endif
 432              
 433 kumpf    1.3 #ifndef PEGASUS_OS_TYPE_WINDOWS
 434 kumpf    1.1     //
 435                  // Get environment variables:
 436                  //
 437                  const char* tmp = getenv("PEGASUS_HOME");
 438              
 439                  if (tmp)
 440                  {
 441                      pegasusHome = tmp;
 442                  }
 443              
 444                  FileSystem::translateSlashes(pegasusHome);
 445 kumpf    1.3 #else
 446 kumpf    1.1 
 447 kumpf    1.3   // windows only
 448                setHome(pegasusHome);
 449              #endif
 450 kumpf    1.1     // on Windows NT if there are no command-line options, run as a service
 451              
 452                  if (argc == 1 )
 453                  {
 454 kumpf    1.3       cim_server_service(argc, argv);
 455 kumpf    1.1     }
 456                  else
 457                  {
 458                      // Get help, version, and shutdown options
 459 kumpf    1.3 
 460 kumpf    1.1         for (int i = 1; i < argc; )
 461                      {
 462                          const char* arg = argv[i];
 463              
 464                          // Check for -option
 465                          if (*arg == '-')
 466                          {
 467                              // Get the option
 468                              const char* option = arg + 1;
 469              
 470                              //
 471                              // Check to see if user asked for the version (-v option):
 472                              //
 473 kumpf    1.3                 if (*option == OPTION_VERSION &&
 474                                  strlen(option) == 1)
 475 kumpf    1.1                 {
 476 kumpf    1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 477 kumpf    1.1                     cout << PLATFORM_PRODUCT_VERSION << endl;
 478              #else
 479                                  cout << PEGASUS_VERSION << endl;
 480              #endif
 481                                  exit(0);
 482                              }
 483                              //
 484                              // Check to see if user asked for help (-h option):
 485                              //
 486 kumpf    1.3                 else if (*option == OPTION_HELP &&
 487                                      (strlen(option) == 1))
 488 kumpf    1.1                 {
 489                                  PrintHelp(argv[0]);
 490                                  exit(0);
 491                              }
 492 kumpf    1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 493 kumpf    1.3                 else if (*option == OPTION_HOME &&
 494                                      (strlen(option) == 1))
 495 kumpf    1.1                 {
 496                                  if (i + 1 < argc)
 497                                  {
 498                                      pegasusHome.assign(argv[i + 1]);
 499                                  }
 500                                  else
 501                                  {
 502                                      cout << "Missing argument for option -" << option << endl;
 503                                      exit(0);
 504                                  }
 505              
 506                                  memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 507                                  argc -= 2;
 508                              }
 509              #endif
 510              #if defined(PEGASUS_OS_HPUX)
 511                              //
 512                              // Check to see if user asked for the version (-X option):
 513                              //
 514 kumpf    1.3                 if (*option == OPTION_BINDVERBOSE &&
 515                                      (strlen(option) == 1))
 516 kumpf    1.1                 {
 517 kumpf    1.3 		    System::bindVerbose = true;
 518 kumpf    1.1                     cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
 519                                       << endl;
 520                                  // remove the option from the command line
 521                                  memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 522                                  argc--;   
 523                              }
 524              #endif
 525                              //
 526                              // Check to see if user asked for shutdown (-s option):
 527                              //
 528 kumpf    1.3                 else if (*option == OPTION_SHUTDOWN &&
 529                                      (strlen(option) == 1))
 530 kumpf    1.1                 {
 531                                  //
 532                                  // check to see if user is root
 533                                  //
 534 kumpf    1.2 #ifndef PEGASUS_OS_OS400
 535 kumpf    1.1                     if (!System::isPrivilegedUser(System::getEffectiveUserName()))
 536                                  {
 537                                      cout << "You must have superuser privilege to run ";
 538                                      cout << "cimserver." << endl;
 539                                      exit(0);
 540                                  }
 541 kumpf    1.2 #endif
 542 kumpf    1.1 
 543                                  //
 544                                  // Check to see if shutdown has already been specified:
 545                                  //
 546                                  if (shutdownOption)
 547                                  {
 548                                      cout << "Duplicate shutdown option specified." << endl;
 549                                      exit(0);
 550                                  }
 551              
 552                                  shutdownOption = true;
 553               
 554                                  // remove the option from the command line
 555                                  memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 556                                  argc--;   
 557                              }
 558 kumpf    1.3 #ifdef PEGASUS_OS_TYPE_WINDOWS
 559                              else if (strcmp(option, OPTION_INSTALL) == 0)
 560                              {
 561                                //
 562                                // Install as a NT service
 563                                //
 564                                char *opt_arg = NULL;
 565                                if (i+1 < argc)
 566                                {
 567                                  opt_arg = argv[i+1];
 568                                  
 569                                }
 570                                if(cimserver_install_nt_service(opt_arg))
 571                                {
 572                                    cout << "\nPegasus installed as NT Service";
 573                                    exit(0);
 574                                }
 575                                else
 576                                {
 577                                    exit(0);
 578                                }
 579 kumpf    1.3                 }
 580                              else if (strcmp(option, OPTION_REMOVE) == 0)
 581                              {
 582                                //
 583                                // Remove Pegasus as an NT service
 584                                //
 585                                char *opt_arg = NULL;
 586                                if (i+1 < argc)
 587                                {
 588                                  opt_arg = argv[i+1];                    
 589                                }
 590                                if(cimserver_remove_nt_service(opt_arg))
 591                                {
 592                                    cout << "\nPegasus removed as NT Service";
 593                                    exit(0);
 594                                }
 595                                else
 596                                {
 597                                    exit(0);
 598                                }
 599              
 600 kumpf    1.3                 }
 601                              else if (strcmp(option, OPTION_START) == 0)
 602                              {
 603                                //
 604                                // Start as a NT service
 605                                //
 606                                char *opt_arg = NULL;
 607                                if (i+1 < argc)
 608                                {
 609                                  opt_arg = argv[i+1];                    
 610                                }
 611                                if(cimserver_start_nt_service(opt_arg))
 612                                {
 613                                    cout << "\nPegasus started as NT Service";
 614                                    exit(0);
 615                                }
 616                                else
 617                                {
 618                                    exit(0);
 619                                }
 620                              }
 621 kumpf    1.3                 else if (strcmp(option, OPTION_STOP) == 0)
 622                              {
 623                                //
 624                                // Stop as a NT service
 625                                //
 626                                char *opt_arg = NULL;
 627                                if (i+1 < argc)
 628                                {
 629                                  opt_arg = argv[i+1];                    
 630                                }
 631                                if(cimserver_stop_nt_service(opt_arg))
 632                                {
 633                                    cout << "\nPegasus stopped as NT Service";
 634                                    exit(0);
 635                                }
 636                                else
 637                                {
 638                                    exit(0);
 639                                }
 640                              }
 641              #endif
 642 kumpf    1.1                 else
 643 kumpf    1.3                     i++;
 644 kumpf    1.1             }
 645                          else
 646 kumpf    1.3                 i++;
 647 kumpf    1.1         }
 648                  }
 649              
 650                  //
 651                  // Set the value for pegasusHome property
 652                  //
 653                  ConfigManager::setPegasusHome(pegasusHome);
 654              
 655                  //
 656                  // Get an instance of the Config Manager.
 657                  //
 658                  configManager = ConfigManager::getInstance();
 659 kumpf    1.10     configManager->useConfigFiles = true;
 660 kumpf    1.1  
 661                   //
 662                   // Get options (from command line and from configuration file); this
 663                   // removes corresponding options and their arguments from the command
 664                   // line.
 665                   //
 666                   try
 667                   {
 668                       GetOptions(configManager, argc, argv, pegasusHome);
 669                   }
 670                   catch (Exception& e)
 671                   {
 672 kumpf    1.3  #ifdef PEGASUS_OS_OS400
 673               	Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 674               			"$0: $1",argv[0] ,e.getMessage());
 675               #else
 676 kumpf    1.1          cerr << argv[0] << ": " << e.getMessage() << endl;
 677 kumpf    1.3  #endif
 678 kumpf    1.1          exit(1);
 679                   }
 680               
 681 kumpf    1.3  // l10n
 682               	// Set the home directory, msg sub-dir, into the MessageLoader.
 683               	// This will be the default directory where the resource bundles 
 684               	// are found.
 685               	String messagesDir = String::EMPTY;
 686               #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM
 687               	messagesDir = OS400_DEFAULT_MESSAGE_SOURCE;
 688               #else
 689               	messagesDir = ConfigManager::getHomedPath("msg");
 690               #endif
 691               	MessageLoader::setPegasusMsgHome(messagesDir);		
 692               
 693 kumpf    1.2      Boolean enableHttpConnection = String::equal(
 694 kumpf    1.3          configManager->getCurrentValue("enableHttpConnection"), "true");
 695                   Boolean enableHttpsConnection = String::equal(
 696                       configManager->getCurrentValue("enableHttpsConnection"), "true");
 697 kumpf    1.9      Boolean enableSSLExportClientVerification  = String::equal(
 698                       configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
 699 kumpf    1.2  
 700                   // Make sure at least one connection is enabled
 701               #ifndef PEGASUS_LOCAL_DOMAIN_SOCKET
 702                   if (!enableHttpConnection && !enableHttpsConnection)
 703                   {
 704 kumpf    1.3          Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 705 kumpf    1.2              "Neither HTTP nor HTTPS connection is enabled.  "
 706                           "CIMServer will not be started.");
 707 kumpf    1.3          cerr << "Neither HTTP nor HTTPS connection is enabled.  "
 708 kumpf    1.2              "CIMServer will not be started." << endl;
 709 kumpf    1.3          exit(1);
 710 kumpf    1.2      }
 711               #endif
 712               
 713 kumpf    1.1      try
 714                   {
 715                       //
 716                       // Check to see if we should Pegasus as a daemon
 717                       //
 718               
 719                       if (String::equal(configManager->getCurrentValue("daemon"), "true"))
 720                       {
 721                           daemonOption = true;
 722                       }
 723               	
 724                       // Get the log file directory definition.
 725                       // We put String into Cstring because
 726                       // Directory functions only handle Cstring.
 727                       // ATTN-KS: create String based directory functions.
 728               
 729                       logsDirectory = configManager->getCurrentValue("logdir");
 730 kumpf    1.3          logsDirectory = 
 731               	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
 732 kumpf    1.1  
 733                       // Set up the Logger. This does not open the logs
 734                       // Might be more logical to clean before set.
 735                       // ATTN: Need tool to completely disable logging.
 736               
 737 kumpf    1.3  #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 738               !defined(PEGASUS_OS_OS400)
 739 kumpf    1.1          Logger::setHomeDirectory(logsDirectory);
 740               #endif
 741               
 742                       //
 743                       // Check to see if we need to shutdown CIMOM 
 744                       //
 745                       if (shutdownOption)
 746                       {
 747                           String configTimeout = 
 748                               configManager->getCurrentValue("shutdownTimeout");
 749                           timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
 750                           
 751                           shutdownCIMOM(timeoutValue);
 752               
 753 kumpf    1.3  #ifdef PEGASUS_OS_OS400
 754               	    Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 755               			"CIM Server stopped.");  
 756               #else
 757 kumpf    1.1              cout << "CIM Server stopped." << endl;
 758 kumpf    1.2  #endif
 759 kumpf    1.3              cimserver_exit(0);
 760 kumpf    1.1          }
 761               
 762                       // Leave this in until people get familiar with the logs.
 763 kumpf    1.3  #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 764               !defined(PEGASUS_OS_OS400)
 765 kumpf    1.1          cout << "Logs Directory = " << logsDirectory << endl;
 766               #endif
 767               
 768                       if (String::equal(configManager->getCurrentValue("slp"), "true"))
 769                       {
 770                           useSLP =  true;
 771                       }
 772                   }
 773 kumpf    1.5      catch (UnrecognizedConfigProperty& e)
 774 kumpf    1.1      {
 775 kumpf    1.3  
 776               #ifdef PEGASUS_OS_OS400
 777               	Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 778               		    "Error: $0",e.getMessage());  
 779               #else
 780               	cout << "Error: " << e.getMessage() << endl;
 781               #endif
 782 kumpf    1.1      }
 783               
 784 kumpf    1.2      Uint32 portNumberHttps;
 785                   Uint32 portNumberHttp;
 786 kumpf    1.9      Uint32 portNumberExportHttps;
 787 kumpf    1.1  
 788 kumpf    1.2      if (enableHttpsConnection)
 789 kumpf    1.1      {
 790 kumpf    1.2          String httpsPort = configManager->getCurrentValue("httpsPort");
 791 kumpf    1.1          CString portString = httpsPort.getCString();
 792 kumpf    1.3          char* end = 0;
 793                       Uint32 port = strtol(portString, &end, 10);
 794                       assert(end != 0 && *end == '\0');
 795 kumpf    1.1  
 796                       //
 797 kumpf    1.3          // Look up the WBEM-HTTPS port number
 798 kumpf    1.1          //
 799 kumpf    1.2          portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
 800 kumpf    1.1      }
 801 kumpf    1.2  
 802                   if (enableHttpConnection)
 803 kumpf    1.1      {
 804 kumpf    1.2          String httpPort = configManager->getCurrentValue("httpPort");
 805 kumpf    1.1          CString portString = httpPort.getCString();
 806 kumpf    1.3          char* end = 0;
 807                       Uint32 port = strtol(portString, &end, 10);
 808                       assert(end != 0 && *end == '\0');
 809 kumpf    1.1  
 810                       //
 811 kumpf    1.3          // Look up the WBEM-HTTP port number
 812 kumpf    1.1          //
 813 kumpf    1.2          portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
 814 kumpf    1.1      }
 815               
 816 kumpf    1.9      if (enableSSLExportClientVerification) 
 817                   { 
 818                      // 
 819                      // No config property is looked up to get the default port number. 
 820                      // Lookup the port defined in /etc/services for the service name 
 821                      // wbem-exp-https and bind to that port. If the service is  not defined 
 822                      // then log a warning message and do not start the cimserver. 
 823                      // 
 824                      Uint32 port = 0; 
 825               
 826                      portNumberExportHttps = System::lookupPort(WBEM_EXPORT_HTTPS_SERVICE_NAME, port); 
 827               
 828                      if (portNumberExportHttps == 0) 
 829                      { 
 830                          Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING, 
 831                              "src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED", 
 832                              "Port not defined for the service wbem-exp-https. CIMServer will not be started."); 
 833               
 834                          MessageLoaderParms parms("src.Server.cimserver.EXPORT_HTTPS_PORT_NOT_DEFINED", 
 835                              "Port not defined for the service wbem-exp-https. CIMServer will not be started."); 
 836               
 837 kumpf    1.9             cerr << MessageLoader::getMessage(parms) << endl; 
 838               
 839                          return(1); 
 840                      } 
 841                   } 
 842               
 843 kumpf    1.1      // Put out startup up message.
 844 kumpf    1.3  #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 845               !defined(PEGASUS_OS_OS400)
 846 kumpf    1.2      cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
 847 kumpf    1.1      cout << "Built " << __DATE__ << " " << __TIME__ << endl;
 848 kumpf    1.3      cout <<"Starting..."
 849               	 << (useSLP ? " SLP reg. " : " No SLP ")
 850               	<< endl;
 851 kumpf    1.1  #endif
 852 kumpf    1.3  
 853 kumpf    1.1      // do we need to run as a daemon ?
 854                   if (daemonOption)
 855                   {
 856                       if(-1 == cimserver_fork())
 857 kumpf    1.2  #ifndef PEGASUS_OS_OS400
 858 kumpf    1.3  	{	
 859               	    exit(-1);
 860               	}
 861 kumpf    1.2  #else
 862 kumpf    1.3  	{
 863                           return(-1);
 864               	}
 865 kumpf    1.2  	else
 866 kumpf    1.3  	{
 867               	    return(0);
 868               	}
 869 kumpf    1.2  #endif
 870 kumpf    1.3  	
 871 kumpf    1.1      }
 872               
 873               #ifdef PEGASUS_OS_OS400
 874                   // Special server initialization code for OS/400.
 875                   if (cimserver_initialize() != 0)
 876                   {
 877 kumpf    1.3  	// do some logging here!
 878               	Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 879               		    "CIM Server failed to initialize");  
 880               	exit(-1);
 881 kumpf    1.1      } 
 882               #endif
 883               
 884 kumpf    1.3  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 885 kumpf    1.1      umask(S_IWGRP|S_IWOTH);
 886 kumpf    1.2  
 887                   //
 888                   // check if CIMServer is already running
 889                   // if CIMServer is already running, print message and 
 890                   // notify parent process (if there is a parent process) to terminate
 891                   //
 892                   if(isCIMServerRunning())
 893                   {
 894               	cout << "Unable to start CIMServer." << endl;
 895               	cout << "CIMServer is already running." << endl;
 896               
 897               	//
 898                       // notify parent process (if there is a parent process) to terminate
 899                       //
 900                       if (daemonOption)
 901 kumpf    1.3                  notify_parent(1);
 902 kumpf    1.2  
 903                       exit(1);
 904                   }
 905                    
 906 kumpf    1.1  #endif
 907               
 908                   // try loop to bind the address, and run the server
 909                   try
 910                   {
 911 dj.gorey 1.8  	#ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
 912 kumpf    1.3  	Monitor monitor(true);
 913 dj.gorey 1.7  	#else
 914               	monitor_2 monitor();
 915               	#endif
 916 kumpf    1.3  	CIMServer server(&monitor);
 917 kumpf    1.2  
 918                       if (enableHttpConnection)
 919                       {
 920 kumpf    1.9              server.addAcceptor(false, portNumberHttp, false, false);
 921 kumpf    1.3              Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
 922 kumpf    1.2                          "Listening on HTTP port $0.", portNumberHttp);
 923                       }
 924                       if (enableHttpsConnection)
 925                       {
 926 kumpf    1.9              server.addAcceptor(false, portNumberHttps, true, false);
 927 kumpf    1.3              Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
 928 kumpf    1.2                          "Listening on HTTPS port $0.", portNumberHttps);
 929                       }
 930 kumpf    1.9          if (enableSSLExportClientVerification) 
 931                       { 
 932                           server.addAcceptor(false, portNumberExportHttps, true, true); 
 933               
 934                           Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, 
 935                               "src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT", 
 936                               "Listening on Export HTTPS port $0.", portNumberExportHttps); 
 937                       } 
 938               
 939 kumpf    1.2  #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
 940 kumpf    1.9          server.addAcceptor(true, 0, false, false);
 941 kumpf    1.3          Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
 942 kumpf    1.2                      "Listening on local connection socket.");
 943 kumpf    1.1  #endif
 944               
 945 kumpf    1.3  #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && !defined(PEGASUS_OS_OS400)
 946 kumpf    1.2          if (enableHttpConnection)
 947                       {
 948                           cout << "Listening on HTTP port " << portNumberHttp << endl;
 949                       }
 950                       if (enableHttpsConnection)
 951                       {
 952                           cout << "Listening on HTTPS port " << portNumberHttps << endl;
 953                       }
 954 kumpf    1.9          if (enableSSLExportClientVerification) 
 955                       { 
 956                           MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT", 
 957                               "Listening on Export HTTPS port $0.", portNumberExportHttps); 
 958                   
 959                           cout << MessageLoader::getMessage(parms) << endl; 
 960                       } 
 961                 
 962               
 963 kumpf    1.3  # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
 964 kumpf    1.2          cout << "Listening on local connection socket" << endl;
 965 kumpf    1.3  # endif
 966 kumpf    1.1  #endif
 967               
 968 kumpf    1.3          // bind throws an exception if the bind fails
 969                       server.bind();
 970 kumpf    1.1  
 971 kumpf    1.3  	// notify parent process (if there is a parent process) to terminate 
 972                       // so user knows that there is cimserver ready to serve CIM requests.
 973               	if (daemonOption)
 974               		notify_parent(0);
 975 kumpf    1.2  
 976 kumpf    1.3  	time_t last = 0;
 977 kumpf    1.1  
 978 kumpf    1.3  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 979 kumpf    1.1          //
 980                       // create a file to indicate that the cimserver has started and
 981                       // save the process id of the cimserver process in the file
 982                       //
 983                       // remove the old file if it exists
 984 kumpf    1.3          System::removeFile(CIMSERVER_START_FILE);
 985 kumpf    1.1  
 986                       // open the file
 987 kumpf    1.3          FILE *pid_file = fopen(CIMSERVER_START_FILE, "w");
 988               
 989 kumpf    1.1          if (pid_file)
 990                       {
 991                           // save the pid in the file
 992                           fprintf(pid_file, "%ld\n", (long)server_pid);
 993                           fclose(pid_file);
 994                       }
 995               #endif
 996 kumpf    1.3  
 997               #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 998               !defined(PEGASUS_OS_OS400)
 999               	cout << "Started. " << endl;
1000 kumpf    1.1  #endif
1001               
1002                       // Put server started message to the logger
1003 kumpf    1.2  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
1004 kumpf    1.3          Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1005 kumpf    1.2                      "Started $0 version $1.",
1006                                   PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
1007 kumpf    1.1  #else
1008 kumpf    1.3          Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1009 kumpf    1.2                      "Started $0 version $1.",
1010                                   PEGASUS_NAME, PEGASUS_VERSION);
1011 kumpf    1.1  #endif
1012               
1013 kumpf    1.3  	
1014                       //
1015 kumpf    1.1          // Loop to call CIMServer's runForever() method until CIMServer
1016                       // has been shutdown
1017                       //
1018 kumpf    1.3  	while( !server.terminated() )
1019               	{
1020               	  server.runForever();
1021               	}
1022 kumpf    1.1  
1023                       //
1024                       // normal termination
1025 kumpf    1.3  	//
1026 kumpf    1.1          // Put server shutdown message to the logger
1027 kumpf    1.2  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
1028 kumpf    1.3          Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1029 kumpf    1.2              "$0 stopped.", PLATFORM_PRODUCT_NAME);
1030               #else
1031 kumpf    1.3          Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1032 kumpf    1.1              "$0 stopped.", PEGASUS_NAME);
1033 kumpf    1.2  #endif
1034 kumpf    1.1  
1035 kumpf    1.3  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1036 kumpf    1.1          //
1037                       // close the file created at startup time to indicate that the 
1038                       // cimserver has terminated normally.
1039                       //
1040 kumpf    1.3          FileSystem::removeFile(CIMSERVER_START_FILE);
1041 kumpf    1.1  #endif
1042                   }
1043                   catch(Exception& e)
1044                   {
1045 kumpf    1.3  	Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1046               		    "Error: $0", e.getMessage()); 
1047 kumpf    1.2  
1048 kumpf    1.3  #ifndef PEGASUS_OS_OS400
1049               	PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1050               #endif
1051               
1052               	//
1053                       // notify parent process (if there is a parent process) to terminate
1054 kumpf    1.2          //
1055                       if (daemonOption)
1056 kumpf    1.3                  notify_parent(1);
1057 kumpf    1.2  
1058 kumpf    1.1          return 1;
1059                   }
1060               
1061                   return 0;
1062               }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2