(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 humberto 1.90         cimserver_exit(0);
 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 mday     1.93.6.1 // l10n
 680                   	// Set the home directory, msg sub-dir, into the MessageLoader.
 681                   	// This will be the default directory where the resource bundles 
 682                   	// are found.
 683                   	String messagesDir = String::EMPTY;
 684                   #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM
 685                   	messagesDir = OS400_DEFAULT_MESSAGE_SOURCE;
 686                   #else
 687                   	messagesDir = ConfigManager::getHomedPath("msg");
 688                   #endif
 689                   	MessageLoader::setPegasusMsgHome(messagesDir);		
 690                   
 691 kumpf    1.87         Boolean enableHttpConnection = String::equal(
 692                           configManager->getCurrentValue("enableHttpConnection"), "true");
 693                       Boolean enableHttpsConnection = String::equal(
 694                           configManager->getCurrentValue("enableHttpsConnection"), "true");
 695 kumpf    1.86     
 696                       // Make sure at least one connection is enabled
 697                   #ifndef PEGASUS_LOCAL_DOMAIN_SOCKET
 698                       if (!enableHttpConnection && !enableHttpsConnection)
 699                       {
 700 david    1.88             Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 701 kumpf    1.86                 "Neither HTTP nor HTTPS connection is enabled.  "
 702                               "CIMServer will not be started.");
 703                           cerr << "Neither HTTP nor HTTPS connection is enabled.  "
 704                               "CIMServer will not be started." << endl;
 705                           exit(1);
 706                       }
 707                   #endif
 708                   
 709 mike     1.35         try
 710 mike     1.32         {
 711 mike     1.35             //
 712                           // Check to see if we should Pegasus as a daemon
 713                           //
 714                   
 715                           if (String::equal(configManager->getCurrentValue("daemon"), "true"))
 716                           {
 717                               daemonOption = true;
 718                           }
 719 mday     1.62     	
 720 kumpf    1.36             // Get the log file directory definition.
 721                           // We put String into Cstring because
 722                           // Directory functions only handle Cstring.
 723                           // ATTN-KS: create String based directory functions.
 724                   
 725                           logsDirectory = configManager->getCurrentValue("logdir");
 726 kumpf    1.38             logsDirectory = 
 727                   	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
 728 kumpf    1.36     
 729                           // Set up the Logger. This does not open the logs
 730                           // Might be more logical to clean before set.
 731                           // ATTN: Need tool to completely disable logging.
 732                   
 733 david    1.85     #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 734                   !defined(PEGASUS_OS_OS400)
 735 kumpf    1.36             Logger::setHomeDirectory(logsDirectory);
 736 kumpf    1.57     #endif
 737 kumpf    1.36     
 738                           //
 739 mike     1.35             // Check to see if we need to shutdown CIMOM 
 740                           //
 741                           if (shutdownOption)
 742                           {
 743 kumpf    1.60                 String configTimeout = 
 744                                   configManager->getCurrentValue("shutdownTimeout");
 745 kumpf    1.69                 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
 746 kumpf    1.60                 
 747 kumpf    1.52                 shutdownCIMOM(timeoutValue);
 748 kumpf    1.45     
 749 david    1.85     #ifdef PEGASUS_OS_OS400
 750 david    1.88     	    Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 751 david    1.85     			"CIM Server stopped.");  
 752                   #else
 753 kumpf    1.60                 cout << "CIM Server stopped." << endl;
 754 diane    1.81     #endif
 755 humberto 1.90                 cimserver_exit(0);
 756 mike     1.35             }
 757 mike     1.32     
 758 kumpf    1.36             // Leave this in until people get familiar with the logs.
 759 david    1.85     #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 760                   !defined(PEGASUS_OS_OS400)
 761 kumpf    1.36             cout << "Logs Directory = " << logsDirectory << endl;
 762 kumpf    1.57     #endif
 763 mike     1.35     
 764                           if (String::equal(configManager->getCurrentValue("slp"), "true"))
 765                           {
 766                               useSLP =  true;
 767                           }
 768 mike     1.32         }
 769 mike     1.35         catch (UnrecognizedConfigProperty e)
 770 mike     1.32         {
 771 david    1.85     
 772                   #ifdef PEGASUS_OS_OS400
 773 david    1.88     	Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 774 david    1.85     		    "Error: $0",e.getMessage());  
 775                   #else
 776                   	cout << "Error: " << e.getMessage() << endl;
 777                   #endif
 778 mike     1.32         }
 779                   
 780 kumpf    1.86         Uint32 portNumberHttps;
 781                       Uint32 portNumberHttp;
 782 kumpf    1.53     
 783 kumpf    1.86         if (enableHttpsConnection)
 784 kumpf    1.53         {
 785 kumpf    1.86             String httpsPort = configManager->getCurrentValue("httpsPort");
 786 kumpf    1.69             CString portString = httpsPort.getCString();
 787 kumpf    1.86             char* end = 0;
 788                           Uint32 port = strtol(portString, &end, 10);
 789                           assert(end != 0 && *end == '\0');
 790 kumpf    1.53     
 791                           //
 792 kumpf    1.86             // Look up the WBEM-HTTPS port number
 793 kumpf    1.53             //
 794 kumpf    1.86             portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
 795 kumpf    1.53         }
 796 kumpf    1.86     
 797                       if (enableHttpConnection)
 798 kumpf    1.53         {
 799 kumpf    1.86             String httpPort = configManager->getCurrentValue("httpPort");
 800 kumpf    1.69             CString portString = httpPort.getCString();
 801 kumpf    1.86             char* end = 0;
 802                           Uint32 port = strtol(portString, &end, 10);
 803                           assert(end != 0 && *end == '\0');
 804 kumpf    1.53     
 805                           //
 806 kumpf    1.86             // Look up the WBEM-HTTP port number
 807 kumpf    1.53             //
 808 kumpf    1.86             portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
 809 kumpf    1.53         }
 810 mike     1.32     
 811                       // Put out startup up message.
 812 david    1.85     #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 813                   !defined(PEGASUS_OS_OS400)
 814 kumpf    1.86         cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
 815 mike     1.32         cout << "Built " << __DATE__ << " " << __TIME__ << endl;
 816 kumpf    1.54         cout <<"Starting..."
 817 mike     1.32     	 << (useSLP ? " SLP reg. " : " No SLP ")
 818                   	<< endl;
 819 kumpf    1.63     #endif
 820 mike     1.32     
 821 kumpf    1.63         // do we need to run as a daemon ?
 822                       if (daemonOption)
 823                       {
 824                           if(-1 == cimserver_fork())
 825 diane    1.81     #ifndef PEGASUS_OS_OS400
 826 david    1.85     	{
 827                   	    exit(-1);
 828                   	}
 829 diane    1.81     #else
 830 david    1.85     	{
 831                               return(-1);
 832                   	}
 833 diane    1.81     	else
 834 david    1.85     	{
 835                   	    return(0);
 836                   	}
 837 diane    1.81     #endif
 838 david    1.85     	
 839 kumpf    1.63         }
 840 chuck    1.66     
 841                   #ifdef PEGASUS_OS_OS400
 842                       // Special server initialization code for OS/400.
 843                       if (cimserver_initialize() != 0)
 844                       {
 845 david    1.85     	// do some logging here!
 846 david    1.88     	Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 847 david    1.85     		    "CIM Server failed to initialize");  
 848                   	exit(-1);
 849 chuck    1.66         } 
 850                   #endif
 851 mday     1.62     
 852 marek    1.92     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 853 kumpf    1.63         umask(S_IWGRP|S_IWOTH);
 854 kumpf    1.79     
 855                       //
 856                       // check if CIMServer is already running
 857                       // if CIMServer is already running, print message and 
 858                       // notify parent process (if there is a parent process) to terminate
 859                       //
 860                       if(isCIMServerRunning())
 861                       {
 862                   	cout << "Unable to start CIMServer." << endl;
 863                   	cout << "CIMServer is already running." << endl;
 864                   
 865                   	//
 866                           // notify parent process (if there is a parent process) to terminate
 867                           //
 868                           if (daemonOption)
 869                                   notify_parent();
 870                   
 871                           exit(1);
 872                       }
 873                        
 874 kumpf    1.63     #endif
 875 kumpf    1.51     
 876 mike     1.32         // try loop to bind the address, and run the server
 877                       try
 878                       {
 879 kumpf    1.75     #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
 880 kumpf    1.86             char slp_address[32];
 881 mike     1.32           	slp_client *discovery = new slp_client() ;;
 882                           String serviceURL;
 883                   	serviceURL.assign("service:cim.pegasus://");
 884                   	String host_name = slp_get_host_name();
 885 kumpf    1.67     	serviceURL.append(host_name);
 886                   	serviceURL.append(":");
 887 kumpf    1.86             // ATTN: Fix this to work for multiple connections
 888                           sprintf(slp_address, "%u",
 889                                   enableHttpConnection ? portNumberHttp : portNumberHttps);
 890                           serviceURL.append(slp_address);
 891 mike     1.35     #endif
 892 mike     1.32     
 893 mday     1.61     	Monitor monitor(true);
 894 kumpf    1.86     	CIMServer server(&monitor);
 895 kumpf    1.41     
 896 kumpf    1.86             if (enableHttpConnection)
 897                           {
 898                               server.addAcceptor(false, portNumberHttp, false);
 899 david    1.88                 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
 900 kumpf    1.86                             "Listening on HTTP port $0.", portNumberHttp);
 901                           }
 902                           if (enableHttpsConnection)
 903                           {
 904                               server.addAcceptor(false, portNumberHttps, true);
 905 david    1.89                 Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
 906 kumpf    1.86                             "Listening on HTTPS port $0.", portNumberHttps);
 907                           }
 908 kumpf    1.41     #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
 909 kumpf    1.86             server.addAcceptor(true, 0, false);
 910 david    1.88             Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
 911 kumpf    1.86                         "Listening on local connection socket.");
 912 kumpf    1.41     #endif
 913 kumpf    1.86     
 914                   #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && !defined(PEGASUS_OS_OS400)
 915                           if (enableHttpConnection)
 916                           {
 917                               cout << "Listening on HTTP port " << portNumberHttp << endl;
 918                           }
 919                           if (enableHttpsConnection)
 920                           {
 921                               cout << "Listening on HTTPS port " << portNumberHttps << endl;
 922                           }
 923                   # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
 924                           cout << "Listening on local connection socket" << endl;
 925                   # endif
 926 david    1.85     #endif
 927 mike     1.35     
 928 kumpf    1.86             // bind throws an exception if the bind fails
 929                           server.bind();
 930 kumpf    1.73     
 931 dan      1.76     	// notify parent process (if there is a parent process) to terminate 
 932                           // so user knows that cimserver is ready to serve CIM requests.
 933                   	if (daemonOption)
 934                   		notify_parent();
 935 mike     1.32     
 936                   	time_t last = 0;
 937 mike     1.35     
 938 marek    1.92     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 939 kumpf    1.45             //
 940 kumpf    1.56             // create a file to indicate that the cimserver has started and
 941                           // save the process id of the cimserver process in the file
 942 kumpf    1.45             //
 943 kumpf    1.56             // remove the old file if it exists
 944 kumpf    1.91             System::removeFile(CIMSERVER_START_FILE);
 945 kumpf    1.56     
 946                           // open the file
 947 kumpf    1.91             FILE *pid_file = fopen(CIMSERVER_START_FILE, "w");
 948                   
 949 kumpf    1.56             if (pid_file)
 950 kumpf    1.45             {
 951 kumpf    1.56                 // save the pid in the file
 952                               fprintf(pid_file, "%ld\n", (long)server_pid);
 953                               fclose(pid_file);
 954 kumpf    1.45             }
 955                   #endif
 956 kumpf    1.91     
 957 david    1.85     #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 958                   !defined(PEGASUS_OS_OS400)
 959 kumpf    1.54     	cout << "Started. " << endl;
 960 kumpf    1.63     #endif
 961 kumpf    1.54     
 962                           // Put server started message to the logger
 963 kumpf    1.80     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 964 david    1.88             Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
 965 kumpf    1.86                         "Started $0 version $1.",
 966                                       PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
 967 kumpf    1.63     #else
 968 david    1.88             Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
 969 kumpf    1.86                         "Started $0 version $1.",
 970                                       PEGASUS_NAME, PEGASUS_VERSION);
 971 kumpf    1.63     #endif
 972 kumpf    1.45     
 973 mday     1.62     	
 974 mike     1.35             //
 975                           // Loop to call CIMServer's runForever() method until CIMServer
 976                           // has been shutdown
 977                           //
 978                   	while( !server.terminated() )
 979 mike     1.32     	{
 980 kumpf    1.75     #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
 981 mike     1.32     	  if(useSLP  ) 
 982                   	  {
 983                   	    if(  (time(NULL) - last ) > 60 ) 
 984                   	    {
 985 kumpf    1.69     	      if( discovery != NULL && serviceURL.size() )
 986                   		discovery->srv_reg_all(serviceURL.getCString(),
 987 mike     1.35     				       "(namespace=root/cimv2)",
 988 mike     1.32     				       "service:cim.pegasus", 
 989                   				       "DEFAULT", 
 990                   				       70) ;
 991                   	      time(&last);
 992                   	    }
 993                   	  
 994                   	    discovery->service_listener();
 995                   	  }
 996 mike     1.35     #endif
 997 mike     1.32     	  server.runForever();
 998                   	}
 999                   
