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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2