(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 mike     1.32  //%/////////////////////////////////////////////////////////////////////////////
  52                
  53                
  54                //////////////////////////////////////////////////////////////////////
  55                //
  56                // Notes on deamon operation (Unix) and service operation (Win 32):
  57                //
  58 kumpf    1.60  // To run pegasus as a daemon on Unix platforms: 
  59 mike     1.32  //
  60 kumpf    1.60  // cimserver
  61 mike     1.32  //
  62 kumpf    1.60  // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
  63                // property to false:
  64                //
  65                // cimserver daemon=false
  66                //
  67                // The daemon config property has no effect on windows operation. 
  68 mike     1.32  //
  69 mike     1.35  // To shutdown pegasus, use the -s option:
  70                // 
  71 kumpf    1.60  // cimserver -s 
  72 mike     1.35  //
  73 mike     1.32  // To run pegasus as an NT service, there are FOUR  different possibilities:
  74                //
  75                // To INSTALL the Pegasus service, 
  76                //
  77                // cimserver -install
  78                //
  79                // To REMOVE the Pegasus service, 
  80                //
  81                // cimserver -remove
  82                //
  83                // To START the Pegasus service, 
  84                //
  85                // net start cimserver
  86 s.hills  1.117 // or
  87                // cimserver -start
  88 mike     1.32  //
  89                // To STOP the Pegasus service, 
  90                //
  91                // net stop cimserver
  92 s.hills  1.117 // or
  93                // cimserver -stop
  94 mike     1.32  //
  95                // Alternatively, you can use the windows service manager. Pegasus shows up 
  96                // in the service database as "Pegasus CIM Object Manager"
  97                //
  98                // Mike Day, mdday@us.ibm.com
  99                // 
 100                //////////////////////////////////////////////////////////////////////
 101                
 102                
 103 mike     1.35  #include <Pegasus/Common/Config.h>
 104 kumpf    1.59  #include <Pegasus/Common/Constants.h>
 105 mike     1.32  #include <iostream>
 106 mike     1.35  #include <cassert>
 107 mike     1.32  #include <cstdlib>
 108 kumpf    1.45  #include <fstream>
 109 mike     1.32  #include <Pegasus/Common/FileSystem.h>
 110 mike     1.35  #include <Pegasus/Common/Monitor.h>
 111 mike     1.32  #include <Pegasus/Server/CIMServer.h>
 112                #include <Pegasus/Common/PegasusVersion.h>
 113                #include <Pegasus/Common/Logger.h>
 114                #include <Pegasus/Common/System.h>
 115 mike     1.35  #include <Pegasus/Common/Tracer.h>
 116                #include <Pegasus/Config/ConfigManager.h>
 117                #include <Pegasus/Client/CIMClient.h>
 118                #include <Pegasus/Server/ShutdownService.h>
 119 mike     1.32  
 120 kumpf    1.119 PEGASUS_USING_PEGASUS;
 121                PEGASUS_USING_STD;
 122                
 123 kumpf    1.118 int cimserver_run( int argc, char** argv, Boolean shutdownOption );
 124 mike     1.32  
 125 kumpf    1.137 Uint32 parentPid = 0;
 126                
 127 mike     1.32  #if defined(PEGASUS_OS_TYPE_WINDOWS)
 128                # include "cimserver_windows.cpp"
 129                #elif defined(PEGASUS_OS_TYPE_UNIX)
 130 chuck    1.66  # if defined(PEGASUS_OS_OS400)
 131 david    1.120 #  include "vfyptrs.cinc"
 132 david    1.100 #  include "OS400ConvertChar.h"
 133 chuck    1.66  #  include "cimserver_os400.cpp"
 134                # else
 135                #  include "cimserver_unix.cpp"
 136                #endif
 137 mike     1.32  #else
 138                # error "Unsupported platform"
 139                #endif
 140                
 141 mike     1.35  //
 142                //  The command name.
 143                //
 144                static const char COMMAND_NAME []    = "cimserver";
 145                
 146                //
 147                //  The constant defining usage string.
 148                //
 149                static const char USAGE []           = "Usage: ";
 150                
 151                /**
 152                Constants representing the command line options.
 153                */
 154                static const char OPTION_VERSION     = 'v';
 155                
 156                static const char OPTION_HELP        = 'h';
 157                
 158                static const char OPTION_HOME        = 'D';
 159                
 160                static const char OPTION_SHUTDOWN    = 's';
 161                
 162 a.arora  1.142 static const char   LONG_HELP []  = "help";
 163                
 164                static const char   LONG_VERSION []  = "version";
 165                
 166 kumpf    1.48  #if defined(PEGASUS_OS_HPUX)
 167                static const char OPTION_BINDVERBOSE = 'X';
 168                #endif
 169                
 170 kumpf    1.54  static const String PROPERTY_TIMEOUT = "shutdownTimeout";
 171 mike     1.35  
 172                ConfigManager*    configManager;
 173                
 174 s.hills  1.117 /** Helper for platform specific handling. So platform specific code
 175                    can use our single instance of CIMServer.
 176                */
 177                class CimserverHolder
 178                {
 179                public:
 180                	CimserverHolder( CIMServer* s )
 181                	{
 182                		cimserver_set( s );
 183                	}
 184                	virtual ~CimserverHolder()
 185                	{
 186                		cimserver_set( 0 );
 187                	}
 188                };
 189                
 190 mike     1.32  /** GetOptions function - This function defines the Options Table
 191 mike     1.35      and sets up the options from that table using the config manager.
 192 mike     1.32  */
 193                void GetOptions(
 194 mike     1.35      ConfigManager* cm,
 195 mike     1.32      int& argc,
 196 s.hills  1.117     char** argv)
 197 mike     1.32  {
 198 mike     1.35      try
 199 mike     1.32      {
 200 kumpf    1.38          cm->mergeConfigFiles();
 201 mike     1.33  
 202 mike     1.35          cm->mergeCommandLine(argc, argv);
 203                    }
 204 kumpf    1.122     catch (NoSuchFile&)
 205 mike     1.35      {
 206 kumpf    1.122         throw;
 207 mike     1.35      }
 208 kumpf    1.122     catch (FileNotReadable&)
 209 mike     1.35      {
 210 kumpf    1.122         throw;
 211 mike     1.35      }
 212 kumpf    1.122     catch (CannotRenameFile&)
 213 mike     1.35      {
 214 kumpf    1.122         throw;
 215 mike     1.35      }
 216 kumpf    1.122     catch (ConfigFileSyntaxError&)
 217 mike     1.35      {
 218 kumpf    1.122         throw;
 219 mike     1.35      }
 220 kumpf    1.122     catch(UnrecognizedConfigProperty&)
 221 mike     1.35      {
 222 kumpf    1.122         throw;
 223 mike     1.35      }
 224 kumpf    1.122     catch(InvalidPropertyValue&)
 225 mike     1.35      {
 226 kumpf    1.122         throw;
 227 mike     1.35      }
 228 kumpf    1.123     catch (CannotOpenFile&)
 229                    {
 230                        throw;
 231                    }
 232 mike     1.32  }
 233                
 234                /* PrintHelp - This is temporary until we expand the options manager to allow
 235                   options help to be defined with the OptionRow entries and presented from
 236                   those entries.
 237                */
 238                void PrintHelp(const char* arg0)
 239                {
 240 mike     1.35      String usage = String (USAGE);
 241                    usage.append (COMMAND_NAME);
 242                    usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
 243                    usage.append ("  options\n");
 244 a.arora  1.142     usage.append ("    -v, --version   - displays CIM Server version number\n");
 245                    usage.append ("    -h, --help      - prints this help message\n");
 246 humberto 1.97      usage.append ("    -s              - shuts down CIM Server\n");
 247 kumpf    1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
 248                    usage.append ("    -D [home]       - sets pegasus home directory\n");
 249 humberto 1.97  #endif
 250                #if defined(PEGASUS_OS_TYPE_WINDOWS)
 251                    usage.append ("    -install [name] - installs pegasus as a Windows NT Service\n");
 252                    usage.append ("                      [name] is optional and overrides the\n");
 253                    usage.append ("                      default CIM Server Service Name\n");
 254                    usage.append ("    -remove [name]  - removes pegasus as a Windows NT Service\n");
 255                    usage.append ("                      [name] is optional and overrides the\n");
 256                    usage.append ("                      default CIM Server Service Name\n");
 257                    usage.append ("    -start [name]   - starts pegasus as a Windows NT Service\n");
 258                    usage.append ("                      [name] is optional and overrides the\n");
 259                    usage.append ("                      default CIM Server Service Name\n");
 260                    usage.append ("    -stop [name]    - stops pegasus as a Windows NT Service\n");
 261                    usage.append ("                      [name] is optional and overrides the\n");
 262                    usage.append ("                      default CIM Server Service Name\n\n");
 263                #endif
 264                    usage.append ("  configProperty=value\n");
 265                    usage.append ("                    - sets CIM Server configuration property\n");
 266                
 267                    cout << endl;
 268                #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 269                    cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
 270 humberto 1.97  #else
 271                    cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
 272                #endif
 273                    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                #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 588                                cout << PLATFORM_PRODUCT_VERSION << endl;
 589                #else
 590                                cout << PEGASUS_VERSION << endl;
 591                #endif
 592                                exit(0);
 593                            }
 594 mike     1.35              // Check for -option
 595 a.arora  1.142             else if (*arg == '-')
 596 mike     1.35              {
 597                                // Get the option
 598                                const char* option = arg + 1;
 599                
 600                                //
 601                                // Check to see if user asked for the version (-v option):
 602                                //
 603 tony     1.83                  if (*option == OPTION_VERSION &&
 604                                    strlen(option) == 1)
 605 mike     1.35                  {
 606 kumpf    1.80  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
 607 kumpf    1.63                      cout << PLATFORM_PRODUCT_VERSION << endl;
 608                #else
 609 mike     1.35                      cout << PEGASUS_VERSION << endl;
 610 kumpf    1.63  #endif
 611 mike     1.35                      exit(0);
 612                                }
 613                                //
 614                                // Check to see if user asked for help (-h option):
 615                                //
 616 tony     1.83                  else if (*option == OPTION_HELP &&
 617                                        (strlen(option) == 1))
 618 mike     1.35                  {
 619                                    PrintHelp(argv[0]);
 620                                    exit(0);
 621                                }
 622 kumpf    1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
 623 tony     1.83                  else if (*option == OPTION_HOME &&
 624                                        (strlen(option) == 1))
 625 mike     1.35                  {
 626 kumpf    1.60                      if (i + 1 < argc)
 627 mike     1.35                      {
 628                                        pegasusHome.assign(argv[i + 1]);
 629                                    }
 630                                    else
 631                                    {
 632 humberto 1.97                          //l10n
 633                                        //cout << "Missing argument for option -" << option << endl;
 634 humberto 1.99                          String opt(option);
 635 humberto 1.97                          MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
 636                                						 "Missing argument for option -$0",
 637 humberto 1.99                  						 opt);
 638 humberto 1.97                  		cout << MessageLoader::getMessage(parms) << endl;
 639 mike     1.35                          exit(0);
 640                                    }
 641                
 642                                    memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 643                                    argc -= 2;
 644                                }
 645 kumpf    1.63  #endif
 646 kumpf    1.48  #if defined(PEGASUS_OS_HPUX)
 647                                //
 648 kumpf    1.49                  // Check to see if user asked for the version (-X option):
 649 kumpf    1.48                  //
 650 tony     1.83                  if (*option == OPTION_BINDVERBOSE &&
 651                                        (strlen(option) == 1))
 652 kumpf    1.48                  {
 653                		    System::bindVerbose = true;
 654 humberto 1.97                      //l10n
 655                                    //cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
 656                                         //<< endl;
 657                                    MessageLoaderParms parms("src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
 658                                						 "Unsupported debug option, BIND_VERBOSE, enabled.");
 659                                	cout << MessageLoader::getMessage(parms) << endl;
 660 kumpf    1.48                      // remove the option from the command line
 661                                    memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 662                                    argc--;   
 663                                }
 664                #endif
 665 mike     1.35                  //
 666                                // Check to see if user asked for shutdown (-s option):
 667                                //
 668 tony     1.82                  else if (*option == OPTION_SHUTDOWN &&
 669                                        (strlen(option) == 1))
 670 mike     1.35                  {
 671                                    //
 672 kumpf    1.52                      // Check to see if shutdown has already been specified:
 673 mike     1.35                      //
 674 kumpf    1.52                      if (shutdownOption)
 675 mike     1.35                      {
 676 humberto 1.97                          //l10n
 677                                        //cout << "Duplicate shutdown option specified." << endl;
 678                                        MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
 679                                        						 "Duplicate shutdown option specified.");
 680                                       
 681                                        cout << MessageLoader::getMessage(parms) << endl;
 682 mike     1.35                          exit(0);
 683                                    }
 684                
 685 kumpf    1.52                      shutdownOption = true;
 686 mike     1.35   
 687                                    // remove the option from the command line
 688                                    memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 689                                    argc--;   
 690                                }
 691                                else
 692                                    i++;
 693                            }
 694                            else
 695                                i++;
 696 mike     1.32          }
 697 mike     1.35  
 698 kumpf    1.38      //
 699                    // Set the value for pegasusHome property
 700                    //
 701                    ConfigManager::setPegasusHome(pegasusHome);
 702 mike     1.32  
 703 mike     1.35      //
 704 s.hills  1.117     // Do the plaform specific run
 705                    //
 706                
 707                    return platform_run( argc, argv, shutdownOption );
 708                }
 709                
 710                
 711                //
 712                // The main, common, running code
 713                //
 714                // NOTE: Do NOT call exit().  Use return(), otherwise some platforms 
 715                // will fail to shutdown properly/cleanly.
 716                //
 717                // TODO: Current change minimal for platform "service" shutdown bug fixes.  
 718                // Perhpas further extract out common stuff and put into main(), put 
 719                // daemon stuff into platform specific platform_run(), etc.  
 720                // Note: make sure to not put error handling stuff that platform 
 721                // specific runs may need to deal with bettter (instead of exit(), etc).
 722                //
 723                
 724                int cimserver_run( int argc, char** argv, Boolean shutdownOption )
 725 s.hills  1.117 {
 726                    String logsDirectory = String::EMPTY;
 727                    Boolean daemonOption = false;
 728                
 729                    //
 730 mike     1.35      // Get an instance of the Config Manager.
 731                    //
 732                    configManager = ConfigManager::getInstance();
 733 kumpf    1.136     configManager->useConfigFiles = true;
 734 mike     1.35  
 735 lucier   1.130 #ifdef PEGASUS_OS_OS400
 736                    // In a special startup case for IBM OS400, when the server is
 737                    // automatically started when the machine starts up the config
 738                    // file cannot be read because of access restrictions for the
 739                    // user starting the server.  In this case, we need to skip
 740                    // reading the config options and therefore any use of the config
 741                    // manager also.  To make this determinations we will check to see
 742                    // if the daemon flag is set to true.  If so, then there will be a
 743                    // series of checks to bracket all the calls to the configManager
 744                    // which would otherwise fail.  All this will only be done for
 745                    // IBM OS400.
 746                
 747                    Boolean os400StartupOption = false;
 748                    // loop through args to check for daemon=true
 749                    for (int i=1; i < argc; i++)
 750                      if (strcmp(argv[i], "daemon=true") == 0)
 751                      {
 752                        os400StartupOption = true;
 753                        daemonOption = true;
 754                      }
 755                #endif    
 756 lucier   1.130 
 757 mike     1.35      //
 758 mike     1.32      // Get options (from command line and from configuration file); this
 759 mike     1.35      // removes corresponding options and their arguments from the command
 760 mike     1.32      // line.
 761 mike     1.35      //
 762 mike     1.32      try
 763                    {
 764 lucier   1.130 #ifdef PEGASUS_OS_OS400
 765                    if (os400StartupOption == false)
 766                #endif   
 767 s.hills  1.117         GetOptions(configManager, argc, argv);
 768 mike     1.32      }
 769                    catch (Exception& e)
 770                    {
 771 kumpf    1.127         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 772                            "src.Server.cimserver.SERVER_NOT_STARTED",
 773                            "cimserver not started:  $0", e.getMessage());
 774                
 775                #if !defined(PEGASUS_OS_OS400)
 776                        MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 777                            "cimserver not started: $0", e.getMessage());
 778                
 779                        PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
 780                            << PEGASUS_STD(endl);
 781 david    1.85  #endif
 782 kumpf    1.127 
 783 s.hills  1.117         return(1);
 784 mike     1.32      }
 785                
 786 chuck    1.94  // l10n
 787                	// Set the home directory, msg sub-dir, into the MessageLoader.
 788                	// This will be the default directory where the resource bundles 
 789 david    1.133 	// are found.    
 790                	MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
 791                		ConfigManager::getInstance()->getCurrentValue("messageDir")));		
 792 chuck    1.94  
 793 lucier   1.130 #ifdef PEGASUS_OS_OS400
 794                    // Still need to declare and set the connection variables.
 795                    // Will initialize to false since they are fixed at false for OS400.
 796                
 797                    // NOTE:  OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down
 798                    // the test will not be compiled in.  If OS400 ever turns off that
 799                    // define, then we will need to change this code path to insure that
 800                    // one of the variables is true.    
 801                    Boolean enableHttpConnection = false;
 802                    Boolean enableHttpsConnection = false;
 803 kumpf    1.135     Boolean enableSSLExportClientVerification = false;
 804 lucier   1.130 
 805                    if (os400StartupOption == false)
 806                    {
 807                      enableHttpConnection = String::equal(
 808                          configManager->getCurrentValue("enableHttpConnection"), "true");
 809                      enableHttpsConnection = String::equal(
 810                          configManager->getCurrentValue("enableHttpsConnection"), "true");
 811 kumpf    1.135       enableSSLExportClientVerification = String::equal(
 812                          configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
 813 lucier   1.130     }
 814                #else
 815 kumpf    1.87      Boolean enableHttpConnection = String::equal(
 816                        configManager->getCurrentValue("enableHttpConnection"), "true");
 817                    Boolean enableHttpsConnection = String::equal(
 818                        configManager->getCurrentValue("enableHttpsConnection"), "true");
 819 kumpf    1.135     Boolean enableSSLExportClientVerification = String::equal(
 820                        configManager->getCurrentValue("enableSSLExportClientVerification"), "true");
 821 lucier   1.130 #endif
 822 kumpf    1.86  
 823                    // Make sure at least one connection is enabled
 824                #ifndef PEGASUS_LOCAL_DOMAIN_SOCKET
 825                    if (!enableHttpConnection && !enableHttpsConnection)
 826                    {
 827 humberto 1.97          //l10n
 828                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 829                            //"Neither HTTP nor HTTPS connection is enabled.  "
 830                            //"CIMServer will not be started.");
 831                        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 832                        	"src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 833                            "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 834                        //cerr << "Neither HTTP nor HTTPS connection is enabled.  "
 835                            //"CIMServer will not be started." << endl;
 836                        MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 837                        						 "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 838                        cerr << MessageLoader::getMessage(parms) << endl;
 839 s.hills  1.117         return(1);
 840 kumpf    1.86      }
 841                #endif
 842                
 843 mike     1.35      try
 844 mike     1.32      {
 845 mike     1.35          //
 846                        // Check to see if we should Pegasus as a daemon
 847                        //
 848                
 849                        if (String::equal(configManager->getCurrentValue("daemon"), "true"))
 850                        {
 851                            daemonOption = true;
 852                        }
 853 mday     1.62  	
 854 lucier   1.130 #ifdef PEGASUS_OS_OS400
 855                    if (os400StartupOption == false)
 856                    {
 857                #endif            
 858 kumpf    1.36          // Get the log file directory definition.
 859                        // We put String into Cstring because
 860                        // Directory functions only handle Cstring.
 861                        // ATTN-KS: create String based directory functions.
 862                
 863                        logsDirectory = configManager->getCurrentValue("logdir");
 864 kumpf    1.38          logsDirectory = 
 865                	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
 866 lucier   1.130 #ifdef PEGASUS_OS_OS400
 867                    }  // end if (os400StartupOption == false)
 868                #endif
 869 kumpf    1.36  
 870                        // Set up the Logger. This does not open the logs
 871                        // Might be more logical to clean before set.
 872                        // ATTN: Need tool to completely disable logging.
 873                
 874 david    1.85  #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 875                !defined(PEGASUS_OS_OS400)
 876 kumpf    1.36          Logger::setHomeDirectory(logsDirectory);
 877 kumpf    1.57  #endif
 878 kumpf    1.36  
 879                        //
 880 mike     1.35          // Check to see if we need to shutdown CIMOM 
 881                        //
 882                        if (shutdownOption)
 883                        {
 884 kumpf    1.60              String configTimeout = 
 885                                configManager->getCurrentValue("shutdownTimeout");
 886 s.hills  1.117             Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
 887 kumpf    1.60              
 888 kumpf    1.52              shutdownCIMOM(timeoutValue);
 889 kumpf    1.45  
 890 david    1.85  #ifdef PEGASUS_OS_OS400
 891 humberto 1.97  	    //l10n
 892                	    //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 893                			//"CIM Server stopped.");  
 894                		Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 895                			"src.Server.cimserver.SERVER_STOPPED",
 896 humberto 1.103 			"CIM Server stopped.");
 897 s.hills  1.117             cimserver_exitRC(0);
 898 david    1.85  #else
 899 humberto 1.97  			//l10n
 900                            //cout << "CIM Server stopped." << endl;
 901                            MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",
 902 humberto 1.106             						 "CIM Server stopped.");
 903                
 904 humberto 1.97              cout << MessageLoader::getMessage(parms) << endl;
 905 s.hills  1.117             return(0);
 906 diane    1.81  #endif
 907 mike     1.35          }
 908 mike     1.32  
 909 kumpf    1.139 #if defined(PEGASUS_DEBUG)
 910 kumpf    1.36          // Leave this in until people get familiar with the logs.
 911 humberto 1.97          //l10n
 912                        //cout << "Logs Directory = " << logsDirectory << endl;
 913                        MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
 914                            				     "Logs Directory = ");
 915                        cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
 916 kumpf    1.57  #endif
 917 mike     1.32      }
 918 kumpf    1.122     catch (UnrecognizedConfigProperty& e)
 919 mike     1.32      {
 920 david    1.85  
 921                #ifdef PEGASUS_OS_OS400
 922 humberto 1.97  	//l10n
 923                	//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 924                		    //"Error: $0",e.getMessage());  
 925                	Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 926                			"src.Server.cimserver.ERROR",
 927                		    "Error: $0",e.getMessage()); 
 928 david    1.85  #else
 929 humberto 1.97  	//l10n
 930                	//cout << "Error: " << e.getMessage() << endl;
 931                	MessageLoaderParms parms("src.Server.cimserver.ERROR",
 932                							 "Error: $0",
 933                							 e.getMessage());
 934                	cout << MessageLoader::getMessage(parms) << endl;
 935 david    1.85  #endif
 936 mike     1.32      }
 937                
 938 kumpf    1.86      Uint32 portNumberHttps;
 939                    Uint32 portNumberHttp;
 940 kumpf    1.135     Uint32 portNumberExportHttps;
 941 kumpf    1.53  
 942 kumpf    1.86      if (enableHttpsConnection)
 943 kumpf    1.53      {
 944 kumpf    1.86          String httpsPort = configManager->getCurrentValue("httpsPort");
 945 kumpf    1.69          CString portString = httpsPort.getCString();
 946 kumpf    1.86          char* end = 0;
 947                        Uint32 port = strtol(portString, &end, 10);
 948                        assert(end != 0 && *end == '\0');
 949 kumpf    1.53  
 950                        //
 951 kumpf    1.86          // Look up the WBEM-HTTPS port number
 952 kumpf    1.53          //
 953 kumpf    1.86          portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
 954 kumpf    1.53      }
 955 kumpf    1.86  
 956                    if (enableHttpConnection)
 957 kumpf    1.53      {
 958 kumpf    1.86          String httpPort = configManager->getCurrentValue("httpPort");
 959 kumpf    1.69          CString portString = httpPort.getCString();
 960 kumpf    1.86          char* end = 0;
 961                        Uint32 port = strtol(portString, &end, 10);
 962                        assert(end != 0 && *end == '\0');
 963 kumpf    1.53  
 964                        //
 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.86      cout << PEGASUS_NAME << PEGASUS_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 dj.gorey 1.131 #if defined(PEGASUS_USE_23HTTPMONITOR_SERVER) 
1113 dj.gorey 1.129 	Monitor monitor(true);
1114 mday     1.114 	CIMServer server(&monitor);
1115 david    1.110 #else
1116 dj.gorey 1.129 	monitor_2 monitor;
1117 mday     1.112 	CIMServer server(&monitor);
1118 david    1.110 #endif
1119 mday     1.111 
1120 s.hills  1.117 	CimserverHolder cimserverHolder( &server );
1121 kumpf    1.41  
1122 kumpf    1.86          if (enableHttpConnection)
1123                        {
1124 kumpf    1.135             server.addAcceptor(false, portNumberHttp, false, false);
1125 humberto 1.97              //l10n
1126                            //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1127                                        //"Listening on HTTP port $0.", portNumberHttp);
1128                                        
1129                            Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1130 humberto 1.103             				"src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1131                                        	"Listening on HTTP port $0.", portNumberHttp);
1132 kumpf    1.86          }
1133                        if (enableHttpsConnection)
1134                        {
1135 kumpf    1.135             server.addAcceptor(false, portNumberHttps, true, false);
1136 humberto 1.97              //l10n
1137                            //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1138                                        //"Listening on HTTPS port $0.", portNumberHttps);
1139                            Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1140 humberto 1.103             				"src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1141                                        	"Listening on HTTPS port $0.", portNumberHttps);
1142 kumpf    1.86          }
1143 kumpf    1.135         if (enableSSLExportClientVerification)
1144                        {
1145                            server.addAcceptor(false, portNumberExportHttps, true, true);
1146                
1147                            Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1148                                "src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1149                                "Listening on Export HTTPS port $0.", portNumberExportHttps);
1150                        }
1151                
1152 kumpf    1.41  #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
1153 kumpf    1.135         server.addAcceptor(true, 0, false, false);
1154 humberto 1.97          //l10n
1155                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1156                                    //"Listening on local connection socket.");
1157                        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1158 humberto 1.103 		      "src.Server.cimserver.LISTENING_ON_LOCAL",
1159                		      "Listening on local connection socket.");
1160 kumpf    1.41  #endif
1161 kumpf    1.86  
1162 kumpf    1.139 #if defined(PEGASUS_DEBUG)
1163 kumpf    1.86          if (enableHttpConnection)
1164                        {
1165 humberto 1.97              //l10n
1166                            //cout << "Listening on HTTP port " << portNumberHttp << endl;
1167 humberto 1.103 	  MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1168                				   "Listening on HTTP port $0.", portNumberHttp);
1169 humberto 1.97             	cout << MessageLoader::getMessage(parms) << endl;
1170 kumpf    1.86          }
1171                        if (enableHttpsConnection)
1172                        {
1173 humberto 1.97              //l10n
1174                            //cout << "Listening on HTTPS port " << portNumberHttps << endl;
1175 humberto 1.103             MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1176                				     "Listening on HTTPS port $0.", portNumberHttps);
1177 humberto 1.97             	cout << MessageLoader::getMessage(parms) << endl;
1178 kumpf    1.86          }
1179 kumpf    1.135         if (enableSSLExportClientVerification)
1180                        {
1181                            MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_EXPORT_HTTPS_PORT",
1182                                "Listening on Export HTTPS port $0.", portNumberExportHttps);
1183                
1184                            cout << MessageLoader::getMessage(parms) << endl;
1185                        }
1186                
1187 kumpf    1.86  # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
1188 humberto 1.97          //l10n
1189                        //cout << "Listening on local connection socket" << endl;
1190                        MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",
1191 humberto 1.103 				 "Listening on local connection socket.");
1192 humberto 1.97          cout << MessageLoader::getMessage(parms) << endl;
1193 kumpf    1.86  # endif
1194 david    1.85  #endif
1195 mike     1.35  
1196 kumpf    1.86          // bind throws an exception if the bind fails
1197                        server.bind();
1198 kumpf    1.73  
1199 dan      1.76  	// notify parent process (if there is a parent process) to terminate 
1200 konrad.r 1.95          // so user knows that there is cimserver ready to serve CIM requests.
1201 dan      1.76  	if (daemonOption)
1202 konrad.r 1.95  		notify_parent(0);
1203 mike     1.32  
1204                	time_t last = 0;
1205 mike     1.35  
1206 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)
1207 kumpf    1.45          //
1208 kumpf    1.56          // create a file to indicate that the cimserver has started and
1209                        // save the process id of the cimserver process in the file
1210 kumpf    1.45          //
1211 kumpf    1.56          // remove the old file if it exists
1212 kumpf    1.91          System::removeFile(CIMSERVER_START_FILE);
1213 kumpf    1.56  
1214                        // open the file
1215 kumpf    1.91          FILE *pid_file = fopen(CIMSERVER_START_FILE, "w");
1216                
1217 kumpf    1.56          if (pid_file)
1218 kumpf    1.45          {
1219 kumpf    1.56              // save the pid in the file
1220                            fprintf(pid_file, "%ld\n", (long)server_pid);
1221                            fclose(pid_file);
1222 kumpf    1.45          }
1223                #endif
1224 kumpf    1.91  
1225 kumpf    1.139 #if defined(PEGASUS_DEBUG)
1226 kumpf    1.54  	cout << "Started. " << endl;
1227 kumpf    1.63  #endif
1228 mday     1.116 	
1229 kumpf    1.54          // Put server started message to the logger
1230 kumpf    1.80  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
1231 humberto 1.97          //l10n
1232                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1233                                    //"Started $0 version $1.",
1234                                    //PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
1235                        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1236                        			"src.Server.cimserver.STARTED_VERSION",
1237 kumpf    1.86                      "Started $0 version $1.",
1238                                    PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
1239 kumpf    1.63  #else
1240 humberto 1.97  		//l10n
1241                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1242                                    //"Started $0 version $1.",
1243                                    //PEGASUS_NAME, PEGASUS_VERSION);
1244                        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1245                        			"src.Server.cimserver.STARTED_VERSION",
1246 kumpf    1.86                      "Started $0 version $1.",
1247                                    PEGASUS_NAME, PEGASUS_VERSION);
1248 kumpf    1.63  #endif
1249 kumpf    1.45  
1250 mday     1.62  	
1251 mike     1.35          //
1252                        // Loop to call CIMServer's runForever() method until CIMServer
1253                        // has been shutdown
1254                        //
1255                	while( !server.terminated() )
1256 mike     1.32  	{
1257 mday     1.116 
1258 mike     1.32  	  server.runForever();
1259 mday     1.112 
1260 mike     1.32  	}
1261 mday     1.112 	MessageQueueService::force_shutdown(true);
1262 kumpf    1.45          //
1263                        // normal termination
1264 mike     1.34  	//
1265 kumpf    1.54          // Put server shutdown message to the logger
1266 kumpf    1.86  #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
1267 humberto 1.97          //l10n
1268                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1269                            //"$0 stopped.", PLATFORM_PRODUCT_NAME);
1270                        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1271                        	"src.Server.cimserver.STOPPED",
1272 kumpf    1.86              "$0 stopped.", PLATFORM_PRODUCT_NAME);
1273                #else
1274 humberto 1.97  		//l10n
1275                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1276                            //"$0 stopped.", PEGASUS_NAME);
1277                        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1278                        	"src.Server.cimserver.STOPPED",
1279 kumpf    1.54              "$0 stopped.", PEGASUS_NAME);
1280 kumpf    1.86  #endif
1281 kumpf    1.45  
1282 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)
1283 kumpf    1.45          //
1284 kumpf    1.56          // close the file created at startup time to indicate that the 
1285                        // cimserver has terminated normally.
1286 kumpf    1.45          //
1287 kumpf    1.91          FileSystem::removeFile(CIMSERVER_START_FILE);
1288 kumpf    1.45  #endif
1289 mike     1.32      }
1290                    catch(Exception& e)
1291                    {
1292 david    1.100 
1293 humberto 1.97  	//l10n
1294                	//Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1295                		    //"Error: $0", e.getMessage()); 
1296                	Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1297                			"src.Server.cimserver.ERROR",
1298                		    "Error: $0", e.getMessage());  
1299 konrad.r 1.95  
1300                #ifndef PEGASUS_OS_OS400
1301 humberto 1.97  	//l10n
1302                	//PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1303                	MessageLoaderParms parms("src.Server.cimserver.ERROR",
1304                							 "Error: $0", e.getMessage());
1305                	PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1306 david    1.100 
1307 david    1.85  #endif
1308 kumpf    1.77  
1309                	//
1310                        // notify parent process (if there is a parent process) to terminate
1311                        //
1312                        if (daemonOption)
1313 konrad.r 1.95                  notify_parent(1);
1314 kumpf    1.77  
1315 kumpf    1.54          return 1;
1316 mike     1.32      }
1317                
1318                    return 0;
1319                }
1320 tony     1.128 
1321                
1322                
1323                

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2