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

   1 karl  1.179 //%2006////////////////////////////////////////////////////////////////////////
   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 karl  1.149 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  10             // EMC Corporation; VERITAS Software Corporation; The Open Group.
  11 karl  1.179 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  12             // EMC Corporation; Symantec Corporation; The Open Group.
  13 mike  1.32  //
  14             // Permission is hereby granted, free of charge, to any person obtaining a copy
  15 kumpf 1.58  // 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 mike  1.32  // 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 karl  1.179 // 
  21 kumpf 1.58  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  22 mike  1.32  // 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 kumpf 1.58  // 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 mike  1.32  // 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             
  35             //////////////////////////////////////////////////////////////////////
  36             //
  37 carolann.graves 1.171 // Notes on daemon operation (Unix) and service operation (Win 32):
  38 mike            1.32  //
  39 david.dillard   1.165 // To run pegasus as a daemon on Unix platforms:
  40 mike            1.32  //
  41 kumpf           1.60  // cimserver
  42 mike            1.32  //
  43 kumpf           1.60  // 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 david.dillard   1.165 // The daemon config property has no effect on windows operation.
  49 mike            1.32  //
  50 mike            1.35  // To shutdown pegasus, use the -s option:
  51 david.dillard   1.165 //
  52                       // cimserver -s
  53 mike            1.35  //
  54 mike            1.32  // To run pegasus as an NT service, there are FOUR  different possibilities:
  55                       //
  56 david.dillard   1.165 // To INSTALL the Pegasus service,
  57 mike            1.32  //
  58                       // cimserver -install
  59                       //
  60 david.dillard   1.165 // To REMOVE the Pegasus service,
  61 mike            1.32  //
  62                       // cimserver -remove
  63                       //
  64 david.dillard   1.165 // To START the Pegasus service,
  65 mike            1.32  //
  66                       // net start cimserver
  67 s.hills         1.117 // or
  68                       // cimserver -start
  69 mike            1.32  //
  70 david.dillard   1.165 // To STOP the Pegasus service,
  71 mike            1.32  //
  72                       // net stop cimserver
  73 s.hills         1.117 // or
  74                       // cimserver -stop
  75 mike            1.32  //
  76 david.dillard   1.165 // Alternatively, you can use the windows service manager. Pegasus shows up
  77 mike            1.32  // in the service database as "Pegasus CIM Object Manager"
  78                       //
  79                       //////////////////////////////////////////////////////////////////////
  80                       
  81                       
  82 mike            1.35  #include <Pegasus/Common/Config.h>
  83 kumpf           1.59  #include <Pegasus/Common/Constants.h>
  84 jim.wunderlich  1.172 #include <Pegasus/Common/PegasusAssert.h>
  85 mike            1.32  #include <Pegasus/Common/FileSystem.h>
  86 mike            1.35  #include <Pegasus/Common/Monitor.h>
  87 mike            1.32  #include <Pegasus/Common/PegasusVersion.h>
  88                       #include <Pegasus/Common/Logger.h>
  89                       #include <Pegasus/Common/System.h>
  90 mike            1.35  #include <Pegasus/Common/Tracer.h>
  91 kumpf           1.174 #include <Pegasus/Common/LanguageParser.h>
  92 mike            1.35  #include <Pegasus/Config/ConfigManager.h>
  93                       #include <Pegasus/Client/CIMClient.h>
  94 h.sterling      1.153 #include <Pegasus/Server/CIMServer.h>
  95                       #include <Service/ServerProcess.h>
  96 kumpf           1.198 #include <Service/ServerShutdownClient.h>
  97                       #include <Service/ServerRunStatus.h>
  98 mike            1.32  
  99 chuck           1.155 #if defined(PEGASUS_OS_OS400)
 100                       #  include "vfyptrs.cinc"
 101                       #  include "OS400ConvertChar.h"
 102                       #endif
 103                       
 104 thilo.boehm     1.185 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) 
 105                       #include <Service/ARM_zOS.h>
 106 marek           1.186 # ifdef PEGASUS_ZOS_SECURITY
 107                       // This include file will not be provided in the OpenGroup CVS for now.
 108                       // Do NOT try to include it in your compile
 109                       #  include <Pegasus/Common/safCheckzOS_inline.h>
 110                       # endif
 111 thilo.boehm     1.185 #endif
 112                       
 113 kumpf           1.178 #if defined(PEGASUS_OS_TYPE_UNIX)
 114                       # if defined(PEGASUS_OS_OS400)
 115 mateus.baur     1.175 #  include <unistd.cleinc>
 116 kumpf           1.178 # else
 117 mateus.baur     1.175 #  include <unistd.h>
 118 kumpf           1.178 # endif
 119                       # include <sys/types.h>
 120                       # include <sys/stat.h>
 121                       # include <fcntl.h>
 122 mateus.baur     1.175 #endif
 123                       
 124 kumpf           1.119 PEGASUS_USING_PEGASUS;
 125                       PEGASUS_USING_STD;
 126                       
 127 kumpf           1.198 #define PEGASUS_PROCESS_NAME "cimserver"
 128 mike            1.32  
 129 h.sterling      1.153 //Windows service variables are not defined elsewhere in the product
 130                       //enable ability to override these
 131                       #ifndef PEGASUS_SERVICE_NAME
 132                       #define PEGASUS_SERVICE_NAME "Pegasus CIM Object Manager";
 133 chuck           1.66  #endif
 134 h.sterling      1.153 #ifndef PEGASUS_SERVICE_DESCRIPTION
 135                       #define PEGASUS_SERVICE_DESCRIPTION "Pegasus CIM Object Manager Service";
 136 mike            1.32  #endif
 137                       
 138 h.sterling      1.153 class CIMServerProcess : public ServerProcess
 139                       {
 140                       public:
 141                       
 142                           CIMServerProcess(void)
 143                           {
 144                               cimserver_set_process(this);
 145                           }
 146                       
 147                           virtual ~CIMServerProcess(void)
 148                           {
 149                           }
 150                       
 151                           //defined in PegasusVersion.h
 152                           virtual const char* getProductName() const
 153                           {
 154                               return PEGASUS_PRODUCT_NAME;
 155                           }
 156                       
 157                           virtual const char* getExtendedName() const
 158                           {
 159 h.sterling      1.153         return PEGASUS_SERVICE_NAME;
 160                           }
 161                       
 162                           virtual const char* getDescription() const
 163                           {
 164                               return PEGASUS_SERVICE_DESCRIPTION;
 165                           }
 166 david.dillard   1.165 
 167 h.sterling      1.153     //defined in PegasusVersion.h
 168 jim.wunderlich  1.180     virtual const char* getCompleteVersion() const
 169                           {
 170 jim.wunderlich  1.181       if (*PEGASUS_PRODUCT_STATUS == '\0' )
 171 jim.wunderlich  1.180 	return PEGASUS_PRODUCT_VERSION;
 172                             else
 173                       	return PEGASUS_PRODUCT_VERSION " " PEGASUS_PRODUCT_STATUS;      
 174                           }
 175                       
 176                           //defined in PegasusVersion.h
 177 h.sterling      1.153     virtual const char* getVersion() const
 178                           {
 179                               return PEGASUS_PRODUCT_VERSION;
 180                           }
 181                       
 182                           virtual const char* getProcessName() const
 183                           {
 184                               return PEGASUS_PROCESS_NAME;
 185                           }
 186                       
 187 kumpf           1.184     //defined in Constants.h
 188 h.sterling      1.153     virtual const char* getPIDFileName() const
 189                           {
 190 kumpf           1.184         return PEGASUS_CIMSERVER_START_FILE;
 191 h.sterling      1.153     }
 192                       
 193 kumpf           1.178     int cimserver_run(
 194                               int argc,
 195                               char** argv,
 196                               Boolean shutdownOption,
 197                               Boolean debugOutputOption);
 198 h.sterling      1.153 
 199                           void cimserver_stop(void);
 200                       };
 201                       
 202 kumpf           1.198 ServerRunStatus _serverRunStatus(
 203                           PEGASUS_PROCESS_NAME, PEGASUS_CIMSERVER_START_FILE);
 204 h.sterling      1.153 AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
 205                       static CIMServer* _cimServer = 0;
 206 konrad.r        1.163 static Monitor* _monitor = 0;
 207 konrad.r        1.166 static Thread* dummyInitialThread = 0;
 208 mike            1.35  //
 209                       //  The command name.
 210                       //
 211                       static const char COMMAND_NAME []    = "cimserver";
 212                       
 213                       //
 214                       //  The constant defining usage string.
 215                       //
 216                       static const char USAGE []           = "Usage: ";
 217                       
 218                       /**
 219                       Constants representing the command line options.
 220                       */
 221                       static const char OPTION_VERSION     = 'v';
 222                       
 223                       static const char OPTION_HELP        = 'h';
 224                       
 225                       static const char OPTION_HOME        = 'D';
 226                       
 227                       static const char OPTION_SHUTDOWN    = 's';
 228                       
 229 a.arora         1.142 static const char   LONG_HELP []  = "help";
 230                       
 231                       static const char   LONG_VERSION []  = "version";
 232                       
 233 kumpf           1.178 static const char OPTION_DEBUGOUTPUT = 'X';
 234 kumpf           1.48  
 235 kumpf           1.54  static const String PROPERTY_TIMEOUT = "shutdownTimeout";
 236 mike            1.35  
 237                       ConfigManager*    configManager;
 238                       
 239 mike            1.32  /** GetOptions function - This function defines the Options Table
 240 mike            1.35      and sets up the options from that table using the config manager.
 241 kumpf           1.198 
 242                           Some possible exceptions:  NoSuchFile, FileNotReadable, CannotRenameFile,
 243                           ConfigFileSyntaxError, UnrecognizedConfigProperty, InvalidPropertyValue,
 244                           CannotOpenFile.
 245 mike            1.32  */
 246                       void GetOptions(
 247 mike            1.35      ConfigManager* cm,
 248 mike            1.32      int& argc,
 249 mateus.baur     1.193     char** argv,
 250 kumpf           1.198     Boolean shutdownOption)
 251 mike            1.32  {
 252 kumpf           1.198     if (shutdownOption)
 253                           {
 254                               cm->loadConfigFiles();
 255                           }
 256                           else
 257 mike            1.32      {
 258 kumpf           1.198         cm->mergeConfigFiles();
 259                           }
 260 mateus.baur     1.193 
 261 kumpf           1.198     // Temporarily disable updates to the current configuration
 262                           // file if shutdownOption is true
 263                           cm->useConfigFiles = (shutdownOption==false);
 264 mike            1.33  
 265 kumpf           1.198     cm->mergeCommandLine(argc, argv);
 266 mateus.baur     1.193 
 267 kumpf           1.198     // Enable updates again
 268                           cm->useConfigFiles = true;
 269 mike            1.32  }
 270                       
 271                       /* PrintHelp - This is temporary until we expand the options manager to allow
 272                          options help to be defined with the OptionRow entries and presented from
 273                          those entries.
 274                       */
 275                       void PrintHelp(const char* arg0)
 276                       {
 277 mike            1.35      String usage = String (USAGE);
 278                           usage.append (COMMAND_NAME);
 279                           usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
 280                           usage.append ("  options\n");
 281 a.arora         1.142     usage.append ("    -v, --version   - displays CIM Server version number\n");
 282                           usage.append ("    -h, --help      - prints this help message\n");
 283 humberto        1.97      usage.append ("    -s              - shuts down CIM Server\n");
 284 kumpf           1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
 285                           usage.append ("    -D [home]       - sets pegasus home directory\n");
 286 humberto        1.97  #endif
 287                       #if defined(PEGASUS_OS_TYPE_WINDOWS)
 288 joyce.j         1.148     usage.append ("    -install [name] - installs pegasus as a Windows Service\n");
 289 humberto        1.97      usage.append ("                      [name] is optional and overrides the\n");
 290                           usage.append ("                      default CIM Server Service Name\n");
 291 aruran.ms       1.183     usage.append ("                      by appending [name]\n");
 292 joyce.j         1.148     usage.append ("    -remove [name]  - removes pegasus as a Windows Service\n");
 293 humberto        1.97      usage.append ("                      [name] is optional and overrides the\n");
 294                           usage.append ("                      default CIM Server Service Name\n");
 295 aruran.ms       1.183     usage.append ("                      by appending [name]\n");
 296 joyce.j         1.148     usage.append ("    -start [name]   - starts pegasus as a Windows Service\n");
 297 humberto        1.97      usage.append ("                      [name] is optional and overrides the\n");
 298                           usage.append ("                      default CIM Server Service Name\n");
 299 aruran.ms       1.183     usage.append ("                      by appending [name]\n");
 300 joyce.j         1.148     usage.append ("    -stop [name]    - stops pegasus as a Windows Service\n");
 301 humberto        1.97      usage.append ("                      [name] is optional and overrides the\n");
 302 aruran.ms       1.183     usage.append ("                      default CIM Server Service Name\n");
 303                           usage.append ("                      by appending [name]\n\n");
 304 humberto        1.97  #endif
 305                           usage.append ("  configProperty=value\n");
 306                           usage.append ("                    - sets CIM Server configuration property\n");
 307                       
 308                           cout << endl;
 309 jim.wunderlich  1.180     cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getCompleteVersion() << endl;
 310 humberto        1.97      cout << endl;
 311 david.dillard   1.165 
 312 humberto        1.97  #if defined(PEGASUS_OS_TYPE_WINDOWS)
 313 humberto        1.104     MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
 314 kumpf           1.152 #elif defined(PEGASUS_USE_RELEASE_DIRS)
 315 kumpf           1.138     MessageLoaderParms parms("src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);
 316 humberto        1.97  #else
 317 kumpf           1.138     MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
 318 humberto        1.97  #endif
 319                           cout << MessageLoader::getMessage(parms) << endl;
 320 mike            1.35  }
 321                       
 322 h.sterling      1.156 //This needs to be called at various points in the code depending on the platform and error conditions.
 323                       //We need to delete the _cimServer reference on exit in order for the destructors to get called.
 324                       void deleteCIMServer()
 325                       {
 326                           if (_cimServer)
 327                           {
 328                               delete _cimServer;
 329                               _cimServer = 0;
 330 carolann.graves 1.171 
 331                       #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) \
 332                       || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
 333                       || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS)
 334                               //
 335                               //  Remove the PID file to indicate CIMServer termination
 336                               //
 337                               FileSystem::removeFile(_cimServerProcess->getPIDFileName());
 338                       #endif
 339 h.sterling      1.156     }
 340 kumpf           1.182     delete _monitor;
 341 konrad.r        1.166    if (dummyInitialThread)
 342                          {
 343                       	Thread::clearLanguages();
 344                       	delete dummyInitialThread;
 345                          }
 346 h.sterling      1.156 }
 347                       
 348 chuck           1.96  // l10n
 349                       //
 350                       // Dummy function for the Thread object associated with the initial thread.
 351                       // Since the initial thread is used to process CIM requests, this is
 352                       // needed to localize the exceptions thrown during CIM request processing.
 353 david.dillard   1.165 // Note: This function should never be called!
 354                       //
 355 mike            1.188 ThreadReturnType PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
 356 chuck           1.96  {
 357 mike            1.188    return((ThreadReturnType)0);
 358 chuck           1.96  }
 359                       
 360 mike            1.35  
 361 mike            1.33  /////////////////////////////////////////////////////////////////////////
 362 mike            1.32  //  MAIN
 363                       //////////////////////////////////////////////////////////////////////////
 364                       int main(int argc, char** argv)
 365                       {
 366 kumpf           1.196     String pegasusHome;
 367 mike            1.35      Boolean shutdownOption = false;
 368 kumpf           1.178     Boolean debugOutputOption = false;
 369 mday            1.47  
 370 humberto        1.97  //l10n
 371                       // Set Message loading to process locale
 372 david.dillard   1.165 MessageLoader::_useProcessLocale = true;
 373 humberto        1.97  //l10n
 374                       
 375 kv.le           1.140 //l10n
 376                       #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
 377                       setlocale(LC_ALL, "");
 378                       #endif
 379                       
 380 chuck           1.66  #ifdef PEGASUS_OS_OS400
 381 david           1.120 
 382                         VFYPTRS_INCDCL;               // VFYPTRS local variables
 383                       
 384                         // verify pointers
 385                         #pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\
 386                           0,_C2_MH_ESCAPE)
 387                           for( int arg_index = 1; arg_index < argc; arg_index++ ){
 388 h.sterling      1.153     VFYPTRS(VERIFY_SPP_NULL(argv[arg_index]));
 389 david           1.120     }
 390                         #pragma disable_handler
 391                       
 392 david           1.100     // Convert the args to ASCII
 393                           for(Uint32 i = 0;i< argc;++i)
 394                           {
 395 h.sterling      1.153     EtoA(argv[i]);
 396 david           1.100     }
 397                       
 398 chuck           1.66      // Initialize Pegasus home to the shipped OS/400 directory.
 399                           pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
 400                       #endif
 401                       
 402 kv.le           1.134 
 403 tony            1.82  #ifndef PEGASUS_OS_TYPE_WINDOWS
 404 kumpf           1.38      //
 405                           // Get environment variables:
 406                           //
 407 david           1.100 #ifdef PEGASUS_OS_OS400
 408                       #pragma convert(37)
 409                           const char* tmp = getenv("PEGASUS_HOME");
 410                       #pragma convert(0)
 411                           char home[256] = {0};
 412                           if (tmp && strlen(tmp) < 256)
 413                           {
 414 h.sterling      1.153     strcpy(home, tmp);
 415                           EtoA(home);
 416                           pegasusHome = home;
 417 david           1.100     }
 418                       #else
 419 kv.le           1.134   #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
 420                           pegasusHome = AIX_RELEASE_PEGASUS_HOME;
 421 marek           1.170   #elif !defined(PEGASUS_USE_RELEASE_DIRS) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 422 kumpf           1.38      const char* tmp = getenv("PEGASUS_HOME");
 423                       
 424                           if (tmp)
 425                           {
 426                               pegasusHome = tmp;
 427                           }
 428 kv.le           1.134   #endif
 429 david           1.100 #endif
 430 kumpf           1.38  
 431                           FileSystem::translateSlashes(pegasusHome);
 432 tony            1.82  #else
 433 kumpf           1.38  
 434 tony            1.82    // windows only
 435 h.sterling      1.153   //setHome(pegasusHome);
 436                         pegasusHome = _cimServerProcess->getHome();
 437 tony            1.82  #endif
 438 mike            1.32  
 439 kumpf           1.60          // Get help, version, and shutdown options
 440 mike            1.35  
 441                               for (int i = 1; i < argc; )
 442                               {
 443                                   const char* arg = argv[i];
 444 a.arora         1.142             if(String::equal(arg,"--help"))
 445                                   {
 446                                           PrintHelp(argv[0]);
 447                                           exit(0);
 448                                   }
 449                                   else if(String::equal(arg,"--version"))
 450                                   {
 451 jim.wunderlich  1.180                 cout << _cimServerProcess->getCompleteVersion() << endl;
 452 a.arora         1.142                 exit(0);
 453                                   }
 454 mike            1.35              // Check for -option
 455 a.arora         1.142             else if (*arg == '-')
 456 mike            1.35              {
 457                                       // Get the option
 458                                       const char* option = arg + 1;
 459                       
 460                                       //
 461                                       // Check to see if user asked for the version (-v option):
 462                                       //
 463 tony            1.83                  if (*option == OPTION_VERSION &&
 464                                           strlen(option) == 1)
 465 mike            1.35                  {
 466 jim.wunderlich  1.180                     cout << _cimServerProcess->getCompleteVersion() << endl;
 467 mike            1.35                      exit(0);
 468                                       }
 469                                       //
 470                                       // Check to see if user asked for help (-h option):
 471                                       //
 472 tony            1.83                  else if (*option == OPTION_HELP &&
 473                                               (strlen(option) == 1))
 474 mike            1.35                  {
 475                                           PrintHelp(argv[0]);
 476                                           exit(0);
 477                                       }
 478 kumpf           1.138 #if !defined(PEGASUS_USE_RELEASE_DIRS)
 479 tony            1.83                  else if (*option == OPTION_HOME &&
 480                                               (strlen(option) == 1))
 481 mike            1.35                  {
 482 kumpf           1.60                      if (i + 1 < argc)
 483 mike            1.35                      {
 484                                               pegasusHome.assign(argv[i + 1]);
 485                                           }
 486                                           else
 487                                           {
 488 humberto        1.97                          //l10n
 489                                               //cout << "Missing argument for option -" << option << endl;
 490 humberto        1.99                          String opt(option);
 491 humberto        1.97                          MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
 492 h.sterling      1.153                                          "Missing argument for option -$0",
 493                                                                opt);
 494                                               cout << MessageLoader::getMessage(parms) << endl;
 495 mike            1.35                          exit(0);
 496                                           }
 497                       
 498                                           memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 499                                           argc -= 2;
 500                                       }
 501 kumpf           1.63  #endif
 502 kumpf           1.48                  //
 503 kumpf           1.178                 // Check to see if user asked for debug output (-X option):
 504 kumpf           1.48                  //
 505 kumpf           1.178                 else if (*option == OPTION_DEBUGOUTPUT &&
 506 tony            1.83                          (strlen(option) == 1))
 507 kumpf           1.48                  {
 508 kumpf           1.178                     MessageLoaderParms parms(
 509                                               "src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
 510                                               "Unsupported debug output option is enabled.");
 511 h.sterling      1.153                     cout << MessageLoader::getMessage(parms) << endl;
 512 kumpf           1.178 
 513                                           debugOutputOption = true;
 514                       
 515                       #if defined(PEGASUS_OS_HPUX)
 516                                           System::bindVerbose = true;
 517                       #endif
 518                       
 519 kumpf           1.48                      // remove the option from the command line
 520                                           memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 521 david.dillard   1.165                     argc--;
 522 kumpf           1.48                  }
 523 mike            1.35                  //
 524                                       // Check to see if user asked for shutdown (-s option):
 525                                       //
 526 tony            1.82                  else if (*option == OPTION_SHUTDOWN &&
 527                                               (strlen(option) == 1))
 528 mike            1.35                  {
 529                                           //
 530 kumpf           1.52                      // Check to see if shutdown has already been specified:
 531 mike            1.35                      //
 532 kumpf           1.52                      if (shutdownOption)
 533 mike            1.35                      {
 534 humberto        1.97                          //l10n
 535                                               //cout << "Duplicate shutdown option specified." << endl;
 536                                               MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
 537 h.sterling      1.153                                                  "Duplicate shutdown option specified.");
 538 david.dillard   1.165 
 539 humberto        1.97                          cout << MessageLoader::getMessage(parms) << endl;
 540 mike            1.35                          exit(0);
 541                                           }
 542                       
 543 kumpf           1.52                      shutdownOption = true;
 544 david.dillard   1.165 
 545 mike            1.35                      // remove the option from the command line
 546                                           memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 547 david.dillard   1.165                     argc--;
 548 mike            1.35                  }
 549                                       else
 550                                           i++;
 551                                   }
 552                                   else
 553                                       i++;
 554 mike            1.32          }
 555 mike            1.35  
 556 kumpf           1.38      //
 557                           // Set the value for pegasusHome property
 558                           //
 559                           ConfigManager::setPegasusHome(pegasusHome);
 560 mike            1.32  
 561 mike            1.35      //
 562 carolann.graves 1.171     // Do the platform specific run
 563 s.hills         1.117     //
 564                       
 565 kumpf           1.178     return _cimServerProcess->platform_run(
 566                               argc, argv, shutdownOption, debugOutputOption);
 567 s.hills         1.117 }
 568                       
 569 h.sterling      1.153 void CIMServerProcess::cimserver_stop()
 570                       {
 571                           _cimServer->shutdownSignal();
 572                       }
 573 s.hills         1.117 
 574                       //
 575                       // The main, common, running code
 576                       //
 577 david.dillard   1.165 // NOTE: Do NOT call exit().  Use return(), otherwise some platforms
 578 s.hills         1.117 // will fail to shutdown properly/cleanly.
 579                       //
 580 david.dillard   1.165 // TODO: Current change minimal for platform "service" shutdown bug fixes.
 581 carolann.graves 1.171 // Perhaps further extract out common stuff and put into main(), put
 582 david.dillard   1.165 // daemon stuff into platform specific platform_run(), etc.
 583                       // Note: make sure to not put error handling stuff that platform
 584 carolann.graves 1.171 // specific runs may need to deal with better (instead of exit(), etc).
 585 s.hills         1.117 //
 586                       
 587 kumpf           1.178 int CIMServerProcess::cimserver_run(
 588                           int argc,
 589                           char** argv,
 590                           Boolean shutdownOption,
 591                           Boolean debugOutputOption)
 592 s.hills         1.117 {
 593 kumpf           1.196     String logsDirectory;
 594 s.hills         1.117     Boolean daemonOption = false;
 595                       
 596                           //
 597 mike            1.35      // Get an instance of the Config Manager.
 598                           //
 599                           configManager = ConfigManager::getInstance();
 600 kumpf           1.136     configManager->useConfigFiles = true;
 601 mike            1.35  
 602 lucier          1.130 #ifdef PEGASUS_OS_OS400
 603                           // In a special startup case for IBM OS400, when the server is
 604                           // automatically started when the machine starts up the config
 605                           // file cannot be read because of access restrictions for the
 606                           // user starting the server.  In this case, we need to skip
 607                           // reading the config options and therefore any use of the config
 608                           // manager also.  To make this determinations we will check to see
 609                           // if the daemon flag is set to true.  If so, then there will be a
 610                           // series of checks to bracket all the calls to the configManager
 611                           // which would otherwise fail.  All this will only be done for
 612                           // IBM OS400.
 613                       
 614                           Boolean os400StartupOption = false;
 615                           // loop through args to check for daemon=true
 616                           for (int i=1; i < argc; i++)
 617                             if (strcmp(argv[i], "daemon=true") == 0)
 618                             {
 619                               os400StartupOption = true;
 620                               daemonOption = true;
 621                             }
 622 chuck           1.164 
 623                           if (!os400StartupOption)
 624                           {
 625                               // If this is the server job, then set the job
 626                               // to save the job log.
 627                               system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
 628                           }
 629 david.dillard   1.165 #endif
 630 lucier          1.130 
 631 mike            1.35      //
 632 mike            1.32      // Get options (from command line and from configuration file); this
 633 mike            1.35      // removes corresponding options and their arguments from the command
 634 mike            1.32      // line.
 635 mike            1.35      //
 636 mike            1.32      try
 637                           {
 638 lucier          1.130 #ifdef PEGASUS_OS_OS400
 639                           if (os400StartupOption == false)
 640 david.dillard   1.165 #endif
 641 mateus.baur     1.193         // If current process is "cimserver -s" (shutdown option = true) the contents
 642                               // of current config should not be overwriten by planned config
 643                               GetOptions(configManager, argc, argv, shutdownOption);
 644 mike            1.32      }
 645                           catch (Exception& e)
 646                           {
 647 kumpf           1.127         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 648                                   "src.Server.cimserver.SERVER_NOT_STARTED",
 649                                   "cimserver not started:  $0", e.getMessage());
 650                       
 651                       #if !defined(PEGASUS_OS_OS400)
 652                               MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 653                                   "cimserver not started: $0", e.getMessage());
 654                       
 655                               PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
 656                                   << PEGASUS_STD(endl);
 657 david           1.85  #endif
 658 kumpf           1.127 
 659 s.hills         1.117         return(1);
 660 mike            1.32      }
 661                       
 662 chuck           1.94  // l10n
 663 h.sterling      1.153     // Set the home directory, msg sub-dir, into the MessageLoader.
 664 david.dillard   1.165     // This will be the default directory where the resource bundles
 665                           // are found.
 666 h.sterling      1.153     MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
 667 david.dillard   1.165         ConfigManager::getInstance()->getCurrentValue("messageDir")));
 668 chuck           1.94  
 669 lucier          1.130 #ifdef PEGASUS_OS_OS400
 670                           // Still need to declare and set the connection variables.
 671                           // Will initialize to false since they are fixed at false for OS400.
 672                       
 673                           // NOTE:  OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down
 674                           // the test will not be compiled in.  If OS400 ever turns off that
 675                           // define, then we will need to change this code path to insure that
 676 david.dillard   1.165     // one of the variables is true.
 677 lucier          1.130     Boolean enableHttpConnection = false;
 678                           Boolean enableHttpsConnection = false;
 679                       
 680                           if (os400StartupOption == false)
 681                           {
 682 kumpf           1.187       enableHttpConnection = ConfigManager::parseBooleanValue(
 683                                 configManager->getCurrentValue("enableHttpConnection"));
 684                             enableHttpsConnection = ConfigManager::parseBooleanValue(
 685                                 configManager->getCurrentValue("enableHttpsConnection"));
 686 lucier          1.130     }
 687                       #else
 688 kumpf           1.187     Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
 689                               configManager->getCurrentValue("enableHttpConnection"));
 690                           Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
 691                               configManager->getCurrentValue("enableHttpsConnection"));
 692 lucier          1.130 #endif
 693 kumpf           1.86  
 694                           // Make sure at least one connection is enabled
 695 h.sterling      1.159 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
 696 kumpf           1.86      if (!enableHttpConnection && !enableHttpsConnection)
 697                           {
 698 humberto        1.97          //l10n
 699                               //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 700                                   //"Neither HTTP nor HTTPS connection is enabled.  "
 701                                   //"CIMServer will not be started.");
 702                               Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
 703 h.sterling      1.153             "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 704 humberto        1.97              "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 705                               //cerr << "Neither HTTP nor HTTPS connection is enabled.  "
 706                                   //"CIMServer will not be started." << endl;
 707                               MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
 708 h.sterling      1.153                                  "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
 709 humberto        1.97          cerr << MessageLoader::getMessage(parms) << endl;
 710 s.hills         1.117         return(1);
 711 kumpf           1.86      }
 712                       #endif
 713                       
 714 mike            1.35      try
 715 mike            1.32      {
 716 mike            1.35          //
 717 kumpf           1.187         // Check to see if we should start Pegasus as a daemon
 718 mike            1.35          //
 719                       
 720 kumpf           1.187         daemonOption = ConfigManager::parseBooleanValue(
 721                                   configManager->getCurrentValue("daemon"));
 722 david.dillard   1.165 
 723 lucier          1.130 #ifdef PEGASUS_OS_OS400
 724                           if (os400StartupOption == false)
 725                           {
 726 david.dillard   1.165 #endif
 727 konrad.r        1.161 #if !defined(PEGASUS_USE_SYSLOGS)
 728 david.dillard   1.165         logsDirectory =
 729 h.sterling      1.153         ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
 730 konrad.r        1.161 #endif
 731 lucier          1.130 #ifdef PEGASUS_OS_OS400
 732                           }  // end if (os400StartupOption == false)
 733                       #endif
 734 kumpf           1.36  
 735                               // Set up the Logger. This does not open the logs
 736                               // Might be more logical to clean before set.
 737                               // ATTN: Need tool to completely disable logging.
 738                       
 739 david           1.85  #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
 740 konrad.r        1.161 !defined(PEGASUS_OS_OS400) && !defined(PEGASUS_USE_SYSLOGS)
 741 kumpf           1.36          Logger::setHomeDirectory(logsDirectory);
 742 kumpf           1.57  #endif
 743 kumpf           1.36  
 744                               //
 745 david.dillard   1.165         // Check to see if we need to shutdown CIMOM
 746 mike            1.35          //
 747                               if (shutdownOption)
 748                               {
 749 david.dillard   1.165             String configTimeout =
 750 kumpf           1.60                  configManager->getCurrentValue("shutdownTimeout");
 751 s.hills         1.117             Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
 752 dave.sudlik     1.191 // To deregister Pegasus with SLP
 753                       #ifdef PEGASUS_SLP_REG_TIMEOUT
 754                                   unregisterPegasusFromSLP();
 755                       #endif
 756 david.dillard   1.165 
 757 kumpf           1.198             ServerShutdownClient serverShutdownClient(&_serverRunStatus);
 758                                   serverShutdownClient.shutdown(timeoutValue);
 759 kumpf           1.45  
 760 david           1.85  #ifdef PEGASUS_OS_OS400
 761 h.sterling      1.153         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
 762                                   "src.Server.cimserver.SERVER_STOPPED",
 763                                   "CIM Server stopped.");
 764 s.hills         1.117             cimserver_exitRC(0);
 765 david           1.85  #else
 766 kumpf           1.198             MessageLoaderParms parms(
 767                                       "src.Server.cimserver.SERVER_STOPPED",
 768                                       "CIM Server stopped.");
 769 humberto        1.106 
 770 humberto        1.97              cout << MessageLoader::getMessage(parms) << endl;
 771 s.hills         1.117             return(0);
 772 diane           1.81  #endif
 773 mike            1.35          }
 774 mike            1.32  
 775 kumpf           1.198 #if defined(PEGASUS_DEBUG) && !defined(PEGASUS_USE_SYSLOGS)
 776 kumpf           1.36          // Leave this in until people get familiar with the logs.
 777 humberto        1.97          MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
 778 h.sterling      1.153                                  "Logs Directory = ");
 779 humberto        1.97          cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
 780 kumpf           1.57  #endif
 781 mike            1.32      }
 782 kumpf           1.122     catch (UnrecognizedConfigProperty& e)
 783 mike            1.32      {
 784 marek           1.186         // UnrecognizedConfigProperty is already translated
 785                               // thus, just output the message
 786                               Logger::put(Logger::ERROR_LOG,
 787                                           System::CIMSERVER,
 788                                           Logger::SEVERE,
 789                                           e.getMessage());
 790                       #ifndef PEGASUS_OS_OS400
 791                               cout << e.getMessage() << endl;
 792                       #endif
 793                           }
 794                           catch (Exception& ex)
 795                           {
 796                               Logger::put(Logger::ERROR_LOG,
 797                                             System::CIMSERVER,
 798                                             Logger::SEVERE,
 799                                             ex.getMessage());
 800                       #ifndef PEGASUS_OS_OS400
 801                               cout << ex.getMessage() << endl;
 802                       #endif
 803                               exit(1);
 804                           }
 805 david           1.85  
 806 marek           1.186 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && defined(PEGASUS_ZOS_SECURITY)
 807                           startupCheckBPXServer(true);
 808                           startupCheckProfileCIMSERVclassWBEM();
 809                           startupEnableMSC();
 810 david           1.85  #endif
 811 mike            1.32  
 812 h.sterling      1.158     // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.
 813                           // 1) If the user explicitly specified a port, use it.
 814                           // 2) If the user did not specify a port, get the port from the services file.
 815                           // 3) If no value is specified in the services file, use the IANA WBEM default port.
 816                           // Note that 2 and 3 are done within the System::lookupPort method
 817                           // An empty string from the ConfigManager implies that the user did not specify a port.
 818                       
 819 w.otsuka        1.147     Uint32 portNumberHttps=0;
 820                           Uint32 portNumberHttp=0;
 821                           Uint32 portNumberExportHttps=0;
 822 kumpf           1.53  
 823 kumpf           1.86      if (enableHttpsConnection)
 824 kumpf           1.53      {
 825 kumpf           1.86          String httpsPort = configManager->getCurrentValue("httpsPort");
 826 h.sterling      1.158         if (httpsPort == String::EMPTY)
 827 joyce.j         1.144         {
 828 h.sterling      1.158             //
 829                                   // Look up the WBEM-HTTPS port number
 830                                   //
 831                                   portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
 832                       
 833                               } else
 834 david.dillard   1.165         {
 835 h.sterling      1.158             //
 836                                   // user-specified
 837                                   //
 838                                   CString portString = httpsPort.getCString();
 839                                   char* end = 0;
 840                                   portNumberHttps = strtol(portString, &end, 10);
 841                                   if(!(end != 0 && *end == '\0'))
 842                                   {
 843 joyce.j         1.160                 InvalidPropertyValue e("httpsPort", httpsPort);
 844 aruran.ms       1.173                 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 845                                                     "src.Server.cimserver.SERVER_NOT_STARTED",
 846                                                     "cimserver not started:  $0", e.getMessage());
 847                       #if !defined(PEGASUS_OS_OS400)
 848                                       MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 849                                                                "cimserver not started: $0", e.getMessage());
 850                                       PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
 851                                                         << PEGASUS_STD(endl);
 852                       #endif
 853 h.sterling      1.158                 exit(1);
 854                                   }
 855 joyce.j         1.144         }
 856 kumpf           1.53      }
 857 kumpf           1.86  
 858                           if (enableHttpConnection)
 859 kumpf           1.53      {
 860 kumpf           1.86          String httpPort = configManager->getCurrentValue("httpPort");
 861 h.sterling      1.158         if (httpPort == String::EMPTY)
 862 joyce.j         1.144         {
 863 h.sterling      1.158             //
 864                                   // Look up the WBEM-HTTP port number
 865                                   //
 866                                   portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
 867                       
 868                               } else
 869                               {
 870                                   //
 871                                   // user-specified
 872                                   //
 873                                   CString portString = httpPort.getCString();
 874                                   char* end = 0;
 875                                   portNumberHttp = strtol(portString, &end, 10);
 876                                   if(!(end != 0 && *end == '\0'))
 877                                   {
 878 joyce.j         1.160                 InvalidPropertyValue e("httpPort", httpPort);
 879 aruran.ms       1.173                 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 880                                                     "src.Server.cimserver.SERVER_NOT_STARTED",
 881                                                     "cimserver not started:  $0", e.getMessage());
 882                       #if !defined(PEGASUS_OS_OS400)
 883                                       MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 884                                                                    "cimserver not started: $0", e.getMessage());
 885                                       PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
 886                                                         << PEGASUS_STD(endl);
 887                       #endif
 888 h.sterling      1.158                 exit(1);
 889                                   }
 890 joyce.j         1.144         }
 891 kumpf           1.53      }
 892 kumpf           1.139 #if defined(PEGASUS_DEBUG)
 893 mike            1.32      // Put out startup up message.
 894 jim.wunderlich  1.180     cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getCompleteVersion() << endl;
 895 humberto        1.97      //l10n
 896                           //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
 897                           //cout <<"Starting..."
 898                           MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
 899 h.sterling      1.153                              "Built $0 $1\nStarting...",
 900                                                    __DATE__,
 901                                                    __TIME__);
 902 humberto        1.97  #endif
 903                       
 904                       //l10n
 905                       // reset message loading to NON-process locale
 906 david.dillard   1.165 MessageLoader::_useProcessLocale = false;
 907 humberto        1.97  //l10n
 908 mike            1.32  
 909 kumpf           1.137     // Get the parent's PID before forking
 910 kumpf           1.198     _serverRunStatus.setParentPid(System::getPID());
 911 david.dillard   1.165 
 912 kumpf           1.63      // do we need to run as a daemon ?
 913                           if (daemonOption)
 914                           {
 915 h.sterling      1.153         if(-1 == _cimServerProcess->cimserver_fork())
 916 diane           1.81  #ifndef PEGASUS_OS_OS400
 917 h.sterling      1.153     {
 918                               return(-1);
 919                           }
 920 diane           1.81  #else
 921 h.sterling      1.153     {
 922 david           1.85              return(-1);
 923 h.sterling      1.153     }
 924                           else
 925                           {
 926                               return(0);
 927                           }
 928 diane           1.81  #endif
 929 david.dillard   1.165 
 930 kumpf           1.63      }
 931 chuck           1.66  
 932 chuck           1.96  // l10n
 933                           // Now we are after the fork...
 934                           // Create a dummy Thread object that can be used to store the
 935 kumpf           1.176     // AcceptLanguageList object for CIM requests that are serviced
 936 chuck           1.96      // by this thread (initial thread of server).  Need to do this
 937                           // because this thread is not in a ThreadPool, but is used
 938                           // to service CIM requests.
 939                           // The run function for the dummy Thread should never be called,
 940 konrad.r        1.166     dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
 941 david.dillard   1.165     Thread::setCurrent(dummyInitialThread);
 942 kumpf           1.176     AcceptLanguageList default_al;
 943 humberto        1.108     try{
 944 kumpf           1.174          default_al = LanguageParser::getDefaultAcceptLanguages();
 945 kumpf           1.176          Thread::setLanguages(new AcceptLanguageList(default_al));
 946 kumpf           1.122     }catch(InvalidAcceptLanguageHeader& e){
 947 h.sterling      1.153           Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 948                                         "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
 949 david.dillard   1.165                   "Could not convert the system process locale into a valid AcceptLanguage format.");
 950 h.sterling      1.153           Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 951 david.dillard   1.165                              e.getMessage());
 952 humberto        1.108     }
 953 david.dillard   1.165 
 954                       
 955 chuck           1.96  
 956 chuck           1.66  #ifdef PEGASUS_OS_OS400
 957                           // Special server initialization code for OS/400.
 958                           if (cimserver_initialize() != 0)
 959                           {
 960 h.sterling      1.153     // do some logging here!
 961                           //l10n
 962                           //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 963 david.dillard   1.165             //"CIM Server failed to initialize");
 964 h.sterling      1.153     Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 965                                         "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE",
 966 david.dillard   1.165                   "CIM Server failed to initialize");
 967 h.sterling      1.153     return(-1);
 968 david.dillard   1.165     }
 969 chuck           1.66  #endif
 970 chuck           1.96  
 971 kumpf           1.167 #ifndef PEGASUS_OS_TYPE_WINDOWS
 972                           umask(S_IRWXG|S_IRWXO);
 973                       #endif
 974 mday            1.62  
 975 mateus.baur     1.175 
 976                       #if defined(PEGASUS_OS_TYPE_UNIX)
 977                         //    
 978                         // CRITICAL SECTION BEGIN
 979                         //
 980                         // This is the beginning of the critical section regarding the
 981                         // access to pidfile (file to indicate that the cimserver has started).
 982                         // Sometimes, when 2 or more cimserver processes are started at the same 
 983                         // time, they can't detect the concurrent process execution because the 
 984                         // logic fails when pidfile is accessed concurrently.
 985                       
 986                         FILE *startupLockFile;
 987                       
 988 denise.eckstein 1.177   if ((startupLockFile = fopen(ConfigManager::getHomedPath(
 989                                 CIMSERVER_LOCK_FILE).getCString(), "w")) != 0)
 990 mateus.baur     1.175   {
 991                             lockf(fileno(startupLockFile), F_LOCK, 0);
 992                         }
 993                       #endif
 994                       
 995 gs.keenan       1.150 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
 996                       || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
 997 jim.wunderlich  1.169 || defined(PEGASUS_OS_SOLARIS) || defined (PEGASUS_OS_VMS)
 998 kumpf           1.79  
 999                           //
