(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                       // Mike Day, mdday@us.ibm.com
  80 david.dillard   1.165 //
  81 mike            1.32  //////////////////////////////////////////////////////////////////////
  82                       
  83                       
  84 mike            1.35  #include <Pegasus/Common/Config.h>
  85 kumpf           1.59  #include <Pegasus/Common/Constants.h>
  86 jim.wunderlich  1.172 #include <Pegasus/Common/PegasusAssert.h>
  87 mike            1.32  #include <cstdlib>
  88                       #include <Pegasus/Common/FileSystem.h>
  89 mike            1.35  #include <Pegasus/Common/Monitor.h>
  90 mike            1.32  #include <Pegasus/Common/PegasusVersion.h>
  91                       #include <Pegasus/Common/Logger.h>
  92                       #include <Pegasus/Common/System.h>
  93 mike            1.35  #include <Pegasus/Common/Tracer.h>
  94 kumpf           1.174 #include <Pegasus/Common/LanguageParser.h>
  95 mike            1.35  #include <Pegasus/Config/ConfigManager.h>
  96                       #include <Pegasus/Client/CIMClient.h>
  97                       #include <Pegasus/Server/ShutdownService.h>
  98 h.sterling      1.153 #include <Pegasus/Server/CIMServer.h>
  99                       #include <Service/ServerProcess.h>
 100 mike            1.32  
 101 chuck           1.155 #if defined(PEGASUS_OS_OS400)
 102                       #  include "vfyptrs.cinc"
 103                       #  include "OS400ConvertChar.h"
 104                       #endif
 105                       
 106 thilo.boehm     1.185 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) 
 107                       #include <Service/ARM_zOS.h>
 108 marek           1.186 # ifdef PEGASUS_ZOS_SECURITY
 109                       // This include file will not be provided in the OpenGroup CVS for now.
 110                       // Do NOT try to include it in your compile
 111                       #  include <Pegasus/Common/safCheckzOS_inline.h>
 112                       # endif
 113 thilo.boehm     1.185 #endif
 114                       
 115 kumpf           1.178 #if defined(PEGASUS_OS_TYPE_UNIX)
 116                       # if defined(PEGASUS_OS_OS400)
 117 mateus.baur     1.175 #  include <unistd.cleinc>
 118 kumpf           1.178 # else
 119 mateus.baur     1.175 #  include <unistd.h>
 120 kumpf           1.178 # endif
 121                       # include <sys/types.h>
 122                       # include <sys/stat.h>
 123                       # include <fcntl.h>
 124 mateus.baur     1.175 #endif
 125                       
 126 kumpf           1.193.2.1 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 127                           # define PEGASUS_PROCESS_NAME "cimservermain"
 128                           #else
 129                           # define PEGASUS_PROCESS_NAME "cimserver"
 130                           #endif
 131                           
 132                           #include <Pegasus/Common/Executor.h>
 133                           
 134 kumpf           1.119     PEGASUS_USING_PEGASUS;
 135                           PEGASUS_USING_STD;
 136                           
 137 h.sterling      1.153     //Windows service variables are not defined elsewhere in the product
 138                           //enable ability to override these
 139                           #ifndef PEGASUS_SERVICE_NAME
 140                           #define PEGASUS_SERVICE_NAME "Pegasus CIM Object Manager";
 141 chuck           1.66      #endif
 142 h.sterling      1.153     #ifndef PEGASUS_SERVICE_DESCRIPTION
 143                           #define PEGASUS_SERVICE_DESCRIPTION "Pegasus CIM Object Manager Service";
 144 mike            1.32      #endif
 145                           
 146 h.sterling      1.153     class CIMServerProcess : public ServerProcess
 147                           {
 148                           public:
 149                           
 150                               CIMServerProcess(void)
 151                               {
 152                                   cimserver_set_process(this);
 153                               }
 154                           
 155                               virtual ~CIMServerProcess(void)
 156                               {
 157                               }
 158                           
 159                               //defined in PegasusVersion.h
 160                               virtual const char* getProductName() const
 161                               {
 162                                   return PEGASUS_PRODUCT_NAME;
 163                               }
 164                           
 165                               virtual const char* getExtendedName() const
 166                               {
 167 h.sterling      1.153             return PEGASUS_SERVICE_NAME;
 168                               }
 169                           
 170                               virtual const char* getDescription() const
 171                               {
 172                                   return PEGASUS_SERVICE_DESCRIPTION;
 173                               }
 174 david.dillard   1.165     
 175 h.sterling      1.153         //defined in PegasusVersion.h
 176 jim.wunderlich  1.180         virtual const char* getCompleteVersion() const
 177                               {
 178 jim.wunderlich  1.181           if (*PEGASUS_PRODUCT_STATUS == '\0' )
 179 jim.wunderlich  1.180     	return PEGASUS_PRODUCT_VERSION;
 180                                 else
 181                           	return PEGASUS_PRODUCT_VERSION " " PEGASUS_PRODUCT_STATUS;      
 182                               }
 183                           
 184                               //defined in PegasusVersion.h
 185 h.sterling      1.153         virtual const char* getVersion() const
 186                               {
 187                                   return PEGASUS_PRODUCT_VERSION;
 188                               }
 189                           
 190                               virtual const char* getProcessName() const
 191                               {
 192                                   return PEGASUS_PROCESS_NAME;
 193                               }
 194                           
 195 kumpf           1.184         //defined in Constants.h
 196 h.sterling      1.153         virtual const char* getPIDFileName() const
 197                               {
 198 kumpf           1.184             return PEGASUS_CIMSERVER_START_FILE;
 199 h.sterling      1.153         }
 200                           
 201 kumpf           1.178         int cimserver_run(
 202                                   int argc,
 203                                   char** argv,
 204                                   Boolean shutdownOption,
 205                                   Boolean debugOutputOption);
 206 h.sterling      1.153     
 207                               void cimserver_stop(void);
 208                           };
 209                           
 210                           AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
 211                           static CIMServer* _cimServer = 0;
 212 konrad.r        1.163     static Monitor* _monitor = 0;
 213 konrad.r        1.166     static Thread* dummyInitialThread = 0;
 214 mike            1.35      //
 215                           //  The command name.
 216                           //
 217                           static const char COMMAND_NAME []    = "cimserver";
 218                           
 219                           //
 220                           //  The constant defining usage string.
 221                           //
 222                           static const char USAGE []           = "Usage: ";
 223                           
 224                           /**
 225                           Constants representing the command line options.
 226                           */
 227                           static const char OPTION_VERSION     = 'v';
 228                           
 229                           static const char OPTION_HELP        = 'h';
 230                           
 231                           static const char OPTION_HOME        = 'D';
 232                           
 233                           static const char OPTION_SHUTDOWN    = 's';
 234                           
 235 a.arora         1.142     static const char   LONG_HELP []  = "help";
 236                           
 237                           static const char   LONG_VERSION []  = "version";
 238                           
 239 kumpf           1.178     static const char OPTION_DEBUGOUTPUT = 'X';
 240 kumpf           1.48      
 241 kumpf           1.54      static const String PROPERTY_TIMEOUT = "shutdownTimeout";
 242 mike            1.35      
 243                           ConfigManager*    configManager;
 244                           
 245 mike            1.32      /** GetOptions function - This function defines the Options Table
 246 mike            1.35          and sets up the options from that table using the config manager.
 247 mike            1.32      */
 248                           void GetOptions(
 249 mike            1.35          ConfigManager* cm,
 250 mike            1.32          int& argc,
 251 mateus.baur     1.193         char** argv,
 252                               const Boolean& shutdownOption)
 253 mike            1.32      {
 254 mike            1.35          try
 255 mike            1.32          {
 256 mateus.baur     1.193             if (shutdownOption)
 257                                   {
 258                                       cm->loadConfigFiles();
 259                                   }
 260                                   else
 261                                   {
 262                                       cm->mergeConfigFiles();
 263                                   }
 264                           
 265                                   // Temporarily disable updates to the current configuration
 266                                   // file if shutdownOption is true
 267                                   cm->useConfigFiles = (shutdownOption==false);
 268 mike            1.33      
 269 mike            1.35              cm->mergeCommandLine(argc, argv);
 270 mateus.baur     1.193     
 271                                   // Enable updates again
 272                                   cm->useConfigFiles = true;
 273 mike            1.35          }
 274 kumpf           1.122         catch (NoSuchFile&)
 275 mike            1.35          {
 276 kumpf           1.122             throw;
 277 mike            1.35          }
 278 kumpf           1.122         catch (FileNotReadable&)
 279 mike            1.35          {
 280 kumpf           1.122             throw;
 281 mike            1.35          }
 282 kumpf           1.122         catch (CannotRenameFile&)
 283 mike            1.35          {
 284 kumpf           1.122             throw;
 285 mike            1.35          }
 286 kumpf           1.122         catch (ConfigFileSyntaxError&)
 287 mike            1.35          {
 288 kumpf           1.122             throw;
 289 mike            1.35          }
 290 kumpf           1.122         catch(UnrecognizedConfigProperty&)
 291 mike            1.35          {
 292 kumpf           1.122             throw;
 293 mike            1.35          }
 294 kumpf           1.122         catch(InvalidPropertyValue&)
 295 mike            1.35          {
 296 kumpf           1.122             throw;
 297 mike            1.35          }
 298 kumpf           1.123         catch (CannotOpenFile&)
 299                               {
 300                                   throw;
 301                               }
 302 mike            1.32      }
 303                           
 304                           /* PrintHelp - This is temporary until we expand the options manager to allow
 305                              options help to be defined with the OptionRow entries and presented from
 306                              those entries.
 307                           */
 308                           void PrintHelp(const char* arg0)
 309                           {
 310 mike            1.35          String usage = String (USAGE);
 311                               usage.append (COMMAND_NAME);
 312                               usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
 313                               usage.append ("  options\n");
 314 a.arora         1.142         usage.append ("    -v, --version   - displays CIM Server version number\n");
 315                               usage.append ("    -h, --help      - prints this help message\n");
 316 humberto        1.97          usage.append ("    -s              - shuts down CIM Server\n");
 317 kumpf           1.138     #if !defined(PEGASUS_USE_RELEASE_DIRS)
 318                               usage.append ("    -D [home]       - sets pegasus home directory\n");
 319 humberto        1.97      #endif
 320                           #if defined(PEGASUS_OS_TYPE_WINDOWS)
 321 joyce.j         1.148         usage.append ("    -install [name] - installs pegasus as a Windows Service\n");
 322 humberto        1.97          usage.append ("                      [name] is optional and overrides the\n");
 323                               usage.append ("                      default CIM Server Service Name\n");
 324 aruran.ms       1.183         usage.append ("                      by appending [name]\n");
 325 joyce.j         1.148         usage.append ("    -remove [name]  - removes pegasus as a Windows Service\n");
 326 humberto        1.97          usage.append ("                      [name] is optional and overrides the\n");
 327                               usage.append ("                      default CIM Server Service Name\n");
 328 aruran.ms       1.183         usage.append ("                      by appending [name]\n");
 329 joyce.j         1.148         usage.append ("    -start [name]   - starts pegasus as a Windows Service\n");
 330 humberto        1.97          usage.append ("                      [name] is optional and overrides the\n");
 331                               usage.append ("                      default CIM Server Service Name\n");
 332 aruran.ms       1.183         usage.append ("                      by appending [name]\n");
 333 joyce.j         1.148         usage.append ("    -stop [name]    - stops pegasus as a Windows Service\n");
 334 humberto        1.97          usage.append ("                      [name] is optional and overrides the\n");
 335 aruran.ms       1.183         usage.append ("                      default CIM Server Service Name\n");
 336                               usage.append ("                      by appending [name]\n\n");
 337 humberto        1.97      #endif
 338                               usage.append ("  configProperty=value\n");
 339                               usage.append ("                    - sets CIM Server configuration property\n");
 340                           
 341                               cout << endl;
 342 jim.wunderlich  1.180         cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getCompleteVersion() << endl;
 343 humberto        1.97          cout << endl;
 344 david.dillard   1.165     
 345 humberto        1.97      #if defined(PEGASUS_OS_TYPE_WINDOWS)
 346 humberto        1.104         MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
 347 kumpf           1.152     #elif defined(PEGASUS_USE_RELEASE_DIRS)
 348 kumpf           1.138         MessageLoaderParms parms("src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);
 349 humberto        1.97      #else
 350 kumpf           1.138         MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
 351 humberto        1.97      #endif
 352                               cout << MessageLoader::getMessage(parms) << endl;
 353 mike            1.35      }
 354                           
 355 h.sterling      1.156     //This needs to be called at various points in the code depending on the platform and error conditions.
 356                           //We need to delete the _cimServer reference on exit in order for the destructors to get called.
 357                           void deleteCIMServer()
 358                           {
 359                               if (_cimServer)
 360                               {
 361                                   delete _cimServer;
 362                                   _cimServer = 0;
 363 carolann.graves 1.171     
 364                           #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) \
 365                           || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
 366                           || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS)
 367                                   //
 368                                   //  Remove the PID file to indicate CIMServer termination
 369                                   //
 370                                   FileSystem::removeFile(_cimServerProcess->getPIDFileName());
 371                           #endif
 372 h.sterling      1.156         }
 373 kumpf           1.182         delete _monitor;
 374 konrad.r        1.166        if (dummyInitialThread)
 375                              {
 376                           	Thread::clearLanguages();
 377                           	delete dummyInitialThread;
 378                              }
 379 h.sterling      1.156     }
 380                           
 381 chuck           1.96      // l10n
 382                           //
 383                           // Dummy function for the Thread object associated with the initial thread.
 384                           // Since the initial thread is used to process CIM requests, this is
 385                           // needed to localize the exceptions thrown during CIM request processing.
 386 david.dillard   1.165     // Note: This function should never be called!
 387                           //
 388 mike            1.188     ThreadReturnType PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
 389 chuck           1.96      {
 390 mike            1.188        return((ThreadReturnType)0);
 391 chuck           1.96      }
 392                           
 393 carolann.graves 1.171     //
 394                           //  Waits until either the CIM Server has terminated, or the shutdown timeout
 395                           //  has expired.  If the shutdown timeout has expired, and the CIM Server is
 396                           //  still running, kills the cimserver process.
 397                           //
 398                           void _waitForTerminationOrTimeout (Uint32 maxWaitTime)
 399                           {
 400                               //
 401                               //  If the CIM Server is still running, and the shutdown timeout has not
 402                               //  expired, loop and wait one second until either the CIM Server has
 403                               //  terminated, or the shutdown timeout has expired
 404                               //
 405                               Boolean running = _cimServerProcess->isCIMServerRunning ();
 406                               while (running && (maxWaitTime > 0))
 407                               {
 408                                   System::sleep (1);
 409                                   running = _cimServerProcess->isCIMServerRunning ();
 410                                   maxWaitTime--;
 411                               }
 412                           
 413                               //
 414 carolann.graves 1.171         //  If the shutdown timeout has expired, and the CIM Server is still
 415                               //  running, kill the cimserver process
 416                               //
 417                               if (running)
 418                               {
 419                                   int kill_rc = _cimServerProcess->cimserver_kill (0);
 420                           
 421                           #ifdef PEGASUS_OS_OS400
 422                                   if (kill_rc == -1)
 423                                   {
 424                                       _cimServerProcess->cimserver_exitRC (2);
 425                                   }
 426                                   _cimServerProcess->cimserver_exitRC (1);
 427                           #endif
 428                           
 429                           #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
 430                           || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_SOLARIS) \
 431                           || defined (PEGASUS_OS_VMS)
 432                                   if (kill_rc != -1)
 433                                   {
 434                                       //l10n - TODO
 435 carolann.graves 1.171                 Logger::put_l (Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 436                                           "src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 437                                           "Shutdown timeout expired.  Forced shutdown initiated.");
 438                                       MessageLoaderParms parms
 439                                           ("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED",
 440                                           "Shutdown timeout expired.  Forced shutdown initiated.");
 441                                       cout << MessageLoader::getMessage(parms) << endl;
 442                                       exit (0);
 443                                   }
 444                           #endif
 445                               }
 446                           }
 447                           
 448 kumpf           1.52      void shutdownCIMOM(Uint32 timeoutValue)
 449 mike            1.35      {
 450                               //
 451                               // Create CIMClient object
 452                               //
 453 kumpf           1.42          CIMClient client;
 454 mike            1.35      
 455                               //
 456 kumpf           1.53          // Get local host name
 457 mike            1.35          //
 458                               String hostStr = System::getHostName();
 459                           
 460                               //
 461 david.dillard   1.165         // open connection to CIMOM
 462 mike            1.35          //
 463                               try
 464                               {
 465 kumpf           1.43              client.connectLocal();
 466 kumpf           1.52      
 467                                   //
 468 kumpf           1.63              // set client timeout to 2 seconds
 469 kumpf           1.52              //
 470 kumpf           1.71              client.setTimeout(2000);
 471 mike            1.35          }
 472 s.hills         1.117         catch(Exception&)
 473 mike            1.35          {
 474 david           1.85      #ifdef PEGASUS_OS_OS400
 475 h.sterling      1.153         //l10n
 476                               //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 477                                       //"Unable to connect to CIM Server.  CIM Server may not be running." );
 478                               Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 479                                       "src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
 480                                       "Unable to connect to CIM Server.  CIM Server may not be running." );
 481                               // The server job may still be active but not responding.
 482                               // Kill the job if it exists.
 483                               if(_cimServerProcess->cimserver_kill(0) == -1)
 484                                  _cimServerProcess->cimserver_exitRC(2);
 485                               _cimServerProcess->cimserver_exitRC(1);
 486 david           1.85      #else
 487 humberto        1.97              //l10n
 488                                   //PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
 489                                   //PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
 490                                   MessageLoaderParms parms("src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING",
 491 kumpf           1.105                                                              "Unable to connect to CIM Server.\nCIM Server may not be running.\n");
 492 humberto        1.97              PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
 493 s.hills         1.117             exit(1);
 494 chuck           1.66      #endif
 495 mike            1.35          }
 496                           
 497                               try
 498                               {
 499                                   //
 500 kumpf           1.52              // construct CIMObjectPath
 501 mike            1.35              //
 502                                   String referenceStr = "//";
 503                                   referenceStr.append(hostStr);
 504 david.dillard   1.165             referenceStr.append("/");
 505 kumpf           1.72              referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
 506 kumpf           1.53              referenceStr.append(":");
 507 kumpf           1.72              referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
 508 kumpf           1.50              CIMObjectPath reference(referenceStr);
 509 mike            1.35      
 510                                   //
 511                                   // issue the invokeMethod request on the shutdown method
 512                                   //
 513                                   Array<CIMParamValue> inParams;
 514                                   Array<CIMParamValue> outParams;
 515                           
 516 kumpf           1.52              // set force option to true for now
 517 kumpf           1.40              inParams.append(CIMParamValue("force",
 518 kumpf           1.52                  CIMValue(Boolean(true))));
 519 mike            1.35      
 520 kumpf           1.40              inParams.append(CIMParamValue("timeout",
 521 kumpf           1.39                  CIMValue(Uint32(timeoutValue))));
 522 mike            1.35      
 523                                   CIMValue retValue = client.invokeMethod(
 524 kumpf           1.59                  PEGASUS_NAMESPACENAME_SHUTDOWN,
 525 mike            1.35                  reference,
 526                                       "shutdown",
 527                                       inParams,
 528                                       outParams);
 529 kumpf           1.43          }
 530 kumpf           1.65          catch(CIMException& e)
 531 kumpf           1.46          {
 532 david           1.85      #ifdef PEGASUS_OS_OS400
 533                           
 534 h.sterling      1.153         if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 535                               {
 536                                   //l10n
 537                                   //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 538                                       //"Failed to shutdown server: $0", "The repository may be empty.");
 539                                   Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 540                                       "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
 541                                       "Error in server shutdown: The repository may be empty.");
 542                               }
 543                               else
 544                               {
 545                                   //l10n
 546                                   //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 547                                       //"Failed to shutdown server: $0", e.getMessage());
 548                                   Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 549                                       "src.Server.cimserver.SHUTDOWN_FAILED",
 550                                       "Error in server shutdown: $0", e.getMessage());
 551                               }
 552                               // Kill the server job.
 553                               if(_cimServerProcess->cimserver_kill(0) == -1)
 554                                  _cimServerProcess->cimserver_exitRC(2);
 555 david           1.85      #else
 556 kumpf           1.105             //l10n - TODO
 557 humberto        1.97              MessageLoaderParms parms("src.Server.cimserver.SHUTDOWN_FAILED",
 558 kumpf           1.105                                      "Error in server shutdown: ");
 559 humberto        1.97              PEGASUS_STD(cerr) << MessageLoader::getMessage(parms);
 560 kumpf           1.63              if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
 561                                   {
 562 kumpf           1.105                 //
 563 david.dillard   1.165                 // Repository may be empty.
 564 kumpf           1.105                 //
 565                                       //l10n - TODO
 566                                       Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 567                                           "src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY",
 568                                           "Error in server shutdown: The repository may be empty.");
 569 humberto        1.97                  MessageLoaderParms parms("src.Server.cimserver.REPOSITORY_EMPTY",
 570 kumpf           1.105                                          "The repository may be empty.");
 571                                       PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
 572 kumpf           1.63              }
 573                                   else
 574                                   {
 575 kumpf           1.105                 //l10n - TODO
 576                                       Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 577                                           "src.Server.cimserver.SHUTDOWN_FAILED",
 578                                           "Error in server shutdown: $0", e.getMessage());
 579 kumpf           1.63                  PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
 580                                   }
 581 kumpf           1.105     
 582 david.dillard   1.165         // Kill the cimserver process
 583 h.sterling      1.153         if (_cimServerProcess->cimserver_kill(0) == 0)
 584 kumpf           1.105             {
 585                                       //l10n - TODO
 586                                       Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 587                                           "src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
 588 h.sterling      1.153                 "Forced shutdown initiated.");
 589 kumpf           1.105                 MessageLoaderParms parms("src.Server.cimserver.SERVER_FORCED_SHUTDOWN",
 590                                                                "Forced shutdown initiated.");
 591                                       PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
 592                                   }
 593 s.hills         1.117             exit(1);
 594 chuck           1.66      #endif
 595 kumpf           1.46          }
 596 kumpf           1.193.2.1     catch(Exception& e)
 597 kumpf           1.45          {
 598 kumpf           1.193.2.1         cerr << "Shutdown failed: " << e.getMessage() << endl;
 599 kumpf           1.45              //
 600 kumpf           1.91              // This may mean that the CIM Server has terminated, causing this
 601                                   // client to get a "Empty HTTP response message" exception.  It may
 602 david.dillard   1.165             // also mean that the CIM Server is taking longer than 2 seconds
 603                                   // (client timeout value) to terminate, causing this client to
 604 kumpf           1.91              // timeout with a "connection timeout" exception.
 605 kumpf           1.45              //
 606 carolann.graves 1.171             //  Wait until either the CIM Server has terminated, or the shutdown
 607                                   //  timeout has expired.  If the timeout has expired and the CIM Server
 608                                   //  is still running, kill the cimserver process.
 609                                   //
 610                                   _waitForTerminationOrTimeout (timeoutValue - 2);
 611 kumpf           1.168         }
 612                           
 613 carolann.graves 1.171         //
 614                               //  InvokeMethod succeeded.
 615                               //  Wait until either the CIM Server has terminated, or the shutdown
 616                               //  timeout has expired.  If the timeout has expired and the CIM Server
 617                               //  is still running, kill the cimserver process.
 618                               //
 619                               _waitForTerminationOrTimeout (timeoutValue);
 620 mike            1.35          return;
 621 mike            1.32      }
 622                           
 623 kumpf           1.193.2.1 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 624                           
 625                           static int _extractExecutorSockOpt(int& argc, char**& argv)
 626                           {
 627                               // Extract the "-x <sock>" option if any. This indicates that the
 628                               // e[x]ecutor is running. The option argument is the socket used
 629                               // to communicate with the executor. Remove the option from the
 630                               // argv list and decrease argc by two.
 631                           
 632                               int sock = -1;
 633                           
 634                               for (int i = 1; i < argc; i++)
 635                               {
 636                                   if (strcmp(argv[i], "-x") == 0)
 637                                   {
 638                                       // Check for missing option argument.
 639                           
 640                                       if (i + 1 == argc)
 641                                       {
 642                                           fprintf(stderr, 
 643                                               "%s: missing option argument for -x\n", argv[0]);
 644 kumpf           1.193.2.1                 exit(1);
 645                                       }
 646                           
 647                                       // Convert argument to integer.
 648                           
 649                                       char* end;
 650                                       unsigned long x = strtoul(argv[i+1], &end, 10);
 651                           
 652                                       // Check whether option argument will fit in integer.
 653                           
 654                                       if (*end != '\0' || x > 2147483647)
 655                                       {
 656                                           fprintf(stderr, 
 657                                               "%s: bad -x option argument: %s\n", argv[0], argv[i+1]);
 658                                           exit(1);
 659                                       }
 660                           
 661                                       sock = int(x);
 662                           
 663                                       // Remove "-x <sock>" from argv-argc.
 664                           
 665 kumpf           1.193.2.1             memmove(argv + i, argv + i + 2, sizeof(char*) * (argc - i - 1));
 666                                       argc -= 2;
 667                                       break;
 668                                   }
 669                               }
 670                           
 671                               return sock;
 672                           }
 673                           
 674                           #endif /* PEGASUS_ENABLE_PRIVILEGE_SEPARATION */
 675 mike            1.35      
 676 mike            1.33      /////////////////////////////////////////////////////////////////////////
 677 mike            1.32      //  MAIN
 678                           //////////////////////////////////////////////////////////////////////////
 679 kumpf           1.193.2.1 
 680 mike            1.32      int main(int argc, char** argv)
 681                           {
 682 kumpf           1.193.2.1 #ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION
 683                           
 684                               // If invoked with "-x <socket>" option, then use executor.
 685                           
 686                               Executor::setSock(_extractExecutorSockOpt(argc, argv));
 687                           
 688                               // Ping executor to be sure the sock was valid.
 689                           
 690                               if (Executor::ping() != 0)
 691                               {
 692                                   fprintf(stderr, 
 693                                       "%s: failed to ping executor on socket given by -x option\n", 
 694                                       argv[0]);
 695                                   exit(1);
 696                               }
 697                           
 698                           #endif /* !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) */
 699                           
 700 mike            1.35          String pegasusHome  = String::EMPTY;
 701                               Boolean shutdownOption = false;
 702 kumpf           1.178         Boolean debugOutputOption = false;
 703 mday            1.47      
 704 humberto        1.97      //l10n
 705                           // Set Message loading to process locale
 706 david.dillard   1.165     MessageLoader::_useProcessLocale = true;
 707 humberto        1.97      //l10n
 708                           
 709 kv.le           1.140     //l10n
 710                           #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
 711                           setlocale(LC_ALL, "");
 712                           #endif
 713                           
 714 chuck           1.66      #ifdef PEGASUS_OS_OS400
 715 david           1.120     
 716                             VFYPTRS_INCDCL;               // VFYPTRS local variables
 717                           
 718                             // verify pointers
 719                             #pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\
 720                               0,_C2_MH_ESCAPE)
 721                               for( int arg_index = 1; arg_index < argc; arg_index++ ){
 722 h.sterling      1.153         VFYPTRS(VERIFY_SPP_NULL(argv[arg_index]));
 723 david           1.120         }
 724                             #pragma disable_handler
 725                           
 726 david           1.100         // Convert the args to ASCII
 727                               for(Uint32 i = 0;i< argc;++i)
 728                               {
 729 h.sterling      1.153         EtoA(argv[i]);
 730 david           1.100         }
 731                           
 732 chuck           1.66          // Initialize Pegasus home to the shipped OS/400 directory.
 733                               pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
 734                           #endif
 735                           
 736 kv.le           1.134     
 737 tony            1.82      #ifndef PEGASUS_OS_TYPE_WINDOWS
 738 kumpf           1.38          //
 739                               // Get environment variables:
 740                               //
 741 david           1.100     #ifdef PEGASUS_OS_OS400
 742                           #pragma convert(37)
 743                               const char* tmp = getenv("PEGASUS_HOME");
 744                           #pragma convert(0)
 745                               char home[256] = {0};
 746                               if (tmp && strlen(tmp) < 256)
 747                               {
 748 h.sterling      1.153         strcpy(home, tmp);
 749                               EtoA(home);
 750                               pegasusHome = home;
 751 david           1.100         }
 752                           #else
 753 kv.le           1.134       #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
 754                               pegasusHome = AIX_RELEASE_PEGASUS_HOME;
 755 marek           1.170       #elif !defined(PEGASUS_USE_RELEASE_DIRS) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
 756 kumpf           1.38          const char* tmp = getenv("PEGASUS_HOME");
 757                           
 758                               if (tmp)
 759                               {
 760                                   pegasusHome = tmp;
 761                               }
 762 kv.le           1.134       #endif
 763 david           1.100     #endif
 764 kumpf           1.38      
 765                               FileSystem::translateSlashes(pegasusHome);
 766 tony            1.82      #else
 767 kumpf           1.38      
 768 tony            1.82        // windows only
 769 h.sterling      1.153       //setHome(pegasusHome);
 770                             pegasusHome = _cimServerProcess->getHome();
 771 tony            1.82      #endif
 772 mike            1.32      
 773 kumpf           1.60              // Get help, version, and shutdown options
 774 mike            1.35      
 775                                   for (int i = 1; i < argc; )
 776                                   {
 777                                       const char* arg = argv[i];
 778 a.arora         1.142                 if(String::equal(arg,"--help"))
 779                                       {
 780                                               PrintHelp(argv[0]);
 781                                               exit(0);
 782                                       }
 783                                       else if(String::equal(arg,"--version"))
 784                                       {
 785 jim.wunderlich  1.180                     cout << _cimServerProcess->getCompleteVersion() << endl;
 786 a.arora         1.142                     exit(0);
 787                                       }
 788 mike            1.35                  // Check for -option
 789 a.arora         1.142                 else if (*arg == '-')
 790 mike            1.35                  {
 791                                           // Get the option
 792                                           const char* option = arg + 1;
 793                           
 794                                           //
 795                                           // Check to see if user asked for the version (-v option):
 796                                           //
 797 tony            1.83                      if (*option == OPTION_VERSION &&
 798                                               strlen(option) == 1)
 799 mike            1.35                      {
 800 jim.wunderlich  1.180                         cout << _cimServerProcess->getCompleteVersion() << endl;
 801 mike            1.35                          exit(0);
 802                                           }
 803                                           //
 804                                           // Check to see if user asked for help (-h option):
 805                                           //
 806 tony            1.83                      else if (*option == OPTION_HELP &&
 807                                                   (strlen(option) == 1))
 808 mike            1.35                      {
 809                                               PrintHelp(argv[0]);
 810                                               exit(0);
 811                                           }
 812 kumpf           1.138     #if !defined(PEGASUS_USE_RELEASE_DIRS)
 813 tony            1.83                      else if (*option == OPTION_HOME &&
 814                                                   (strlen(option) == 1))
 815 mike            1.35                      {
 816 kumpf           1.60                          if (i + 1 < argc)
 817 mike            1.35                          {
 818                                                   pegasusHome.assign(argv[i + 1]);
 819                                               }
 820                                               else
 821                                               {
 822 humberto        1.97                              //l10n
 823                                                   //cout << "Missing argument for option -" << option << endl;
 824 humberto        1.99                              String opt(option);
 825 humberto        1.97                              MessageLoaderParms parms("src.Server.cimserver.MISSING_ARGUMENT",
 826 h.sterling      1.153                                              "Missing argument for option -$0",
 827                                                                    opt);
 828                                                   cout << MessageLoader::getMessage(parms) << endl;
 829 mike            1.35                              exit(0);
 830                                               }
 831                           
 832                                               memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
 833                                               argc -= 2;
 834                                           }
 835 kumpf           1.63      #endif
 836 kumpf           1.48                      //
 837 kumpf           1.178                     // Check to see if user asked for debug output (-X option):
 838 kumpf           1.48                      //
 839 kumpf           1.178                     else if (*option == OPTION_DEBUGOUTPUT &&
 840 tony            1.83                              (strlen(option) == 1))
 841 kumpf           1.48                      {
 842 kumpf           1.178                         MessageLoaderParms parms(
 843                                                   "src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
 844                                                   "Unsupported debug output option is enabled.");
 845 h.sterling      1.153                         cout << MessageLoader::getMessage(parms) << endl;
 846 kumpf           1.178     
 847                                               debugOutputOption = true;
 848                           
 849                           #if defined(PEGASUS_OS_HPUX)
 850                                               System::bindVerbose = true;
 851                           #endif
 852                           
 853 kumpf           1.48                          // remove the option from the command line
 854                                               memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 855 david.dillard   1.165                         argc--;
 856 kumpf           1.48                      }
 857 mike            1.35                      //
 858                                           // Check to see if user asked for shutdown (-s option):
 859                                           //
 860 tony            1.82                      else if (*option == OPTION_SHUTDOWN &&
 861                                                   (strlen(option) == 1))
 862 mike            1.35                      {
 863                                               //
 864 kumpf           1.52                          // Check to see if shutdown has already been specified:
 865 mike            1.35                          //
 866 kumpf           1.52                          if (shutdownOption)
 867 mike            1.35                          {
 868 humberto        1.97                              //l10n
 869                                                   //cout << "Duplicate shutdown option specified." << endl;
 870                                                   MessageLoaderParms parms("src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
 871 h.sterling      1.153                                                      "Duplicate shutdown option specified.");
 872 david.dillard   1.165     
 873 humberto        1.97                              cout << MessageLoader::getMessage(parms) << endl;
 874 mike            1.35                              exit(0);
 875                                               }
 876                           
 877 kumpf           1.52                          shutdownOption = true;
 878 david.dillard   1.165     
 879 mike            1.35                          // remove the option from the command line
 880                                               memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
 881 david.dillard   1.165                         argc--;
 882 mike            1.35                      }
 883                                           else
 884                                               i++;
 885                                       }
 886                                       else
 887                                           i++;
 888 mike            1.32              }
 889 mike            1.35      
 890 kumpf           1.38          //
 891                               // Set the value for pegasusHome property
 892                               //
 893                               ConfigManager::setPegasusHome(pegasusHome);
 894 mike            1.32      
 895 mike            1.35          //
 896 carolann.graves 1.171         // Do the platform specific run
 897 s.hills         1.117         //
 898                           
 899 kumpf           1.178         return _cimServerProcess->platform_run(
 900                                   argc, argv, shutdownOption, debugOutputOption);
 901 s.hills         1.117     }
 902                           
 903 h.sterling      1.153     void CIMServerProcess::cimserver_stop()
 904                           {
 905                               _cimServer->shutdownSignal();
 906                           }
 907 s.hills         1.117     
 908                           //
 909                           // The main, common, running code
 910                           //
 911 david.dillard   1.165     // NOTE: Do NOT call exit().  Use return(), otherwise some platforms
 912 s.hills         1.117     // will fail to shutdown properly/cleanly.
 913                           //
 914 david.dillard   1.165     // TODO: Current change minimal for platform "service" shutdown bug fixes.
 915 carolann.graves 1.171     // Perhaps further extract out common stuff and put into main(), put
 916 david.dillard   1.165     // daemon stuff into platform specific platform_run(), etc.
 917                           // Note: make sure to not put error handling stuff that platform
 918 carolann.graves 1.171     // specific runs may need to deal with better (instead of exit(), etc).
 919 s.hills         1.117     //
 920                           
 921 kumpf           1.178     int CIMServerProcess::cimserver_run(
 922                               int argc,
 923                               char** argv,
 924                               Boolean shutdownOption,
 925                               Boolean debugOutputOption)
 926 s.hills         1.117     {
 927                               String logsDirectory = String::EMPTY;
 928                               Boolean daemonOption = false;
 929                           
 930                               //
 931 mike            1.35          // Get an instance of the Config Manager.
 932                               //
 933                               configManager = ConfigManager::getInstance();
 934 kumpf           1.136         configManager->useConfigFiles = true;
 935 mike            1.35      
 936 lucier          1.130     #ifdef PEGASUS_OS_OS400
 937                               // In a special startup case for IBM OS400, when the server is
 938                               // automatically started when the machine starts up the config
 939                               // file cannot be read because of access restrictions for the
 940                               // user starting the server.  In this case, we need to skip
 941                               // reading the config options and therefore any use of the config
 942                               // manager also.  To make this determinations we will check to see
 943                               // if the daemon flag is set to true.  If so, then there will be a
 944                               // series of checks to bracket all the calls to the configManager
 945                               // which would otherwise fail.  All this will only be done for
 946                               // IBM OS400.
 947                           
 948                               Boolean os400StartupOption = false;
 949                               // loop through args to check for daemon=true
 950                               for (int i=1; i < argc; i++)
 951                                 if (strcmp(argv[i], "daemon=true") == 0)
 952                                 {
 953                                   os400StartupOption = true;
 954                                   daemonOption = true;
 955                                 }
 956 chuck           1.164     
 957                               if (!os400StartupOption)
 958                               {
 959                                   // If this is the server job, then set the job
 960                                   // to save the job log.
 961                                   system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)");
 962                               }
 963 david.dillard   1.165     #endif
 964 lucier          1.130     
 965 mike            1.35          //
 966 mike            1.32          // Get options (from command line and from configuration file); this
 967 mike            1.35          // removes corresponding options and their arguments from the command
 968 mike            1.32          // line.
 969 mike            1.35          //
 970 mike            1.32          try
 971                               {
 972 lucier          1.130     #ifdef PEGASUS_OS_OS400
 973                               if (os400StartupOption == false)
 974 david.dillard   1.165     #endif
 975 mateus.baur     1.193             // If current process is "cimserver -s" (shutdown option = true) the contents
 976                                   // of current config should not be overwriten by planned config
 977                                   GetOptions(configManager, argc, argv, shutdownOption);
 978 mike            1.32          }
 979                               catch (Exception& e)
 980                               {
 981 kumpf           1.127             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
 982                                       "src.Server.cimserver.SERVER_NOT_STARTED",
 983                                       "cimserver not started:  $0", e.getMessage());
 984                           
 985                           #if !defined(PEGASUS_OS_OS400)
 986                                   MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
 987                                       "cimserver not started: $0", e.getMessage());
 988                           
 989                                   PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
 990                                       << PEGASUS_STD(endl);
 991 david           1.85      #endif
 992 kumpf           1.127     
 993 s.hills         1.117             return(1);
 994 mike            1.32          }
 995                           
 996 chuck           1.94      // l10n
 997 h.sterling      1.153         // Set the home directory, msg sub-dir, into the MessageLoader.
 998 david.dillard   1.165         // This will be the default directory where the resource bundles
 999                               // are found.
