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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2