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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2