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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2