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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2