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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2