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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2