(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 humberto 1.97     /* l10n
 216 mike     1.35     String usage = String (USAGE);
 217                   usage.append (COMMAND_NAME);
 218                   usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
 219                   usage.append ("  options\n");
 220 tony     1.93     usage.append ("    -v              - displays CIM Server version number\n");
 221                   usage.append ("    -h              - prints this help message\n");
 222                   usage.append ("    -s              - shuts down CIM Server\n");
 223 kumpf    1.80 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 224 tony     1.93     usage.append ("    -D [home]       - sets pegasus home directory\n");
 225 kumpf    1.60 #endif
 226               #if defined(PEGASUS_OS_TYPE_WINDOWS)
 227 tony     1.93     usage.append ("    -install [name] - installs pegasus as a Windows NT Service\n");
 228                   usage.append ("                      [name] is optional and overrides the\n");
 229                   usage.append ("                      default CIM Server Service Name\n");
 230                   usage.append ("    -remove [name]  - removes pegasus as a Windows NT Service\n");
 231                   usage.append ("                      [name] is optional and overrides the\n");
 232                   usage.append ("                      default CIM Server Service Name\n");
 233                   usage.append ("    -start [name]   - starts pegasus as a Windows NT Service\n");
 234                   usage.append ("                      [name] is optional and overrides the\n");
 235                   usage.append ("                      default CIM Server Service Name\n");
 236                   usage.append ("    -stop [name]    - stops pegasus as a Windows NT Service\n");
 237                   usage.append ("                      [name] is optional and overrides the\n");
 238                   usage.append ("                      default CIM Server Service Name\n\n");
 239 kumpf    1.54 #endif
 240 mike     1.35     usage.append ("  configProperty=value\n");
 241 tony     1.93     usage.append ("                    - sets CIM Server configuration property\n");
 242 mike     1.35 
 243                   cout << endl;
 244 kumpf    1.80 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 245 kumpf    1.63     cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
 246               #else
 247 mike     1.32     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
 248 kumpf    1.63 #endif
 249 mike     1.32     cout << endl;
 250 mike     1.35     cout << usage << endl;
 251 humberto 1.97     */
 252                   
 253                   String usage = String (USAGE);
 254                   usage.append (COMMAND_NAME);
 255                   usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
 256                   usage.append ("  options\n");
 257                   usage.append ("    -v              - displays CIM Server version number\n");
 258                   usage.append ("    -h              - prints this help message\n");
 259                   usage.append ("    -s              - shuts down CIM Server\n");
 260               #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 261                   //usage.append ("    -D [home]       - sets pegasus home directory\n");
 262                   usage.append("$0");
 263               #endif
 264               #if defined(PEGASUS_OS_TYPE_WINDOWS)
 265                   usage.append ("    -install [name] - installs pegasus as a Windows NT Service\n");
 266                   usage.append ("                      [name] is optional and overrides the\n");
 267                   usage.append ("                      default CIM Server Service Name\n");
 268                   usage.append ("    -remove [name]  - removes pegasus as a Windows NT Service\n");
 269                   usage.append ("                      [name] is optional and overrides the\n");
 270                   usage.append ("                      default CIM Server Service Name\n");
 271                   usage.append ("    -start [name]   - starts pegasus as a Windows NT Service\n");
 272 humberto 1.97     usage.append ("                      [name] is optional and overrides the\n");
 273                   usage.append ("                      default CIM Server Service Name\n");
 274                   usage.append ("    -stop [name]    - stops pegasus as a Windows NT Service\n");
 275                   usage.append ("                      [name] is optional and overrides the\n");
 276                   usage.append ("                      default CIM Server Service Name\n\n");
 277               #endif
 278                   usage.append ("  configProperty=value\n");
 279                   usage.append ("                    - sets CIM Server configuration property\n");
 280               
 281                   cout << endl;
 282               #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 283                   cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
 284               #else
 285                   cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
 286               #endif
 287                   cout << endl;
 288                   
 289               #if defined(PEGASUS_OS_TYPE_WINDOWS)
 290                   MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS",
 291                   						 usage,
 292                   						 "    -D [home]       - sets pegasus home directory\n");
 293 humberto 1.97 #elif !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 294               	MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD",
 295                   						 usage,
 296                   						 "    -D [home]       - sets pegasus home directory\n");
 297               #else
 298               	MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD",
 299                   						 usage);
 300               #endif
 301                   //cout << usage << endl;
 302                   cout << MessageLoader::getMessage(parms) << endl;
 303 mike     1.35 }
 304               
 305 chuck    1.96 // l10n
 306               //
 307               // Dummy function for the Thread object associated with the initial thread.
 308               // Since the initial thread is used to process CIM requests, this is
 309               // needed to localize the exceptions thrown during CIM request processing.
 310               // Note: This function should never be called! 
 311               // 
 312               PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
 313               {
 314                  return((PEGASUS_THREAD_RETURN)0);	
 315               }
 316               
 317 humberto 1.90 //
 318               // cimserver_exit: platform specific exit routine calls
 319               //         
 320               void cimserver_exit( int rc ){
 321               #ifdef PEGASUS_OS_OS400
 322                   cimserver_exitRC(rc);
 323               #endif
 324                   exit(rc);
 325               }
 326               
 327 kumpf    1.52 void shutdownCIMOM(Uint32 timeoutValue)
 328 mike     1.35 {
 329                   //
 330                   // Create CIMClient object
 331                   //
 332 kumpf    1.42     CIMClient client;
 333 mike     1.35 
 334                   //
 335 kumpf    1.53     // Get local host name
 336 mike     1.35     //
 337                   String hostStr = System::getHostName();
 338               
 339                   //
 340                   // open connection to CIMOM 
 341                   //
 342                   try
 343                   {
 344 kumpf    1.43         client.connectLocal();
 345 kumpf    1.52 
 346                       //
 347 kumpf    1.63         // set client timeout to 2 seconds
 348 kumpf    1.52         //
 349 kumpf    1.71         client.setTimeout(2000);
 350 mike     1.35     }
 351 kumpf    1.64     catch(Exception& e)
 352 mike     1.35     {
 353 david    1.85 #ifdef PEGASUS_OS_OS400
 354 humberto 1.97 	//l10n
 355               	//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 356               		    //"Unable to connect to CIM Server.  CIM Server may not be running." );
 357               	Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 358               			"src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
 359 david    1.85 		    "Unable to connect to CIM Server.  CIM Server may not be running." );
 360               	// The server job may still be active but not responding.
 361               	// Kill the job if it exists.
 362 humberto 1.90 	if(cimserver_kill() == -1)
 363               	   cimserver_exit(2);
 364               	cimserver_exit(1);
 365 david    1.85 #else
 366 humberto 1.97         //l10n
 367                       //PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
 368                       //PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
 369                       MessageLoaderParms parms("src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
 370                       						 "Unable to connect to CIM Server.\nCIM Server may not be running.\n");
 371                       PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
 372 chuck    1.66 #endif
 373 konrad.r 1.95         cimserver_exit(1);
 374 mike     1.35     }
 375               
 376                   try
 377                   {
 378                       //
 379 kumpf    1.52         // construct CIMObjectPath
 380 mike     1.35         //
 381                       String referenceStr = "//";
 382                       referenceStr.append(hostStr);
 383 chuck    1.70         referenceStr.append("/");  
 384 kumpf    1.72         referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
 385 kumpf    1.53         referenceStr.append(":");
 386 kumpf    1.72         referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
 387 kumpf    1.50         CIMObjectPath reference(referenceStr);
 388 mike     1.35 
 389                       //
 390                       // issue the invokeMethod request on the shutdown method
 391                       //
 392                       Array<CIMParamValue> inParams;
 393                       Array<CIMParamValue> outParams;
 394               
 395 kumpf    1.52         // set force option to true for now
 396 kumpf    1.40         inParams.append(CIMParamValue("force",
 397 kumpf    1.52             CIMValue(Boolean(true))));
 398 mike     1.35 
 399 kumpf    1.40         inParams.append(CIMParamValue("timeout",
 400 kumpf    1.39             CIMValue(Uint32(timeoutValue))));
 401 mike     1.35 
 402                       CIMValue retValue = client.invokeMethod(
 403 kumpf    1.59             PEGASUS_NAMESPACENAME_SHUTDOWN,
 404 mike     1.35             reference,
 405                           "shutdown",
 406                           inParams,
 407                           outParams);
 408 kumpf    1.43     }
 409 kumpf    1.65     catch(CIMException& e)
 410 kumpf    1.46     {
 411 david    1.85 #ifdef PEGASUS_OS_OS400
 412               
 413               	if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 414               	{
 415 humberto 1.97 	    //l10n
 416               	    //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 417               		    //"Failed to shutdown server: $0", "The repository may be empty.");
 418               		Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 419               			"src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
 420               		    "Failed to shutdown server: The repository may be empty.");
 421 david    1.85 	}
 422               	else
 423               	{
 424 humberto 1.97 	    //l10n
 425               	    //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 426               			//"Failed to shutdown server: $0", e.getMessage());
 427               		Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 428               			"src.Server.cimserver.SHUTDOWN_FAILED",
 429 david    1.85 			"Failed to shutdown server: $0", e.getMessage());
 430               	}
 431               	// Kill the server job.
 432 humberto 1.90 	if(cimserver_kill() == -1)
 433               	   cimserver_exit(2);
 434 david    1.85 #else
 435 humberto 1.97         //l10n
 436                       //PEGASUS_STD(cerr) << "Failed to shutdown server: ";
 437                       MessageLoaderParms parms("src.Server.cimserver.SHUTDOWN_FAILED",
 438                       						 "Failed to shutdown server: ");
 439                       PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
 440 kumpf    1.63         if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 441                       {
 442 humberto 1.97             //PEGASUS_STD(cerr) << "The repository may be empty.";
 443                           //PEGASUS_STD(cerr) << PEGASUS_STD(endl);
 444                           MessageLoaderParms parms("src.Server.cimserver.REPOSITORY_EMPTY",
 445                       						 	 "The repository may be empty.");
 446                       	PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
 447 kumpf    1.63         }
 448                       else
 449                       {
 450                           PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
 451                       }
 452 chuck    1.66 #endif
 453 humberto 1.90         cimserver_exit(1);
 454 david    1.85 
 455 kumpf    1.46     }
 456 kumpf    1.65     catch(Exception& e)
 457 kumpf    1.45     {
 458                       //
 459 kumpf    1.91         // This may mean that the CIM Server has terminated, causing this
 460                       // client to get a "Empty HTTP response message" exception.  It may
 461                       // also mean that the CIM Server is taking longer than 2 seconds 
 462                       // (client timeout value) to terminate, causing this client to 
 463                       // timeout with a "connection timeout" exception.
 464 kumpf    1.45         //
 465 kumpf    1.91         // Check to see if CIM Server is still running.  If CIM Server
 466 kumpf    1.63         // is still running and the shutdown timeout has not expired,
 467 kumpf    1.91         // loop and wait one second until either the CIM Server is
 468                       // terminated or timeout expires.  If timeout expires and
 469                       // the CIM Server is still running, kill the CIMServer process.
 470                       // 
 471 kumpf    1.63         Uint32 maxWaitTime = timeoutValue - 2;
 472                       Boolean running = isCIMServerRunning();
 473                       while ( running && maxWaitTime > 0 )
 474                       {
 475                           System::sleep(1);
 476                           running = isCIMServerRunning();
 477                           maxWaitTime = maxWaitTime - 1;
 478                       }
 479               
 480                       if (running)
 481                       {
 482 humberto 1.90             int kill_rc = cimserver_kill();
 483               #ifdef PEGASUS_OS_OS400
 484               	    if(kill_rc == -1)
 485               		cimserver_exit(2);
 486               	    cimserver_exit(1);
 487               #endif
 488 kumpf    1.91 
 489 marek    1.92 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 490 kumpf    1.91 	    if (kill_rc != -1)
 491                           {
 492 humberto 1.97                 //l10n
 493                               //cout << "Shutdown timeout expired.  CIM Server process killed." << endl;
 494                               MessageLoaderParms parms("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 495                               						 "Shutdown timeout expired.  CIM Server process killed.");
 496                               cout << MessageLoader::getMessage(parms) << endl;
 497 kumpf    1.91                 exit(0);
 498                           }
 499               #endif
 500 kumpf    1.63         }
 501 kumpf    1.43     }
 502 mike     1.35 
 503                   return;
 504 mike     1.32 }
 505               
 506 mike     1.35 
 507 mike     1.33 /////////////////////////////////////////////////////////////////////////
 508 mike     1.32 //  MAIN
 509               //////////////////////////////////////////////////////////////////////////
 510               int main(int argc, char** argv)
 511               {
 512 mike     1.35     String pegasusHome  = String::EMPTY;
 513                   String logsDirectory = String::EMPTY;
 514                   Boolean useSLP = false;
 515                   Boolean daemonOption = false;
 516                   Boolean shutdownOption = false;
 517 kumpf    1.60     Uint32 timeoutValue  = 0;
 518 mday     1.47 
 519 humberto 1.97 //l10n
 520               // Set Message loading to process locale
 521               MessageLoader::_useProcessLocale = true; 
 522               //l10n
 523               
 524 chuck    1.66 #ifdef PEGASUS_OS_OS400
 525                   // Initialize Pegasus home to the shipped OS/400 directory.
 526                   pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
 527               #endif
 528               
 529 tony     1.82 #ifndef PEGASUS_OS_TYPE_WINDOWS
 530 kumpf    1.38     //
 531                   // Get environment variables:
 532                   //
 533                   const char* tmp = getenv("PEGASUS_HOME");
 534               
 535                   if (tmp)
 536                   {
 537                       pegasusHome = tmp;
 538                   }
 539               
 540                   FileSystem::translateSlashes(pegasusHome);
 541 tony     1.82 #else
 542 kumpf    1.38 
 543 tony     1.82   // windows only
 544                 setHome(pegasusHome);
 545               #endif
 546 mike     1.32     // on Windows NT if there are no command-line options, run as a service
 547               
 548                   if (argc == 1 )
 549 mike     1.35     {
 550                     cim_server_service(argc, argv);
 551                   }
 552                   else
 553                   {
 554 kumpf    1.60         // Get help, version, and shutdown options
 555 mike     1.35 
 556                       for (int i = 1; i < argc; )
 557                       {
 558                           const char* arg = argv[i];
 559               
 560                           // Check for -option
 561                           if (*arg == '-')
 562                           {
 563                               // Get the option
 564                               const char* option = arg + 1;
 565               
 566                               //
 567                               // Check to see if user asked for the version (-v option):
 568                               //
 569 tony     1.83                 if (*option == OPTION_VERSION &&
 570                                   strlen(option) == 1)
 571 mike     1.35                 {
 572 kumpf    1.80 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 573 kumpf    1.63                     cout << PLATFORM_PRODUCT_VERSION << endl;
 574               #else
 575 mike     1.35                     cout << PEGASUS_VERSION << endl;
 576 kumpf    1.63 #endif
 577 mike     1.35                     exit(0);
 578                               }
 579                               //
 580                               // Check to see if user asked for help (-h option):
 581                               //
 582 tony     1.83                 else if (*option == OPTION_HELP &&
 583                                       (strlen(option) == 1))
 584 mike     1.35                 {
 585                                   PrintHelp(argv[0]);
 586                                   exit(0);
 587                               }
 588 kumpf    1.80 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 589 tony     1.83                 else if (*option == OPTION_HOME &&
 590                                       (strlen(option) == 1))
 591 mike     1.35                 {
 592 kumpf    1.60                     if (i + 1 < argc)
 593 mike     1.35                     {
 594                                       pegasusHome.assign(argv[i + 1]);
 595                                   }
 596                                   else
 597                                   {
 598 humberto 1.97                         //l10n
 599                                       //cout << "Missing argument for option -" << option << endl;
 600                                       MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
 601                               						 "Missing argument for option -$0",
 602                               						 String(option));
 603                               		cout << MessageLoader::getMessage(parms) << endl;
 604 mike     1.35                         exit(0);
 605                                   }
 606               
 607                                   memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 608                                   argc -= 2;
 609                               }
 610 kumpf    1.63 #endif
 611 kumpf    1.48 #if defined(PEGASUS_OS_HPUX)
 612                               //
 613 kumpf    1.49                 // Check to see if user asked for the version (-X option):
 614 kumpf    1.48                 //
 615 tony     1.83                 if (*option == OPTION_BINDVERBOSE &&
 616                                       (strlen(option) == 1))
 617 kumpf    1.48                 {
 618               		    System::bindVerbose = true;
 619 humberto 1.97                     //l10n
 620                                   //cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
 621                                        //<< endl;
 622                                   MessageLoaderParms parms("src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
 623                               						 "Unsupported debug option, BIND_VERBOSE, enabled.");
 624                               	cout << MessageLoader::getMessage(parms) << endl;
 625 kumpf    1.48                     // remove the option from the command line
 626                                   memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 627                                   argc--;   
 628                               }
 629               #endif
 630 mike     1.35                 //
 631                               // Check to see if user asked for shutdown (-s option):
 632                               //
 633 tony     1.82                 else if (*option == OPTION_SHUTDOWN &&
 634                                       (strlen(option) == 1))
 635 mike     1.35                 {
 636                                   //
 637 kumpf    1.52                     // check to see if user is root
 638 mike     1.35                     //
 639 chuck    1.70 #ifndef PEGASUS_OS_OS400
 640 kumpf    1.55                     if (!System::isPrivilegedUser(System::getEffectiveUserName()))
 641 mike     1.35                     {
 642 humberto 1.97                         //l10n
 643                                       //cout << "You must have superuser privilege to run ";
 644                                       //cout << "cimserver." << endl;
 645                                       MessageLoaderParms parms("src.Server.cimserver.SUPERVISOR_PRIVALEDGE_TO_RUN_SERVER",
 646                                       						 "You must have superuser privilege to run cimserver.");
 647                                      
 648                                       cout << MessageLoader::getMessage(parms) << endl;
 649 mike     1.35                         exit(0);
 650                                   }
 651 chuck    1.70 #endif
 652 mike     1.35 
 653                                   //
 654 kumpf    1.52                     // Check to see if shutdown has already been specified:
 655 mike     1.35                     //
 656 kumpf    1.52                     if (shutdownOption)
 657 mike     1.35                     {
 658 humberto 1.97                         //l10n
 659                                       //cout << "Duplicate shutdown option specified." << endl;
 660                                       MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
 661                                       						 "Duplicate shutdown option specified.");
 662                                      
 663                                       cout << MessageLoader::getMessage(parms) << endl;
 664 mike     1.35                         exit(0);
 665                                   }
 666               
 667 kumpf    1.52                     shutdownOption = true;
 668 mike     1.35  
 669                                   // remove the option from the command line
 670                                   memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 671                                   argc--;   
 672                               }
 673 kumpf    1.84 #ifdef PEGASUS_OS_TYPE_WINDOWS
 674 tony     1.83                 else if (strcmp(option, OPTION_INSTALL) == 0)
 675                               {
 676                                 //
 677                                 // Install as a NT service
 678                                 //
 679 tony     1.93                   char *opt_arg = NULL;
 680                                 if (i+1 < argc)
 681                                 {
 682                                   opt_arg = argv[i+1];
 683                                   
 684                                 }
 685                                 if(cimserver_install_nt_service(opt_arg))
 686 tony     1.83                   {
 687 humberto 1.97                      //l10n
 688                                     //cout << "\nPegasus installed as NT Service";
 689                                     MessageLoaderParms parms("src.Server.cimserver.INSTALLED_NT_SERVICE",
 690                                       					   "\n$0 installed as NT Service",
 691                                       					   "Pegasus");
 692                                      
 693                                     cout << MessageLoader::getMessage(parms) << endl;
 694 tony     1.83                       exit(0);
 695                                 }
 696                                 else
 697                                 {
 698                                     exit(0);
 699                                 }
 700                               }
 701                               else if (strcmp(option, OPTION_REMOVE) == 0)
 702                               {
 703                                 //
 704                                 // Remove Pegasus as an NT service
 705                                 //
 706 tony     1.93                   char *opt_arg = NULL;
 707                                 if (i+1 < argc)
 708                                 {
 709                                   opt_arg = argv[i+1];                    
 710                                 }
 711                                 if(cimserver_remove_nt_service(opt_arg))
 712 tony     1.83                   {
 713 humberto 1.97                       //l10n
 714                                     //cout << "\nPegasus removed as NT Service";
 715                                     MessageLoaderParms parms("src.Server.cimserver.REMOVED_NT_SERVICE",
 716                                       					   "\n$0 removed as NT Service",
 717                                       					   "Pegasus");
 718                                      
 719                                     cout << MessageLoader::getMessage(parms) << endl;
 720 tony     1.83                       exit(0);
 721                                 }
 722                                 else
 723                                 {
 724                                     exit(0);
 725                                 }
 726               
 727                               }
 728                               else if (strcmp(option, OPTION_START) == 0)
 729                               {
 730                                 //
 731                                 // Start as a NT service
 732                                 //
 733 tony     1.93                   char *opt_arg = NULL;
 734                                 if (i+1 < argc)
 735                                 {
 736                                   opt_arg = argv[i+1];                    
 737                                 }
 738                                 if(cimserver_start_nt_service(opt_arg))
 739 tony     1.83                   {
 740 humberto 1.97                       //l10n
 741                                     //cout << "\nPegasus started as NT Service";
 742                                     MessageLoaderParms parms("src.Server.cimserver.STARTED_NT_SERVICE",
 743                                       					   "\n$0 started as NT Service",
 744                                       					   "Pegasus");
 745                                      
 746                                     cout << MessageLoader::getMessage(parms) << endl;
 747 tony     1.83                       exit(0);
 748                                 }
 749                                 else
 750                                 {
 751                                     exit(0);
 752                                 }
 753                               }
 754                               else if (strcmp(option, OPTION_STOP) == 0)
 755                               {
 756                                 //
 757                                 // Stop as a NT service
 758                                 //
 759 tony     1.93                   char *opt_arg = NULL;
 760                                 if (i+1 < argc)
 761                                 {
 762                                   opt_arg = argv[i+1];                    
 763                                 }
 764                                 if(cimserver_stop_nt_service(opt_arg))
 765 tony     1.83                   {
 766 humberto 1.97                       //l10n
 767                                     //cout << "\nPegasus stopped as NT Service";
 768                                     MessageLoaderParms parms("src.Server.cimserver.STOPPED_NT_SERVICE",
 769                                       					   "\n$0 stopped as NT Service",
 770                                       					   "Pegasus");
 771                                      
 772                                     cout << MessageLoader::getMessage(parms) << endl;
 773 tony     1.83                       exit(0);
 774                                 }
 775                                 else
 776                                 {
 777                                     exit(0);
 778                                 }
 779                               }
 780 kumpf    1.84 #endif
 781 mike     1.35                 else
 782                                   i++;
 783                           }
 784                           else
 785                               i++;
 786 mike     1.32         }
 787                   }
 788 mike     1.35 
 789 kumpf    1.38     //
 790                   // Set the value for pegasusHome property
 791                   //
 792                   ConfigManager::setPegasusHome(pegasusHome);
 793 mike     1.32 
 794 mike     1.35     //
 795                   // Get an instance of the Config Manager.
 796                   //
 797                   configManager = ConfigManager::getInstance();
 798               
 799                   //
 800 mike     1.32     // Get options (from command line and from configuration file); this
 801 mike     1.35     // removes corresponding options and their arguments from the command
 802 mike     1.32     // line.
 803 mike     1.35     //
 804 mike     1.32     try
 805                   {
 806 mike     1.35         GetOptions(configManager, argc, argv, pegasusHome);
 807 mike     1.32     }
 808                   catch (Exception& e)
 809                   {
 810 david    1.85 #ifdef PEGASUS_OS_OS400
 811 david    1.88 	Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 812 david    1.85 			"$0: $1",argv[0] ,e.getMessage());
 813               #else
 814 mike     1.35         cerr << argv[0] << ": " << e.getMessage() << endl;
 815 david    1.85 #endif
 816 mike     1.35         exit(1);
 817 mike     1.32     }
 818               
 819 chuck    1.94 // l10n
 820               	// Set the home directory, msg sub-dir, into the MessageLoader.
 821               	// This will be the default directory where the resource bundles 
 822               	// are found.
 823               	String messagesDir = String::EMPTY;
 824               #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM
 825               	messagesDir = OS400_DEFAULT_MESSAGE_SOURCE;
 826               #else
 827               	messagesDir = ConfigManager::getHomedPath("msg");
 828               #endif
 829               	MessageLoader::setPegasusMsgHome(messagesDir);		
 830               
 831 kumpf    1.87     Boolean enableHttpConnection = String::equal(
 832                       configManager->getCurrentValue("enableHttpConnection"), "true");
 833                   Boolean enableHttpsConnection = String::equal(
 834                       configManager->getCurrentValue("enableHttpsConnection"), "true");
 835 kumpf    1.86 
 836                   // Make sure at least one connection is enabled
 837               #ifndef PEGASUS_LOCAL_DOMAIN_SOCKET
 838                   if (!enableHttpConnection && !enableHttpsConnection)
 839                   {
 840 humberto 1.97         //l10n
 841                       //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 842                           //"Neither HTTP nor HTTPS connection is enabled.  "
 843                           //"CIMServer will not be started.");
 844                       Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 845                       	"src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 846                           "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 847                       //cerr << "Neither HTTP nor HTTPS connection is enabled.  "
 848                           //"CIMServer will not be started." << endl;
 849                       MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 850                       						 "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 851                       cerr << MessageLoader::getMessage(parms) << endl;
 852 kumpf    1.86         exit(1);
 853                   }
 854               #endif
 855               
 856 mike     1.35     try
 857 mike     1.32     {
 858 mike     1.35         //
 859                       // Check to see if we should Pegasus as a daemon
 860                       //
 861               
 862                       if (String::equal(configManager->getCurrentValue("daemon"), "true"))
 863                       {
 864                           daemonOption = true;
 865                       }
 866 mday     1.62 	
 867 kumpf    1.36         // Get the log file directory definition.
 868                       // We put String into Cstring because
 869                       // Directory functions only handle Cstring.
 870                       // ATTN-KS: create String based directory functions.
 871               
 872                       logsDirectory = configManager->getCurrentValue("logdir");
 873 kumpf    1.38         logsDirectory = 
 874               	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
 875 kumpf    1.36 
 876                       // Set up the Logger. This does not open the logs
 877                       // Might be more logical to clean before set.
 878                       // ATTN: Need tool to completely disable logging.
 879               
 880 david    1.85 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 881               !defined(PEGASUS_OS_OS400)
 882 kumpf    1.36         Logger::setHomeDirectory(logsDirectory);
 883 kumpf    1.57 #endif
 884 kumpf    1.36 
 885                       //
 886 mike     1.35         // Check to see if we need to shutdown CIMOM 
 887                       //
 888                       if (shutdownOption)
 889                       {
 890 kumpf    1.60             String configTimeout = 
 891                               configManager->getCurrentValue("shutdownTimeout");
 892 kumpf    1.69             timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
 893 kumpf    1.60             
 894 kumpf    1.52             shutdownCIMOM(timeoutValue);
 895 kumpf    1.45 
 896 david    1.85 #ifdef PEGASUS_OS_OS400
 897 humberto 1.97 	    //l10n
 898               	    //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 899               			//"CIM Server stopped.");  
 900               		Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 901               			"src.Server.cimserver.SERVER_STOPPED",
 902               			"$0 Server stopped.", "CIM");
 903 david    1.85 #else
 904 humberto 1.97 			//l10n
 905                           //cout << "CIM Server stopped." << endl;
 906                           MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",
 907                           						 "$0 Server stopped.",
 908                           						 "CIM");
 909                           cout << MessageLoader::getMessage(parms) << endl;
 910 diane    1.81 #endif
 911 humberto 1.90             cimserver_exit(0);
 912 mike     1.35         }
 913 mike     1.32 
 914 kumpf    1.36         // Leave this in until people get familiar with the logs.
 915 david    1.85 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 916               !defined(PEGASUS_OS_OS400)
 917 humberto 1.97         //l10n
 918                       //cout << "Logs Directory = " << logsDirectory << endl;
 919                       MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
 920                           				     "Logs Directory = ");
 921                       cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
 922 kumpf    1.57 #endif
 923 mike     1.35 
 924                       if (String::equal(configManager->getCurrentValue("slp"), "true"))
 925                       {
 926                           useSLP =  true;
 927                       }
 928 mike     1.32     }
 929 mike     1.35     catch (UnrecognizedConfigProperty e)
 930 mike     1.32     {
 931 david    1.85 
 932               #ifdef PEGASUS_OS_OS400
 933 humberto 1.97 	//l10n
 934               	//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 935               		    //"Error: $0",e.getMessage());  
 936               	Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 937               			"src.Server.cimserver.ERROR",
 938               		    "Error: $0",e.getMessage()); 
 939 david    1.85 #else
 940 humberto 1.97 	//l10n
 941               	//cout << "Error: " << e.getMessage() << endl;
 942               	MessageLoaderParms parms("src.Server.cimserver.ERROR",
 943               							 "Error: $0",
 944               							 e.getMessage());
 945               	cout << MessageLoader::getMessage(parms) << endl;
 946 david    1.85 #endif
 947 mike     1.32     }
 948               
 949 kumpf    1.86     Uint32 portNumberHttps;
 950                   Uint32 portNumberHttp;
 951 kumpf    1.53 
 952 kumpf    1.86     if (enableHttpsConnection)
 953 kumpf    1.53     {
 954 kumpf    1.86         String httpsPort = configManager->getCurrentValue("httpsPort");
 955 kumpf    1.69         CString portString = httpsPort.getCString();
 956 kumpf    1.86         char* end = 0;
 957                       Uint32 port = strtol(portString, &end, 10);
 958                       assert(end != 0 && *end == '\0');
 959 kumpf    1.53 
 960                       //
 961 kumpf    1.86         // Look up the WBEM-HTTPS port number
 962 kumpf    1.53         //
 963 kumpf    1.86         portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
 964 kumpf    1.53     }
 965 kumpf    1.86 
 966                   if (enableHttpConnection)
 967 kumpf    1.53     {
 968 kumpf    1.86         String httpPort = configManager->getCurrentValue("httpPort");
 969 kumpf    1.69         CString portString = httpPort.getCString();
 970 kumpf    1.86         char* end = 0;
 971                       Uint32 port = strtol(portString, &end, 10);
 972                       assert(end != 0 && *end == '\0');
 973 kumpf    1.53 
 974                       //
 975 kumpf    1.86         // Look up the WBEM-HTTP port number
 976 kumpf    1.53         //
 977 kumpf    1.86         portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
 978 kumpf    1.53     }
 979 mike     1.32 
 980                   // Put out startup up message.
 981 david    1.85 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 982               !defined(PEGASUS_OS_OS400)
 983 kumpf    1.86     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
 984 humberto 1.97     //l10n
 985                   //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
 986                   //cout <<"Starting..."
 987                   MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
 988                   						 "Built $0 $1\nStarting...",
 989                   						 __DATE__,
 990                   						 __TIME__);
 991                   cout << MessageLoader::getMessage(parms)
 992               	 	 << (useSLP ? " SLP reg. " : " No SLP ")
 993               		 << endl;
 994               #endif
 995               
 996               //l10n
 997               // reset message loading to NON-process locale
 998               MessageLoader::_useProcessLocale = false; 
 999               //l10n
