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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2