1000 kumpf    1.45             //
1001                           // normal termination
1002 mike     1.34     	//
1003 kumpf    1.54             // Put server shutdown message to the logger
1004 kumpf    1.86     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
1005 david    1.88             Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1006 kumpf    1.86                 "$0 stopped.", PLATFORM_PRODUCT_NAME);
1007                   #else
1008 david    1.88             Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1009 kumpf    1.54                 "$0 stopped.", PEGASUS_NAME);
1010 kumpf    1.86     #endif
1011 kumpf    1.45     
1012 marek    1.92     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1013 kumpf    1.45             //
1014 kumpf    1.56             // close the file created at startup time to indicate that the 
1015                           // cimserver has terminated normally.
1016 kumpf    1.45             //
1017 kumpf    1.91             FileSystem::removeFile(CIMSERVER_START_FILE);
1018 kumpf    1.45     #endif
1019 mike     1.32         }
1020                       catch(Exception& e)
1021                       {
1022 david    1.85     #ifdef PEGASUS_OS_OS400
1023 david    1.88     	Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1024 david    1.85     		    "Error: $0", e.getMessage()); 
1025                   #else
1026 mike     1.32     	PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1027 david    1.85     #endif
1028 kumpf    1.77     
1029                   	//
1030                           // notify parent process (if there is a parent process) to terminate
1031                           //
1032                           if (daemonOption)
1033                                   notify_parent();
1034                   
1035 kumpf    1.54             return 1;
1036 mike     1.32         }
1037                   
1038                       return 0;
1039                   }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2