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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2