1000                           // check if CIMServer is already running
1001 david.dillard   1.165     // if CIMServer is already running, print message and
1002 kumpf           1.79      // notify parent process (if there is a parent process) to terminate
1003                           //
1004 kumpf           1.198     if (_serverRunStatus.isServerRunning())
1005 kumpf           1.79      {
1006 kumpf           1.198         MessageLoaderParms parms(
1007                                   "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
1008                                   "Unable to start CIMServer. CIMServer is already running.");
1009                               PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
1010                                   PEGASUS_STD(endl);
1011 thilo.boehm     1.192         Logger::put(Logger::ERROR_LOG,System::CIMSERVER,Logger::INFORMATION,
1012 kumpf           1.198             MessageLoader::getMessage(parms));
1013 kumpf           1.79  
1014 kumpf           1.198         //
1015 kumpf           1.79          // notify parent process (if there is a parent process) to terminate
1016                               //
1017                               if (daemonOption)
1018 kumpf           1.198         {
1019                                   _cimServerProcess->notify_parent(1);
1020                               }
1021 kumpf           1.79  
1022 kumpf           1.198         return 1;
1023 kumpf           1.79      }
1024 david.dillard   1.165 
1025 kumpf           1.63  #endif
1026 kumpf           1.51  
1027 mike            1.32      // try loop to bind the address, and run the server
1028                           try
1029                           {
1030 kumpf           1.198         _monitor = new Monitor();
1031                               _cimServer = new CIMServer(_monitor);
1032 kumpf           1.41  
1033 kumpf           1.86          if (enableHttpConnection)
1034                               {
1035 sushma.fernandes 1.189             _cimServer->addAcceptor(false, portNumberHttp, false);
1036 kumpf            1.198 
1037                                    Logger::put_l(
1038                                        Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1039                                        "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1040                                        "Listening on HTTP port $0.", portNumberHttp);
1041 kumpf            1.86          }
1042 kumpf            1.198 
1043 kumpf            1.86          if (enableHttpsConnection)
1044                                {
1045 sushma.fernandes 1.189             _cimServer->addAcceptor(false, portNumberHttps, true);
1046 kumpf            1.198 
1047                                    Logger::put_l(
1048                                        Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1049                                        "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1050                                        "Listening on HTTPS port $0.", portNumberHttps);
1051 kumpf            1.86          }
1052 kumpf            1.135 
1053 h.sterling       1.159 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1054 sushma.fernandes 1.189         _cimServer->addAcceptor(true, 0, false);
1055 kumpf            1.198 
1056                                Logger::put_l(
1057                                    Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1058                                    "src.Server.cimserver.LISTENING_ON_LOCAL",
1059                                    "Listening on local connection socket.");
1060 kumpf            1.41  #endif
1061 kumpf            1.86  
1062 kumpf            1.139 #if defined(PEGASUS_DEBUG)
1063 kumpf            1.86          if (enableHttpConnection)
1064                                {
1065 kumpf            1.198             MessageLoaderParms parms(
1066                                        "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1067                                        "Listening on HTTP port $0.", portNumberHttp);
1068 h.sterling       1.153             cout << MessageLoader::getMessage(parms) << endl;
1069 kumpf            1.86          }
1070                                if (enableHttpsConnection)
1071                                {
1072 kumpf            1.198             MessageLoaderParms parms(
1073                                        "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1074                                        "Listening on HTTPS port $0.", portNumberHttps);
1075 h.sterling       1.153             cout << MessageLoader::getMessage(parms) << endl;
1076 kumpf            1.86          }
1077 kumpf            1.135 
1078 h.sterling       1.159 # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1079 kumpf            1.198         MessageLoaderParms parms(
1080                                    "src.Server.cimserver.LISTENING_ON_LOCAL",
1081                                    "Listening on local connection socket.");
1082 humberto         1.97          cout << MessageLoader::getMessage(parms) << endl;
1083 kumpf            1.86  # endif
1084 david            1.85  #endif
1085 mike             1.35  
1086 kumpf            1.198         _cimServer->bind();
1087                                // notify parent process (if there is a parent process) to terminate
1088 konrad.r         1.95          // so user knows that there is cimserver ready to serve CIM requests.
1089 kumpf            1.198         if (daemonOption)
1090                                {
1091                                    _cimServerProcess->notify_parent(0);
1092                                }
1093 mike             1.35  
1094 kumpf            1.198 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || \
1095                            defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) || \
1096                            defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS)
1097 kumpf            1.45          //
1098 kumpf            1.56          // create a file to indicate that the cimserver has started and
1099                                // save the process id of the cimserver process in the file
1100 kumpf            1.45          //
1101 kumpf            1.198         _serverRunStatus.setServerRunning();
1102 kumpf            1.45  #endif
1103 kumpf            1.91  
1104 kumpf            1.139 #if defined(PEGASUS_DEBUG)
1105 h.sterling       1.153     cout << "Started. " << endl;
1106 kumpf            1.63  #endif
1107 david.dillard    1.165 
1108 mateus.baur      1.175 #if defined(PEGASUS_OS_TYPE_UNIX)    
1109                            //
1110                            // CRITICAL SECTION END
1111                            // 
1112                            // Here is the unlock of file 'lock_file'. It closes the
1113                            // the critical section that guarantees the non concurrent access to
1114                            // pid file (file to indicate that the cimserver has started).
1115                            //
1116                        
1117                            if (startupLockFile)
1118                            {
1119                               lockf(fileno(startupLockFile), F_ULOCK, 0);
1120                               fclose(startupLockFile);
1121                            }
1122                        #endif
1123                        
1124                        
1125 kumpf            1.54          // Put server started message to the logger
1126 kumpf            1.143         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1127                                    Logger::INFORMATION,
1128                                    "src.Server.cimserver.STARTED_VERSION",
1129                                    "Started $0 version $1.",
1130 jim.wunderlich   1.180 		      _cimServerProcess->getProductName(), _cimServerProcess->getCompleteVersion());
1131 kumpf            1.45  
1132 marek            1.190 #if defined(PEGASUS_OS_TYPE_UNIX) && !defined(PEGASUS_OS_ZOS)
1133 kumpf            1.178         if (daemonOption && !debugOutputOption)
1134                                { 
1135                                    // Direct standard input, output, and error to /dev/null,
1136                                    // since we are running as a daemon.
1137                                    close(0);
1138                                    open("/dev/null", O_RDONLY);
1139                                    close(1);
1140                                    open("/dev/null", O_RDWR);
1141                                    close(2);
1142                                    open("/dev/null", O_RDWR);
1143                                }
1144                        #endif
1145                        
1146 thilo.boehm      1.185 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1147                        
1148                                // ARM is a z/OS internal restart facility. 
1149                                // This is a z/OS specific change. 
1150                        
1151                                // Instatiating the automatic restart manager for zOS
1152                                ARM_zOS automaticRestartManager;
1153                        
1154                                // register to zOS ARM
1155                                automaticRestartManager.Register();
1156                        
1157                        #endif
1158                        
1159                        
1160                        
1161 mike             1.35          //
1162                                // Loop to call CIMServer's runForever() method until CIMServer
1163                                // has been shutdown
1164                                //
1165 h.sterling       1.153     while( !_cimServer->terminated() )
1166                            {
1167 mday             1.116 
1168 h.sterling       1.153       _cimServer->runForever();
1169 mday             1.112 
1170 h.sterling       1.153     }
1171 carson.hovey     1.157 
1172 kumpf            1.45          //
1173                                // normal termination
1174 carson.hovey     1.157         //
1175 thilo.boehm      1.185 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1176                        
1177                                // ARM is a z/OS internal restart facility. 
1178                                // This is a z/OS specific change. 
1179                        
1180                                // register to zOS ARM
1181                                automaticRestartManager.DeRegister();
1182                        
1183                        #endif
1184 kumpf            1.143 
1185 kumpf            1.54          // Put server shutdown message to the logger
1186 kumpf            1.143         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1187                                    Logger::INFORMATION, "src.Server.cimserver.STOPPED",
1188 h.sterling       1.153             "$0 stopped.", _cimServerProcess->getProductName());
1189 kumpf            1.45  
1190 carolann.graves  1.171 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) \
1191 gs.keenan        1.150 || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1192 jim.wunderlich   1.169 || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS)
1193 kumpf            1.45          //
1194 carolann.graves  1.171         //  Note: do not remove the PID file created at startup time, since
1195                                //  shutdown is not complete until the CIMServer destructor completes.
1196 kumpf            1.45          //
1197                        #endif
1198 mike             1.32      }
1199 marek            1.195     catch(BindFailedException& e)
1200 mike             1.32      {
1201 marek            1.194         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1202                                    "src.Server.cimserver.SERVER_NOT_STARTED",
1203                                    "cimserver not started:  $0", e.getMessage());
1204 david            1.100 
1205 marek            1.194 #if !defined(PEGASUS_OS_OS400)
1206                                MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
1207                                    "cimserver not started: $0", e.getMessage());
1208 david            1.100 
1209 marek            1.194         cerr << MessageLoader::getMessage(parms) << endl;
1210 david            1.85  #endif
1211 kumpf            1.77  
1212 h.sterling       1.153     //
1213 kumpf            1.77          // notify parent process (if there is a parent process) to terminate
1214                                //
1215                                if (daemonOption)
1216 h.sterling       1.153                 _cimServerProcess->notify_parent(1);
1217 kumpf            1.77  
1218 h.sterling       1.156         deleteCIMServer();
1219 kumpf            1.54          return 1;
1220 mike             1.32      }
1221 marek            1.195     catch(Exception& e)
1222                            {
1223                            Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1224                                    "src.Server.cimserver.ERROR",
1225                                    "Error: $0", e.getMessage());
1226                        #ifndef PEGASUS_OS_OS400
1227                            MessageLoaderParms parms("src.Server.cimserver.ERROR",
1228                                                     "Error: $0", e.getMessage());
1229                            PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1230                        #endif
1231                                //
1232                                // notify parent process (if there is a parent process) to terminate
1233                                //
1234                                if (daemonOption)
1235                                        _cimServerProcess->notify_parent(1);
1236                        
1237                                deleteCIMServer();
1238                                return 1;
1239                            }
1240 mike             1.32  
1241 h.sterling       1.156     deleteCIMServer();
1242 mike             1.32      return 0;
1243                        }
1244 tony             1.128 

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2