1000 h.sterling      1.153         MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
1001 david.dillard   1.165             ConfigManager::getInstance()->getCurrentValue("messageDir")));
1002 chuck           1.94      
1003 lucier          1.130     #ifdef PEGASUS_OS_OS400
1004                               // Still need to declare and set the connection variables.
1005                               // Will initialize to false since they are fixed at false for OS400.
1006                           
1007                               // NOTE:  OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down
1008                               // the test will not be compiled in.  If OS400 ever turns off that
1009                               // define, then we will need to change this code path to insure that
1010 david.dillard   1.165         // one of the variables is true.
1011 lucier          1.130         Boolean enableHttpConnection = false;
1012                               Boolean enableHttpsConnection = false;
1013                           
1014                               if (os400StartupOption == false)
1015                               {
1016 kumpf           1.187           enableHttpConnection = ConfigManager::parseBooleanValue(
1017                                     configManager->getCurrentValue("enableHttpConnection"));
1018                                 enableHttpsConnection = ConfigManager::parseBooleanValue(
1019                                     configManager->getCurrentValue("enableHttpsConnection"));
1020 lucier          1.130         }
1021                           #else
1022 kumpf           1.187         Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
1023                                   configManager->getCurrentValue("enableHttpConnection"));
1024                               Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
1025                                   configManager->getCurrentValue("enableHttpsConnection"));
1026 lucier          1.130     #endif
1027 kumpf           1.86      
1028                               // Make sure at least one connection is enabled
1029 h.sterling      1.159     #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1030 kumpf           1.86          if (!enableHttpConnection && !enableHttpsConnection)
1031                               {
1032 humberto        1.97              //l10n
1033                                   //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1034                                       //"Neither HTTP nor HTTPS connection is enabled.  "
1035                                       //"CIMServer will not be started.");
1036                                   Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1037 h.sterling      1.153                 "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
1038 humberto        1.97                  "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
1039                                   //cerr << "Neither HTTP nor HTTPS connection is enabled.  "
1040                                       //"CIMServer will not be started." << endl;
1041                                   MessageLoaderParms parms("src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
1042 h.sterling      1.153                                      "Neither HTTP nor HTTPS connection is enabled.  CIMServer will not be started.");
1043 humberto        1.97              cerr << MessageLoader::getMessage(parms) << endl;
1044 s.hills         1.117             return(1);
1045 kumpf           1.86          }
1046                           #endif
1047                           
1048 mike            1.35          try
1049 mike            1.32          {
1050 mike            1.35              //
1051 kumpf           1.187             // Check to see if we should start Pegasus as a daemon
1052 mike            1.35              //
1053                           
1054 kumpf           1.187             daemonOption = ConfigManager::parseBooleanValue(
1055                                       configManager->getCurrentValue("daemon"));
1056 david.dillard   1.165     
1057 lucier          1.130     #ifdef PEGASUS_OS_OS400
1058                               if (os400StartupOption == false)
1059                               {
1060 david.dillard   1.165     #endif
1061 kumpf           1.36              // Get the log file directory definition.
1062                                   // We put String into Cstring because
1063                                   // Directory functions only handle Cstring.
1064                                   // ATTN-KS: create String based directory functions.
1065 konrad.r        1.161     #if !defined(PEGASUS_USE_SYSLOGS)
1066                           		// When using syslog facility. No files anymore.
1067 kumpf           1.36              logsDirectory = configManager->getCurrentValue("logdir");
1068 david.dillard   1.165             logsDirectory =
1069 h.sterling      1.153             ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
1070 konrad.r        1.161     #endif
1071 lucier          1.130     #ifdef PEGASUS_OS_OS400
1072                               }  // end if (os400StartupOption == false)
1073                           #endif
1074 kumpf           1.36      
1075                                   // Set up the Logger. This does not open the logs
1076                                   // Might be more logical to clean before set.
1077                                   // ATTN: Need tool to completely disable logging.
1078                           
1079 david           1.85      #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \
1080 konrad.r        1.161     !defined(PEGASUS_OS_OS400) && !defined(PEGASUS_USE_SYSLOGS)
1081 kumpf           1.36              Logger::setHomeDirectory(logsDirectory);
1082 kumpf           1.57      #endif
1083 kumpf           1.36      
1084                                   //
1085 david.dillard   1.165             // Check to see if we need to shutdown CIMOM
1086 mike            1.35              //
1087                                   if (shutdownOption)
1088                                   {
1089 david.dillard   1.165                 String configTimeout =
1090 kumpf           1.60                      configManager->getCurrentValue("shutdownTimeout");
1091 s.hills         1.117                 Uint32 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
1092 dave.sudlik     1.191     // To deregister Pegasus with SLP
1093                           #ifdef PEGASUS_SLP_REG_TIMEOUT
1094                                       unregisterPegasusFromSLP();
1095                           #endif
1096 david.dillard   1.165     
1097 kumpf           1.52                  shutdownCIMOM(timeoutValue);
1098 kumpf           1.45      
1099 david           1.85      #ifdef PEGASUS_OS_OS400
1100 h.sterling      1.153             //l10n
1101                                   //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
1102 david.dillard   1.165                 //"CIM Server stopped.");
1103 h.sterling      1.153             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION,
1104                                       "src.Server.cimserver.SERVER_STOPPED",
1105                                       "CIM Server stopped.");
1106 s.hills         1.117                 cimserver_exitRC(0);
1107 david           1.85      #else
1108 h.sterling      1.153                 //l10n
1109 humberto        1.97                  //cout << "CIM Server stopped." << endl;
1110                                       MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED",
1111 h.sterling      1.153                                          "CIM Server stopped.");
1112 humberto        1.106     
1113 humberto        1.97                  cout << MessageLoader::getMessage(parms) << endl;
1114 s.hills         1.117                 return(0);
1115 diane           1.81      #endif
1116 mike            1.35              }
1117 mike            1.32      
1118 kumpf           1.139     #if defined(PEGASUS_DEBUG)
1119 kumpf           1.36              // Leave this in until people get familiar with the logs.
1120 humberto        1.97              //l10n
1121                                   //cout << "Logs Directory = " << logsDirectory << endl;
1122 konrad.r        1.161     #if !defined(PEGASUS_USE_SYSLOGS)
1123 humberto        1.97              MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
1124 h.sterling      1.153                                      "Logs Directory = ");
1125 humberto        1.97              cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
1126 kumpf           1.57      #endif
1127 konrad.r        1.161     #endif
1128 mike            1.32          }
1129 kumpf           1.122         catch (UnrecognizedConfigProperty& e)
1130 mike            1.32          {
1131 marek           1.186             // UnrecognizedConfigProperty is already translated
1132                                   // thus, just output the message
1133                                   Logger::put(Logger::ERROR_LOG,
1134                                               System::CIMSERVER,
1135                                               Logger::SEVERE,
1136                                               e.getMessage());
1137                           #ifndef PEGASUS_OS_OS400
1138                                   cout << e.getMessage() << endl;
1139                           #endif
1140                               }
1141                               catch (Exception& ex)
1142                               {
1143                                   Logger::put(Logger::ERROR_LOG,
1144                                                 System::CIMSERVER,
1145                                                 Logger::SEVERE,
1146                                                 ex.getMessage());
1147                           #ifndef PEGASUS_OS_OS400
1148                                   cout << ex.getMessage() << endl;
1149                           #endif
1150                                   exit(1);
1151                               }
1152 david           1.85      
1153 marek           1.186     #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) && defined(PEGASUS_ZOS_SECURITY)
1154                               startupCheckBPXServer(true);
1155                               startupCheckProfileCIMSERVclassWBEM();
1156                               startupEnableMSC();
1157 david           1.85      #endif
1158 mike            1.32      
1159 h.sterling      1.158         // Bug 2148 - Here is the order of operations for determining the server HTTP and HTTPS ports.
1160                               // 1) If the user explicitly specified a port, use it.
1161                               // 2) If the user did not specify a port, get the port from the services file.
1162                               // 3) If no value is specified in the services file, use the IANA WBEM default port.
1163                               // Note that 2 and 3 are done within the System::lookupPort method
1164                               // An empty string from the ConfigManager implies that the user did not specify a port.
1165                           
1166 w.otsuka        1.147         Uint32 portNumberHttps=0;
1167                               Uint32 portNumberHttp=0;
1168                               Uint32 portNumberExportHttps=0;
1169 kumpf           1.53      
1170 kumpf           1.86          if (enableHttpsConnection)
1171 kumpf           1.53          {
1172 kumpf           1.86              String httpsPort = configManager->getCurrentValue("httpsPort");
1173 h.sterling      1.158             if (httpsPort == String::EMPTY)
1174 joyce.j         1.144             {
1175 h.sterling      1.158                 //
1176                                       // Look up the WBEM-HTTPS port number
1177                                       //
1178                                       portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);
1179                           
1180                                   } else
1181 david.dillard   1.165             {
1182 h.sterling      1.158                 //
1183                                       // user-specified
1184                                       //
1185                                       CString portString = httpsPort.getCString();
1186                                       char* end = 0;
1187                                       portNumberHttps = strtol(portString, &end, 10);
1188                                       if(!(end != 0 && *end == '\0'))
1189                                       {
1190 joyce.j         1.160                     InvalidPropertyValue e("httpsPort", httpsPort);
1191 aruran.ms       1.173                     Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1192                                                         "src.Server.cimserver.SERVER_NOT_STARTED",
1193                                                         "cimserver not started:  $0", e.getMessage());
1194                           #if !defined(PEGASUS_OS_OS400)
1195                                           MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
1196                                                                    "cimserver not started: $0", e.getMessage());
1197                                           PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
1198                                                             << PEGASUS_STD(endl);
1199                           #endif
1200 h.sterling      1.158                     exit(1);
1201                                       }
1202 joyce.j         1.144             }
1203 kumpf           1.53          }
1204 kumpf           1.86      
1205                               if (enableHttpConnection)
1206 kumpf           1.53          {
1207 kumpf           1.86              String httpPort = configManager->getCurrentValue("httpPort");
1208 h.sterling      1.158             if (httpPort == String::EMPTY)
1209 joyce.j         1.144             {
1210 h.sterling      1.158                 //
1211                                       // Look up the WBEM-HTTP port number
1212                                       //
1213                                       portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT);
1214                           
1215                                   } else
1216                                   {
1217                                       //
1218                                       // user-specified
1219                                       //
1220                                       CString portString = httpPort.getCString();
1221                                       char* end = 0;
1222                                       portNumberHttp = strtol(portString, &end, 10);
1223                                       if(!(end != 0 && *end == '\0'))
1224                                       {
1225 joyce.j         1.160                     InvalidPropertyValue e("httpPort", httpPort);
1226 aruran.ms       1.173                     Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1227                                                         "src.Server.cimserver.SERVER_NOT_STARTED",
1228                                                         "cimserver not started:  $0", e.getMessage());
1229                           #if !defined(PEGASUS_OS_OS400)
1230                                           MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
1231                                                                        "cimserver not started: $0", e.getMessage());
1232                                           PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms)
1233                                                             << PEGASUS_STD(endl);
1234                           #endif
1235 h.sterling      1.158                     exit(1);
1236                                       }
1237 joyce.j         1.144             }
1238 kumpf           1.53          }
1239 kumpf           1.139     #if defined(PEGASUS_DEBUG)
1240 mike            1.32          // Put out startup up message.
1241 jim.wunderlich  1.180         cout << _cimServerProcess->getProductName() << " " << _cimServerProcess->getCompleteVersion() << endl;
1242 humberto        1.97          //l10n
1243                               //cout << "Built " << __DATE__ << " " << __TIME__ << endl;
1244                               //cout <<"Starting..."
1245                               MessageLoaderParms parms("src.Server.cimserver.STARTUP_MESSAGE",
1246 h.sterling      1.153                                  "Built $0 $1\nStarting...",
1247                                                        __DATE__,
1248                                                        __TIME__);
1249 humberto        1.97      #endif
1250                           
1251                           //l10n
1252                           // reset message loading to NON-process locale
1253 david.dillard   1.165     MessageLoader::_useProcessLocale = false;
1254 humberto        1.97      //l10n
1255 mike            1.32      
1256 kumpf           1.137         // Get the parent's PID before forking
1257 h.sterling      1.154         _cimServerProcess->set_parent_pid(System::getPID());
1258 david.dillard   1.165     
1259 kumpf           1.193.2.1 // Do not fork when using privilege separation (executor will daemonize itself
1260                           // later).
1261 kumpf           1.63          if (daemonOption)
1262                               {
1263 h.sterling      1.153             if(-1 == _cimServerProcess->cimserver_fork())
1264 kumpf           1.193.2.1 # ifndef PEGASUS_OS_OS400
1265 david           1.85                  return(-1);
1266 kumpf           1.193.2.1 # else
1267                                       return(-1);
1268                                   else
1269                                       return(0);
1270                           # endif
1271 kumpf           1.63          }
1272 chuck           1.66      
1273 chuck           1.96      // l10n
1274                               // Now we are after the fork...
1275                               // Create a dummy Thread object that can be used to store the
1276 kumpf           1.176         // AcceptLanguageList object for CIM requests that are serviced
1277 chuck           1.96          // by this thread (initial thread of server).  Need to do this
1278                               // because this thread is not in a ThreadPool, but is used
1279                               // to service CIM requests.
1280                               // The run function for the dummy Thread should never be called,
1281 konrad.r        1.166         dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
1282 david.dillard   1.165         Thread::setCurrent(dummyInitialThread);
1283 kumpf           1.176         AcceptLanguageList default_al;
1284 humberto        1.108         try{
1285 kumpf           1.174              default_al = LanguageParser::getDefaultAcceptLanguages();
1286 kumpf           1.176              Thread::setLanguages(new AcceptLanguageList(default_al));
1287 kumpf           1.122         }catch(InvalidAcceptLanguageHeader& e){
1288 h.sterling      1.153               Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1289                                             "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
1290 david.dillard   1.165                       "Could not convert the system process locale into a valid AcceptLanguage format.");
1291 h.sterling      1.153               Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1292 david.dillard   1.165                                  e.getMessage());
1293 humberto        1.108         }
1294 david.dillard   1.165     
1295                           
1296 chuck           1.96      
1297 chuck           1.66      #ifdef PEGASUS_OS_OS400
1298                               // Special server initialization code for OS/400.
1299                               if (cimserver_initialize() != 0)
1300                               {
1301 h.sterling      1.153         // do some logging here!
1302                               //l10n
1303                               //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1304 david.dillard   1.165                 //"CIM Server failed to initialize");
1305 h.sterling      1.153         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1306                                             "src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE",
1307 david.dillard   1.165                       "CIM Server failed to initialize");
1308 h.sterling      1.153         return(-1);
1309 david.dillard   1.165         }
1310 chuck           1.66      #endif
1311 chuck           1.96      
1312 kumpf           1.167     #ifndef PEGASUS_OS_TYPE_WINDOWS
1313                               umask(S_IRWXG|S_IRWXO);
1314                           #endif
1315 mday            1.62      
1316 mateus.baur     1.175     
1317                           #if defined(PEGASUS_OS_TYPE_UNIX)
1318                             //    
1319                             // CRITICAL SECTION BEGIN
1320                             //
1321                             // This is the beginning of the critical section regarding the
1322                             // access to pidfile (file to indicate that the cimserver has started).
1323                             // Sometimes, when 2 or more cimserver processes are started at the same 
1324                             // time, they can't detect the concurrent process execution because the 
1325                             // logic fails when pidfile is accessed concurrently.
1326                           
1327                             FILE *startupLockFile;
1328                           
1329 denise.eckstein 1.177       if ((startupLockFile = fopen(ConfigManager::getHomedPath(
1330                                     CIMSERVER_LOCK_FILE).getCString(), "w")) != 0)
1331 mateus.baur     1.175       {
1332                                 lockf(fileno(startupLockFile), F_LOCK, 0);
1333                             }
1334                           #endif
1335                           
1336 gs.keenan       1.150     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
1337                           || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1338 jim.wunderlich  1.169     || defined(PEGASUS_OS_SOLARIS) || defined (PEGASUS_OS_VMS)
1339 kumpf           1.79      
1340                               //
1341                               // check if CIMServer is already running
1342 david.dillard   1.165         // if CIMServer is already running, print message and
1343 kumpf           1.79          // notify parent process (if there is a parent process) to terminate
1344                               //
1345 h.sterling      1.153         if(_cimServerProcess->isCIMServerRunning())
1346 kumpf           1.79          {
1347 h.sterling      1.153         //l10n
1348                                   //cout << "Unable to start CIMServer." << endl;
1349                                   //cout << "CIMServer is already running." << endl;
1350                                   MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
1351 thilo.boehm     1.192                          "Unable to start CIMServer. CIMServer is already running.");
1352 h.sterling      1.153         PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1353 thilo.boehm     1.192             Logger::put(Logger::ERROR_LOG,System::CIMSERVER,Logger::INFORMATION,
1354                                               MessageLoader::getMessage(parms));
1355 kumpf           1.79      
1356 h.sterling      1.153         //
1357 kumpf           1.79              // notify parent process (if there is a parent process) to terminate
1358                                   //
1359                                   if (daemonOption)
1360 h.sterling      1.153                     _cimServerProcess->notify_parent(1);
1361 kumpf           1.79      
1362 s.hills         1.117             return(1);
1363 kumpf           1.79          }
1364 david.dillard   1.165     
1365 kumpf           1.63      #endif
1366 kumpf           1.51      
1367 mike            1.32          // try loop to bind the address, and run the server
1368                               try
1369                               {
1370 mday            1.116     
1371 konrad.r        1.163         _monitor  = new Monitor();
1372 h.sterling      1.153         //PEP#222
1373                               //CIMServer server(&monitor);
1374                               //CimserverHolder cimserverHolder( &server );
1375 konrad.r        1.163         _cimServer = new CIMServer(_monitor);
1376 mday            1.111     
1377 kumpf           1.41      
1378 kumpf           1.86              if (enableHttpConnection)
1379                                   {
1380 sushma.fernandes 1.189                 _cimServer->addAcceptor(false, portNumberHttp, false);
1381 humberto         1.97                  //l10n
1382                                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1383                                                    //"Listening on HTTP port $0.", portNumberHttp);
1384 david.dillard    1.165     
1385 humberto         1.97                  Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1386 h.sterling       1.153                                 "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1387                                                        "Listening on HTTP port $0.", portNumberHttp);
1388 kumpf            1.86              }
1389                                    if (enableHttpsConnection)
1390                                    {
1391 sushma.fernandes 1.189                 _cimServer->addAcceptor(false, portNumberHttps, true);
1392 humberto         1.97                  //l10n
1393                                        //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1394                                                    //"Listening on HTTPS port $0.", portNumberHttps);
1395                                        Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1396 h.sterling       1.153                                 "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1397                                                        "Listening on HTTPS port $0.", portNumberHttps);
1398 kumpf            1.86              }
1399 kumpf            1.135     
1400 h.sterling       1.159     #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1401 sushma.fernandes 1.189             _cimServer->addAcceptor(true, 0, false);
1402 humberto         1.97              //l10n
1403                                    //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1404                                                //"Listening on local connection socket.");
1405                                    Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
1406 h.sterling       1.153                   "src.Server.cimserver.LISTENING_ON_LOCAL",
1407                                          "Listening on local connection socket.");
1408 kumpf            1.41      #endif
1409 kumpf            1.86      
1410 kumpf            1.139     #if defined(PEGASUS_DEBUG)
1411 kumpf            1.86              if (enableHttpConnection)
1412                                    {
1413 humberto         1.97                  //l10n
1414                                        //cout << "Listening on HTTP port " << portNumberHttp << endl;
1415 h.sterling       1.153           MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT",
1416                                               "Listening on HTTP port $0.", portNumberHttp);
1417                                        cout << MessageLoader::getMessage(parms) << endl;
1418 kumpf            1.86              }
1419                                    if (enableHttpsConnection)
1420                                    {
1421 humberto         1.97                  //l10n
1422                                        //cout << "Listening on HTTPS port " << portNumberHttps << endl;
1423 humberto         1.103                 MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
1424 h.sterling       1.153                          "Listening on HTTPS port $0.", portNumberHttps);
1425                                        cout << MessageLoader::getMessage(parms) << endl;
1426 kumpf            1.86              }
1427 kumpf            1.135     
1428 h.sterling       1.159     # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
1429 humberto         1.97              //l10n
1430                                    //cout << "Listening on local connection socket" << endl;
1431                                    MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL",
1432 h.sterling       1.153                      "Listening on local connection socket.");
1433 humberto         1.97              cout << MessageLoader::getMessage(parms) << endl;
1434 kumpf            1.86      # endif
1435 david            1.85      #endif
1436 mike             1.35      
1437 kumpf            1.86              // bind throws an exception if the bind fails
1438 david.dillard    1.165     	try {
1439 konrad.r         1.163                _cimServer->bind();
1440                            	} catch (const BindFailedException &e)
1441                            	{
1442                            #ifdef PEGASUS_DEBUG
1443                                    MessageLoaderParms parms("src.Server.cimserver.BIND_FAILED",
1444                                             "Could not bind: $0.", e.getMessage());
1445                                    cout << MessageLoader::getMessage(parms) << endl;
1446                            #endif
1447                                    Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
1448                                        "src.Server.cimserver.BIND.FAILED",
1449                                        "Could not bind:  $0", e.getMessage());
1450 kumpf            1.73      
1451 konrad.r         1.163     	   deleteCIMServer();
1452                            	   return 1;
1453                            	}
1454 david.dillard    1.165         // notify parent process (if there is a parent process) to terminate
1455 konrad.r         1.95              // so user knows that there is cimserver ready to serve CIM requests.
1456 kumpf            1.193.2.1 #if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION)
1457                                if (daemonOption)
1458                                    Executor::daemonizeExecutor();
1459                            #else
1460 h.sterling       1.153         if (daemonOption)
1461                                    _cimServerProcess->notify_parent(0);
1462 kumpf            1.193.2.1 #endif
1463 mike             1.32      
1464 h.sterling       1.153         time_t last = 0;
1465 mike             1.35      
1466 gs.keenan        1.150     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \
1467 jim.wunderlich   1.169         || defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_SOLARIS) \
1468 gs.keenan        1.150         || defined(PEGASUS_OS_VMS)
1469 kumpf            1.45              //
1470 kumpf            1.56              // create a file to indicate that the cimserver has started and
1471                                    // save the process id of the cimserver process in the file
1472 kumpf            1.45              //
1473 kumpf            1.56              // remove the old file if it exists
1474 h.sterling       1.153             System::removeFile(_cimServerProcess->getPIDFileName());
1475 kumpf            1.56      
1476                                    // open the file
1477 h.sterling       1.153             FILE *pid_file = fopen(_cimServerProcess->getPIDFileName(), "w");
1478 kumpf            1.91      
1479 kumpf            1.56              if (pid_file)
1480 kumpf            1.45              {
1481 kumpf            1.56                  // save the pid in the file
1482 h.sterling       1.153                 fprintf(pid_file, "%ld\n", _cimServerProcess->get_server_pid());
1483 kumpf            1.56                  fclose(pid_file);
1484 kumpf            1.45              }
1485                            #endif
1486 kumpf            1.91      
1487 kumpf            1.139     #if defined(PEGASUS_DEBUG)
1488 h.sterling       1.153         cout << "Started. " << endl;
1489 kumpf            1.63      #endif
1490 david.dillard    1.165     
1491 mateus.baur      1.175     #if defined(PEGASUS_OS_TYPE_UNIX)    
1492                                //
1493                                // CRITICAL SECTION END
1494                                // 
1495                                // Here is the unlock of file 'lock_file'. It closes the
1496                                // the critical section that guarantees the non concurrent access to
1497                                // pid file (file to indicate that the cimserver has started).
1498                                //
1499                            
1500                                if (startupLockFile)
1501                                {
1502                                   lockf(fileno(startupLockFile), F_ULOCK, 0);
1503                                   fclose(startupLockFile);
1504                                }
1505                            #endif
1506                            
1507                            
1508 kumpf            1.54              // Put server started message to the logger
1509 kumpf            1.143             Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1510                                        Logger::INFORMATION,
1511                                        "src.Server.cimserver.STARTED_VERSION",
1512                                        "Started $0 version $1.",
1513 jim.wunderlich   1.180     		      _cimServerProcess->getProductName(), _cimServerProcess->getCompleteVersion());
1514 kumpf            1.45      
1515 marek            1.190     #if defined(PEGASUS_OS_TYPE_UNIX) && !defined(PEGASUS_OS_ZOS)
1516 kumpf            1.178             if (daemonOption && !debugOutputOption)
1517                                    { 
1518                                        // Direct standard input, output, and error to /dev/null,
1519                                        // since we are running as a daemon.
1520                                        close(0);
1521                                        open("/dev/null", O_RDONLY);
1522                                        close(1);
1523                                        open("/dev/null", O_RDWR);
1524                                        close(2);
1525                                        open("/dev/null", O_RDWR);
1526                                    }
1527                            #endif
1528                            
1529 thilo.boehm      1.185     #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1530                            
1531                                    // ARM is a z/OS internal restart facility. 
1532                                    // This is a z/OS specific change. 
1533                            
1534                                    // Instatiating the automatic restart manager for zOS
1535                                    ARM_zOS automaticRestartManager;
1536                            
1537                                    // register to zOS ARM
1538                                    automaticRestartManager.Register();
1539                            
1540                            #endif
1541                            
1542 mike             1.35              //
1543                                    // Loop to call CIMServer's runForever() method until CIMServer
1544                                    // has been shutdown
1545                                    //
1546 h.sterling       1.153         while( !_cimServer->terminated() )
1547                                {
1548 mday             1.116     
1549 h.sterling       1.153           _cimServer->runForever();
1550 mday             1.112     
1551 h.sterling       1.153         }
1552 carson.hovey     1.157     
1553 kumpf            1.45              //
1554                                    // normal termination
1555 carson.hovey     1.157             //
1556 thilo.boehm      1.185     #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
1557                            
1558                                    // ARM is a z/OS internal restart facility. 
1559                                    // This is a z/OS specific change. 
1560                            
1561                                    // register to zOS ARM
1562                                    automaticRestartManager.DeRegister();
1563                            
1564                            #endif
1565 kumpf            1.143     
1566 kumpf            1.54              // Put server shutdown message to the logger
1567 kumpf            1.143             Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
1568                                        Logger::INFORMATION, "src.Server.cimserver.STOPPED",
1569 h.sterling       1.153                 "$0 stopped.", _cimServerProcess->getProductName());
1570 kumpf            1.45      
1571 carolann.graves  1.171     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) \
1572 gs.keenan        1.150     || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \
1573 jim.wunderlich   1.169     || defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS)
1574 kumpf            1.45              //
1575 carolann.graves  1.171             //  Note: do not remove the PID file created at startup time, since
1576                                    //  shutdown is not complete until the CIMServer destructor completes.
1577 kumpf            1.45              //
1578                            #endif
1579 mike             1.32          }
1580                                catch(Exception& e)
1581                                {
1582 david            1.100     
1583 h.sterling       1.153         //l10n
1584                                //Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1585 david.dillard    1.165                 //"Error: $0", e.getMessage());
1586 h.sterling       1.153         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
1587                                        "src.Server.cimserver.ERROR",
1588 david.dillard    1.165                 "Error: $0", e.getMessage());
1589 konrad.r         1.95      
1590                            #ifndef PEGASUS_OS_OS400
1591 h.sterling       1.153         //l10n
1592                                //PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
1593                                MessageLoaderParms parms("src.Server.cimserver.ERROR",
1594                                                         "Error: $0", e.getMessage());
1595                                PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
1596 david            1.100     
1597 david            1.85      #endif
1598 kumpf            1.77      
1599 h.sterling       1.153         //
1600 kumpf            1.77              // notify parent process (if there is a parent process) to terminate
1601                                    //
1602                                    if (daemonOption)
1603 h.sterling       1.153                     _cimServerProcess->notify_parent(1);
1604 kumpf            1.77      
1605 h.sterling       1.156             deleteCIMServer();
1606 kumpf            1.54              return 1;
1607 mike             1.32          }
1608                            
1609 h.sterling       1.156         deleteCIMServer();
1610 mike             1.32          return 0;
1611                            }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2