1000 mike     1.32 
1001 kumpf    1.63     // do we need to run as a daemon ?
1002                   if (daemonOption)
1003                   {
1004                       if(-1 == cimserver_fork())
1005 diane    1.81 #ifndef PEGASUS_OS_OS400
1006 konrad.r 1.95 	{	
1007 david    1.85 	    exit(-1);
1008               	}
1009 diane    1.81 #else
1010 david    1.85 	{
1011                           return(-1);
1012               	}
1013 diane    1.81 	else
1014 david    1.85 	{
1015               	    return(0);
1016               	}
1017 diane    1.81 #endif
1018 david    1.85 	
1019 kumpf    1.63     }
1020 chuck    1.66 
1021 chuck    1.96 // l10n
1022                   // Now we are after the fork...
1023                   // Create a dummy Thread object that can be used to store the
1024                   // AcceptLanguages object for CIM requests that are serviced
1025                   // by this thread (initial thread of server).  Need to do this
1026                   // because this thread is not in a ThreadPool, but is used
1027                   // to service CIM requests.
1028                   // The run function for the dummy Thread should never be called,
1029                   Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
1030                   Thread::setCurrent(dummyInitialThread);
1031 humberto 1.97     AcceptLanguages default_al = AcceptLanguages::getDefaultAcceptLanguages();
1032                   Thread::setLanguages(new AcceptLanguages(default_al));
1033                   
1034 chuck    1.96 
1035 chuck    1.66 #ifdef PEGASUS_OS_OS400
1036                   // Special server initialization code for OS/400.
1037                   if (cimserver_initialize() != 0)
1038                   {
1039 david    1.85 	// do some logging here!
1040 humberto 1.97 	//l10n
1041               	//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1042               		    //"CIM Server failed to initialize"); 
1043               	Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1044               				  "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE",
1045               		    	  "CIM Server failed to initialize");  
1046 david    1.85 	exit(-1);
1047 chuck    1.66     } 
1048               #endif
1049 chuck    1.96 
1050 mday     1.62 
1051 marek    1.92 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1052 kumpf    1.63     umask(S_IWGRP|S_IWOTH);
1053 kumpf    1.79 
1054                   //
1055                   // check if CIMServer is already running
1056                   // if CIMServer is already running, print message and 
1057                   // notify parent process (if there is a parent process) to terminate
1058                   //
1059                   if(isCIMServerRunning())
1060                   {
1061 humberto 1.97 	//l10n
1062               		//cout << "Unable to start CIMServer." << endl;
1063               		//cout << "CIMServer is already running." << endl;
1064               		MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
1065               								 "Unable to start $0.\n$1 is already running.",
1066               								 "CIMServer","CIMServer");
1067 kumpf    1.79 
1068               	//
1069                       // notify parent process (if there is a parent process) to terminate
1070                       //
1071                       if (daemonOption)
1072 konrad.r 1.95                 notify_parent(1);
1073 kumpf    1.79 
1074                       exit(1);
1075                   }
1076                    
1077 kumpf    1.63 #endif
1078 kumpf    1.51 
1079 mike     1.32     // try loop to bind the address, and run the server
1080                   try
1081                   {
1082 kumpf    1.75 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
1083 kumpf    1.86         char slp_address[32];
1084 mike     1.32       	slp_client *discovery = new slp_client() ;;
1085                       String serviceURL;
1086               	serviceURL.assign("service:cim.pegasus://");
1087               	String host_name = slp_get_host_name();
1088 kumpf    1.67 	serviceURL.append(host_name);
1089               	serviceURL.append(":");
1090 kumpf    1.86         // ATTN: Fix this to work for multiple connections
1091                       sprintf(slp_address, "%u",
1092                               enableHttpConnection ? portNumberHttp : portNumberHttps);
1093                       serviceURL.append(slp_address);
1094 mike     1.35 #endif
1095 mike     1.32 
1096 mday     1.61 	Monitor monitor(true);
1097 kumpf    1.86 	CIMServer server(&monitor);
1098 kumpf    1.41 
1099 kumpf    1.86         if (enableHttpConnection)
1100                       {
1101                           server.addAcceptor(false, portNumberHttp, false);
1102 humberto 1.97             //l10n
1103                           //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1104                                       //"Listening on HTTP port $0.", portNumberHttp);
1105                                       
1106                           Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1107                           				"src.Server.cimserver.LISTENING_ON_PORT"
1108                                       	"Listening on $0 port $1.", "HTTP",portNumberHttp);
1109 kumpf    1.86         }
1110                       if (enableHttpsConnection)
1111                       {
1112                           server.addAcceptor(false, portNumberHttps, true);
1113 humberto 1.97             //l10n
1114                           //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1115                                       //"Listening on HTTPS port $0.", portNumberHttps);
1116                           Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1117                           				"src.Server.cimserver.LISTENING_ON_PORT"
1118                                       	"Listening on $0 port $1.", "HTTPS",portNumberHttps);
1119 kumpf    1.86         }
1120 kumpf    1.41 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
1121 kumpf    1.86         server.addAcceptor(true, 0, false);
1122 humberto 1.97         //l10n
1123                       //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1124                                   //"Listening on local connection socket.");
1125                       Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1126                           				"src.Server.cimserver.LISTENING_ON_LOCAL"
1127                                       	"Listening on local connection socket.");
1128 kumpf    1.41 #endif
1129 kumpf    1.86 
1130               #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && !defined(PEGASUS_OS_OS400)
1131                       if (enableHttpConnection)
1132                       {
1133 humberto 1.97             //l10n
1134                           //cout << "Listening on HTTP port " << portNumberHttp << endl;
1135                           MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_PORT",
1136                           						 "Listening on $0 port $1.", "HTTP",portNumberHttp);
1137                          	cout << MessageLoader::getMessage(parms) << endl;
1138 kumpf    1.86         }
1139                       if (enableHttpsConnection)
1140                       {
1141 humberto 1.97             //l10n
1142                           //cout << "Listening on HTTPS port " << portNumberHttps << endl;
1143                           MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_PORT",
1144                           						 "Listening on $0 port $1.", "HTTPS",portNumberHttps);
1145                          	cout << MessageLoader::getMessage(parms) << endl;
1146 kumpf    1.86         }
1147               # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
1148 humberto 1.97         //l10n
1149                       //cout << "Listening on local connection socket" << endl;
1150                       MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",
1151                           					 "Listening on local connection socket.");
1152                       cout << MessageLoader::getMessage(parms) << endl;
1153 kumpf    1.86 # endif
1154 david    1.85 #endif
1155 mike     1.35 
1156 kumpf    1.86         // bind throws an exception if the bind fails
1157                       server.bind();
1158 kumpf    1.73 
1159 dan      1.76 	// notify parent process (if there is a parent process) to terminate 
1160 konrad.r 1.95         // so user knows that there is cimserver ready to serve CIM requests.
1161 dan      1.76 	if (daemonOption)
1162 konrad.r 1.95 		notify_parent(0);
1163 mike     1.32 
1164               	time_t last = 0;
1165 mike     1.35 
1166 marek    1.92 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1167 kumpf    1.45         //
1168 kumpf    1.56         // create a file to indicate that the cimserver has started and
1169                       // save the process id of the cimserver process in the file
1170 kumpf    1.45         //
1171 kumpf    1.56         // remove the old file if it exists
1172 kumpf    1.91         System::removeFile(CIMSERVER_START_FILE);
1173 kumpf    1.56 
1174                       // open the file
1175 kumpf    1.91         FILE *pid_file = fopen(CIMSERVER_START_FILE, "w");
1176               
1177 kumpf    1.56         if (pid_file)
1178 kumpf    1.45         {
1179 kumpf    1.56             // save the pid in the file
1180                           fprintf(pid_file, "%ld\n", (long)server_pid);
1181                           fclose(pid_file);
1182 kumpf    1.45         }
1183               #endif
1184 kumpf    1.91 
1185 david    1.85 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
1186               !defined(PEGASUS_OS_OS400)
1187 kumpf    1.54 	cout << "Started. " << endl;
1188 kumpf    1.63 #endif
1189 kumpf    1.54 
1190                       // Put server started message to the logger
1191 kumpf    1.80 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
1192 humberto 1.97         //l10n
1193                       //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1194                                   //"Started $0 version $1.",
1195                                   //PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
1196                       Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1197                       			"src.Server.cimserver.STARTED_VERSION",
1198 kumpf    1.86                     "Started $0 version $1.",
1199                                   PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
1200 kumpf    1.63 #else
1201 humberto 1.97 		//l10n
1202                       //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1203                                   //"Started $0 version $1.",
1204                                   //PEGASUS_NAME, PEGASUS_VERSION);
1205                       Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1206                       			"src.Server.cimserver.STARTED_VERSION",
1207 kumpf    1.86                     "Started $0 version $1.",
1208                                   PEGASUS_NAME, PEGASUS_VERSION);
1209 kumpf    1.63 #endif
1210 kumpf    1.45 
1211 mday     1.62 	
1212 mike     1.35         //
1213                       // Loop to call CIMServer's runForever() method until CIMServer
1214                       // has been shutdown
1215                       //
1216               	while( !server.terminated() )
1217 mike     1.32 	{
1218 kumpf    1.75 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
1219 mike     1.32 	  if(useSLP  ) 
1220               	  {
1221               	    if(  (time(NULL) - last ) > 60 ) 
1222               	    {
1223 kumpf    1.69 	      if( discovery != NULL && serviceURL.size() )
1224               		discovery->srv_reg_all(serviceURL.getCString(),
1225 mike     1.35 				       "(namespace=root/cimv2)",
1226 mike     1.32 				       "service:cim.pegasus", 
1227               				       "DEFAULT", 
1228               				       70) ;
1229               	      time(&last);
1230               	    }
1231               	  
1232               	    discovery->service_listener();
1233               	  }
1234 mike     1.35 #endif
1235 mike     1.32 	  server.runForever();
1236               	}
1237               
1238 kumpf    1.45         //
1239                       // normal termination
1240 mike     1.34 	//
1241 kumpf    1.54         // Put server shutdown message to the logger
1242 kumpf    1.86 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
1243 humberto 1.97         //l10n
1244                       //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1245                           //"$0 stopped.", PLATFORM_PRODUCT_NAME);
1246                       Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1247                       	"src.Server.cimserver.STOPPED",
1248 kumpf    1.86             "$0 stopped.", PLATFORM_PRODUCT_NAME);
1249               #else
1250 humberto 1.97 		//l10n
1251                       //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1252                           //"$0 stopped.", PEGASUS_NAME);
1253                       Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1254                       	"src.Server.cimserver.STOPPED",
1255 kumpf    1.54             "$0 stopped.", PEGASUS_NAME);
1256 kumpf    1.86 #endif
1257 kumpf    1.45 
1258 marek    1.92 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1259 kumpf    1.45         //
1260 kumpf    1.56         // close the file created at startup time to indicate that the 
1261                       // cimserver has terminated normally.
1262 kumpf    1.45         //
1263 kumpf    1.91         FileSystem::removeFile(CIMSERVER_START_FILE);
1264 kumpf    1.45 #endif
1265 mike     1.32     }
1266                   catch(Exception& e)
1267                   {
1268 humberto 1.97 	//l10n
1269               	//Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1270               		    //"Error: $0", e.getMessage()); 
1271               	Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1272               			"src.Server.cimserver.ERROR",
1273               		    "Error: $0", e.getMessage());  
1274 konrad.r 1.95 
1275               #ifndef PEGASUS_OS_OS400
1276 humberto 1.97 	//l10n
1277               	//PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1278               	MessageLoaderParms parms("src.Server.cimserver.ERROR",
1279               							 "Error: $0", e.getMessage());
1280               	PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1281 david    1.85 #endif
1282 kumpf    1.77 
1283               	//
1284                       // notify parent process (if there is a parent process) to terminate
1285                       //
1286                       if (daemonOption)
1287 konrad.r 1.95                 notify_parent(1);
1288 kumpf    1.77 
1289 kumpf    1.54         return 1;
1290 mike     1.32     }
1291               
1292                   return 0;
1293               }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2