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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2