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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2