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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2