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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2