(file) Return to cimserver.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / WMIMapper / WMIServer

  1 martin 1.41 //%LICENSE////////////////////////////////////////////////////////////////
  2             // 
  3             // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9             // 
 10             // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16             // 
 17             // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19             // 
 20             // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21             // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 22 martin 1.41 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 kumpf  1.1  // 
 28 martin 1.41 //////////////////////////////////////////////////////////////////////////
 29 kumpf  1.1  //
 30 mateus.baur 1.36 //%////////////////////////////////////////////////////////////////////////////
 31 kumpf       1.1  
 32                  
 33                  //////////////////////////////////////////////////////////////////////
 34                  //
 35                  // Notes on deamon operation (Unix) and service operation (Win 32):
 36                  //
 37                  // To run pegasus as a daemon on Unix platforms: 
 38                  //
 39                  // cimserver
 40                  //
 41                  // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
 42                  // property to false:
 43                  //
 44                  // cimserver daemon=false
 45                  //
 46                  // The daemon config property has no effect on windows operation. 
 47                  //
 48                  // To shutdown pegasus, use the -s option:
 49                  // 
 50                  // cimserver -s 
 51                  //
 52 kumpf       1.1  // To run pegasus as an NT service, there are FOUR  different possibilities:
 53                  //
 54                  // To INSTALL the Pegasus service, 
 55                  //
 56                  // cimserver -install
 57                  //
 58                  // To REMOVE the Pegasus service, 
 59                  //
 60                  // cimserver -remove
 61                  //
 62                  // To START the Pegasus service, 
 63                  //
 64                  // net start cimserver
 65 mateus.baur 1.17 // or
 66                  // cimserver -start
 67 kumpf       1.1  //
 68                  // To STOP the Pegasus service, 
 69                  //
 70                  // net stop cimserver
 71 mateus.baur 1.17 // or
 72                  // cimserver -stop
 73 kumpf       1.1  //
 74                  // Alternatively, you can use the windows service manager. Pegasus shows up 
 75                  // in the service database as "Pegasus CIM Object Manager"
 76                  //
 77                  //////////////////////////////////////////////////////////////////////
 78                  
 79                  
 80                  #include <Pegasus/Common/Config.h>
 81                  #include <Pegasus/Common/Constants.h>
 82                  #include <iostream>
 83 jim.wunderlich 1.20 #include <Pegasus/Common/PegasusAssert.h>
 84 kumpf          1.1  #include <fstream>
 85                     #include <Pegasus/Common/FileSystem.h>
 86                     #include <Pegasus/Common/PegasusVersion.h>
 87                     #include <Pegasus/Common/Logger.h>
 88                     #include <Pegasus/Common/System.h>
 89                     #include <Pegasus/Common/Tracer.h>
 90 kumpf          1.21 #include <Pegasus/Common/LanguageParser.h>
 91 kumpf          1.1  #include <Pegasus/Config/ConfigManager.h>
 92                     #include <Pegasus/Client/CIMClient.h>
 93 mateus.baur    1.17 #include <Pegasus/Server/CIMServer.h>
 94                     #include <Service/ServerProcess.h>
 95 kumpf          1.30 #include <Service/ServerShutdownClient.h>
 96                     #include <Service/ServerRunStatus.h>
 97 mateus.baur    1.17 
 98                     PEGASUS_USING_PEGASUS;
 99                     PEGASUS_USING_STD;
100 kumpf          1.1  
101 kumpf          1.30 #define PEGASUS_PROCESS_NAME "WMI Mapper"
102 kumpf          1.3  
103 mateus.baur    1.17 //Windows service variables are not defined elsewhere in the product
104                     //enable ability to override these
105                     #ifndef PEGASUS_SERVICE_NAME
106                     #define PEGASUS_SERVICE_NAME "Pegasus WMI Mapper";
107 kumpf          1.1  #endif
108 mateus.baur    1.17 #ifndef PEGASUS_SERVICE_DESCRIPTION
109                     #define PEGASUS_SERVICE_DESCRIPTION "Pegasus WMI Mapper Service";
110 kumpf          1.1  #endif
111                     
112 mateus.baur    1.17 class CIMServerProcess : public ServerProcess
113                     {
114                     public:
115                     
116                         CIMServerProcess(void)
117                         {
118                             cimserver_set_process(this);
119                         }
120                     
121                         virtual ~CIMServerProcess(void)
122                         {
123                         }
124                     
125                         //defined in PegasusVersion.h
126                         virtual const char* getProductName() const
127                         {
128                             return PEGASUS_PRODUCT_NAME;
129                         }
130                     
131                         virtual const char* getExtendedName() const
132                         {
133 mateus.baur    1.17         return PEGASUS_SERVICE_NAME;
134                         }
135                     
136                         virtual const char* getDescription() const
137                         {
138                             return PEGASUS_SERVICE_DESCRIPTION;
139                         }
140                         
141                         //defined in PegasusVersion.h
142                         virtual const char* getVersion() const
143                         {
144                             return PEGASUS_PRODUCT_VERSION;
145                         }
146                     
147                         virtual const char* getProcessName() const
148                         {
149                             return PEGASUS_PROCESS_NAME;
150                         }
151                     
152 mateus.baur    1.32     int cimserver_run(
153                             int argc,
154                             char** argv,
155                             Boolean shutdownOption,
156                             Boolean debugOutputOption);
157 mateus.baur    1.17 
158                         void cimserver_stop(void);
159                     };
160                     
161 kumpf          1.30 ServerRunStatus _serverRunStatus(
162                         PEGASUS_PROCESS_NAME, PEGASUS_CIMSERVER_START_FILE);
163 mateus.baur    1.17 AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess());
164                     static CIMServer* _cimServer = 0;
165 kumpf          1.1  
166                     //
167                     //  The command name.
168                     //
169                     static const char COMMAND_NAME []    = "cimserver";
170                     
171                     //
172                     //  The constant defining usage string.
173                     //
174                     static const char USAGE []           = "Usage: ";
175                     
176                     /**
177                     Constants representing the command line options.
178                     */
179                     static const char OPTION_VERSION     = 'v';
180                     
181                     static const char OPTION_HELP        = 'h';
182                     
183                     static const char OPTION_HOME        = 'D';
184                     
185                     static const char OPTION_SHUTDOWN    = 's';
186 kumpf          1.1  
187 mateus.baur    1.17 static const char   LONG_HELP []  = "help";
188 kumpf          1.3  
189 mateus.baur    1.17 static const char   LONG_VERSION []  = "version";
190 kumpf          1.3  
191 kumpf          1.1  #if defined(PEGASUS_OS_HPUX)
192                     static const char OPTION_BINDVERBOSE = 'X';
193                     #endif
194                     
195                     /** GetOptions function - This function defines the Options Table
196                         and sets up the options from that table using the config manager.
197 kumpf          1.30 
198                         Some possible exceptions:  NoSuchFile, FileNotReadable, CannotRenameFile,
199                         ConfigFileSyntaxError, UnrecognizedConfigProperty, InvalidPropertyValue,
200                         CannotOpenFile.
201 kumpf          1.1  */
202                     void GetOptions(
203                         ConfigManager* cm,
204                         int& argc,
205 mateus.baur    1.17     char** argv)
206 kumpf          1.1  {
207 kumpf          1.30     cm->mergeConfigFiles();
208                         cm->mergeCommandLine(argc, argv);
209 kumpf          1.1  }
210                     
211                     /* PrintHelp - This is temporary until we expand the options manager to allow
212                        options help to be defined with the OptionRow entries and presented from
213                        those entries.
214                     */
215                     void PrintHelp(const char* arg0)
216                     {
217                         String usage = String (USAGE);
218                         usage.append (COMMAND_NAME);
219                         usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
220                         usage.append ("  options\n");
221 mateus.baur    1.36     usage.append("    -v, --version   - displays CIM Server version number\n");
222 mateus.baur    1.17     usage.append ("    -h, --help      - prints this help message\n");
223 kumpf          1.3      usage.append ("    -s              - shuts down CIM Server\n");
224 mateus.baur    1.17 #if !defined(PEGASUS_USE_RELEASE_DIRS)
225 kumpf          1.3      usage.append ("    -D [home]       - sets pegasus home directory\n");
226 kumpf          1.1  #endif
227                     #if defined(PEGASUS_OS_TYPE_WINDOWS)
228 mateus.baur    1.36     usage.append ("    -install [name] - installs pegasus as a Windows "
229                             "Service\n");
230                         usage.append ("                      [name] is optional and overrides "
231                             "the\n");
232 kumpf          1.3      usage.append ("                      default CIM Server Service Name\n");
233 mateus.baur    1.36     usage.append ("    -remove [name]  - removes pegasus as a Windows "
234                             "Service\n");
235                         usage.append ("                      [name] is optional and overrides "
236                             "the\n");
237 kumpf          1.3      usage.append ("                      default CIM Server Service Name\n");
238 mateus.baur    1.36     usage.append ("    -start [name]   - starts pegasus as a Windows "
239                             "Service\n");
240                         usage.append ("                      [name] is optional and overrides "
241                             "the\n");
242 kumpf          1.3      usage.append ("                      default CIM Server Service Name\n");
243 mateus.baur    1.36     usage.append ("    -stop [name]    - stops pegasus as a Windows "
244                             "Service\n");
245                         usage.append ("                      [name] is optional and overrides "
246                             "the\n");
247 kumpf          1.3      usage.append ("                      default CIM Server Service Name\n\n");
248 kumpf          1.1  #endif
249                         usage.append ("  configProperty=value\n");
250 mateus.baur    1.36     usage.append ("                    - sets CIM Server configuration "
251                             "property\n");
252 kumpf          1.1  
253                         cout << endl;
254 mateus.baur    1.36     cout << _cimServerProcess->getProductName() << " " << 
255                             _cimServerProcess->getVersion() << endl;
256 kumpf          1.1      cout << endl;
257 mateus.baur    1.17     
258                     #if defined(PEGASUS_OS_TYPE_WINDOWS)
259                         MessageLoaderParms parms("src.Server.cimserver.MENU.WINDOWS", usage);
260                     #elif defined(PEGASUS_USE_RELEASE_DIRS)
261 mateus.baur    1.36     MessageLoaderParms parms(
262                             "src.Server.cimserver.MENU.HPUXLINUXIA64GNU", usage);
263 mateus.baur    1.17 #else
264                         MessageLoaderParms parms("src.Server.cimserver.MENU.STANDARD", usage);
265                     #endif
266                         cout << MessageLoader::getMessage(parms) << endl;
267                     }
268                     
269 mateus.baur    1.36 // This needs to be called at various points in the code depending on the
270                     // platform and error conditions. We need to delete the _cimServer 
271                     // reference on exit in order for the destructors to get called.
272 mateus.baur    1.17 void deleteCIMServer()
273                     {
274 kumpf          1.34     delete _cimServer;
275                         _cimServer = 0;
276 kumpf          1.1  }
277                     
278 mateus.baur    1.17 // l10n
279 kumpf          1.3  //
280 mateus.baur    1.17 // Dummy function for the Thread object associated with the initial thread.
281                     // Since the initial thread is used to process CIM requests, this is
282                     // needed to localize the exceptions thrown during CIM request processing.
283                     // Note: This function should never be called! 
284                     // 
285 mike           1.26 ThreadReturnType PEGASUS_THREAD_CDECL dummyThreadFunc(void *parm)
286 mateus.baur    1.17 {
287 mike           1.26    return((ThreadReturnType)0);    
288 kumpf          1.3  }
289                     
290 kumpf          1.1  
291                     /////////////////////////////////////////////////////////////////////////
292                     //  MAIN
293                     //////////////////////////////////////////////////////////////////////////
294                     int main(int argc, char** argv)
295                     {
296 kumpf          1.28     String pegasusHome;
297 kumpf          1.1      Boolean shutdownOption = false;
298 mateus.baur    1.32     Boolean debugOutputOption = false;
299 mateus.baur    1.17 
300                     //l10n
301                     // Set Message loading to process locale
302                     MessageLoader::_useProcessLocale = true; 
303                     //l10n
304                     
305                     //l10n
306                     #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_HAS_MESSAGES)
307                     setlocale(LC_ALL, "");
308                     #endif
309 kumpf          1.1  
310 kumpf          1.3  #ifndef PEGASUS_OS_TYPE_WINDOWS
311 kumpf          1.1      //
312                         // Get environment variables:
313                         //
314 mateus.baur    1.17   #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS)
315                         pegasusHome = AIX_RELEASE_PEGASUS_HOME;
316                       #elif !defined(PEGASUS_USE_RELEASE_DIRS)
317 kumpf          1.1      const char* tmp = getenv("PEGASUS_HOME");
318                     
319                         if (tmp)
320                         {
321                             pegasusHome = tmp;
322                         }
323 mateus.baur    1.17   #endif
324 kumpf          1.1  
325                         FileSystem::translateSlashes(pegasusHome);
326 kumpf          1.3  #else
327 kumpf          1.1  
328 kumpf          1.3    // windows only
329 mateus.baur    1.17   //setHome(pegasusHome);
330                       pegasusHome = _cimServerProcess->getHome();
331 kumpf          1.3  #endif
332 kumpf          1.1  
333                             // Get help, version, and shutdown options
334 kumpf          1.3  
335 kumpf          1.1          for (int i = 1; i < argc; )
336                             {
337                                 const char* arg = argv[i];
338 mateus.baur    1.17             if(String::equal(arg,"--help"))
339                                 {
340                                         PrintHelp(argv[0]);
341                                         exit(0);
342                                 }
343                                 else if(String::equal(arg,"--version"))
344                                 {
345                                     cout << _cimServerProcess->getVersion() << endl;
346                                     exit(0);
347                                 }
348 kumpf          1.1              // Check for -option
349 mateus.baur    1.17             else if (*arg == '-')
350 kumpf          1.1              {
351                                     // Get the option
352                                     const char* option = arg + 1;
353                     
354                                     //
355                                     // Check to see if user asked for the version (-v option):
356                                     //
357 kumpf          1.3                  if (*option == OPTION_VERSION &&
358                                         strlen(option) == 1)
359 kumpf          1.1                  {
360 mateus.baur    1.17                     cout << _cimServerProcess->getVersion() << endl;
361 kumpf          1.1                      exit(0);
362                                     }
363                                     //
364                                     // Check to see if user asked for help (-h option):
365                                     //
366 kumpf          1.3                  else if (*option == OPTION_HELP &&
367                                             (strlen(option) == 1))
368 kumpf          1.1                  {
369                                         PrintHelp(argv[0]);
370                                         exit(0);
371                                     }
372 mateus.baur    1.17 #if !defined(PEGASUS_USE_RELEASE_DIRS)
373 kumpf          1.3                  else if (*option == OPTION_HOME &&
374                                             (strlen(option) == 1))
375 kumpf          1.1                  {
376                                         if (i + 1 < argc)
377                                         {
378                                             pegasusHome.assign(argv[i + 1]);
379                                         }
380                                         else
381 mateus.baur    1.36                     {                        
382 mateus.baur    1.17                         String opt(option);
383 mateus.baur    1.36                         MessageLoaderParms parms(
384                                                 "src.Server.cimserver.MISSING_ARGUMENT",
385                                                 "Missing argument for option -$0",
386                                                 opt);
387 mateus.baur    1.17                         cout << MessageLoader::getMessage(parms) << endl;
388 kumpf          1.1                          exit(0);
389                                         }
390                     
391 mateus.baur    1.36                     memmove(&argv[i], &argv[i + 2], 
392                                             (argc-i-1) * sizeof(char*));
393 kumpf          1.1                      argc -= 2;
394                                     }
395                     #endif
396                     #if defined(PEGASUS_OS_HPUX)
397                                     //
398                                     // Check to see if user asked for the version (-X option):
399                                     //
400 kumpf          1.3                  if (*option == OPTION_BINDVERBOSE &&
401                                             (strlen(option) == 1))
402 kumpf          1.1                  {
403 mateus.baur    1.36                     System::bindVerbose = true;
404                                         
405                                         MessageLoaderParms parms(
406                                             "src.Server.cimserver.UNSUPPORTED_DEBUG_OPTION",
407                                             "Unsupported debug option, BIND_VERBOSE, enabled.");
408 mateus.baur    1.17                     cout << MessageLoader::getMessage(parms) << endl;
409 kumpf          1.1                      // remove the option from the command line
410                                         memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
411                                         argc--;   
412                                     }
413                     #endif
414                                     //
415                                     // Check to see if user asked for shutdown (-s option):
416                                     //
417 kumpf          1.3                  else if (*option == OPTION_SHUTDOWN &&
418                                             (strlen(option) == 1))
419 kumpf          1.1                  {
420                                         //
421                                         // Check to see if shutdown has already been specified:
422                                         //
423                                         if (shutdownOption)
424 mateus.baur    1.36                     {   
425                                             MessageLoaderParms parms(
426                                                 "src.Server.cimserver.DUPLICATE_SHUTDOWN_OPTION",
427                                                 "Duplicate shutdown option specified.");
428 mateus.baur    1.17                        
429                                             cout << MessageLoader::getMessage(parms) << endl;
430 kumpf          1.1                          exit(0);
431                                         }
432                     
433                                         shutdownOption = true;
434                      
435                                         // remove the option from the command line
436                                         memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
437                                         argc--;   
438                                     }
439                                     else
440 kumpf          1.3                      i++;
441 kumpf          1.1              }
442                                 else
443 kumpf          1.3                  i++;
444 kumpf          1.1          }
445                     
446                         //
447                         // Set the value for pegasusHome property
448                         //
449                         ConfigManager::setPegasusHome(pegasusHome);
450                     
451                         //
452 mateus.baur    1.17     // Do the plaform specific run
453                         //
454                     
455 mateus.baur    1.32     return _cimServerProcess->platform_run(
456                             argc, argv, shutdownOption, debugOutputOption);
457 mateus.baur    1.17 }
458                     
459                     void CIMServerProcess::cimserver_stop()
460                     {
461                         _cimServer->shutdownSignal();
462                     }
463                     
464                     //
465                     // The main, common, running code
466                     //
467                     // NOTE: Do NOT call exit().  Use return(), otherwise some platforms 
468                     // will fail to shutdown properly/cleanly.
469                     //
470                     // TODO: Current change minimal for platform "service" shutdown bug fixes.  
471                     // Perhpas further extract out common stuff and put into main(), put 
472                     // daemon stuff into platform specific platform_run(), etc.  
473                     // Note: make sure to not put error handling stuff that platform 
474                     // specific runs may need to deal with bettter (instead of exit(), etc).
475                     //
476                     
477 mateus.baur    1.32 int CIMServerProcess::cimserver_run(
478                         int argc,
479                         char** argv,
480                         Boolean shutdownOption,
481                         Boolean debugOutputOption)
482 mateus.baur    1.17 {
483 kumpf          1.28     String logsDirectory;
484 mateus.baur    1.17     Boolean daemonOption = false;
485                     
486                         //
487 kumpf          1.1      // Get an instance of the Config Manager.
488                         //
489 kumpf          1.34     ConfigManager* configManager = ConfigManager::getInstance();
490 kumpf          1.10     configManager->useConfigFiles = true;
491 kumpf          1.1  
492                         //
493                         // Get options (from command line and from configuration file); this
494                         // removes corresponding options and their arguments from the command
495                         // line.
496                         //
497                         try
498 ouyang.jian    1.31     { 
499 mateus.baur    1.17         GetOptions(configManager, argc, argv);
500 kumpf          1.1      }
501                         catch (Exception& e)
502                         {
503 mateus.baur    1.17         MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
504                                 "cimserver not started: $0", e.getMessage());
505                     
506 kumpf          1.39         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
507                                 parms);
508                     
509 mateus.baur    1.36         PEGASUS_STD(cerr) << argv[0] << ": " << 
510                                 MessageLoader::getMessage(parms) << PEGASUS_STD(endl);
511 mateus.baur    1.17 
512                             return(1);
513 kumpf          1.1      }
514                     
515 kumpf          1.3  // l10n
516 h.sterling     1.16     // Set the home directory, msg sub-dir, into the MessageLoader.
517                         // This will be the default directory where the resource bundles 
518 mateus.baur    1.17     // are found.    
519                         MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath(
520                             ConfigManager::getInstance()->getCurrentValue("messageDir")));      
521                     
522 kumpf          1.25     Boolean enableHttpConnection = ConfigManager::parseBooleanValue(
523                             configManager->getCurrentValue("enableHttpConnection"));
524                         Boolean enableHttpsConnection = ConfigManager::parseBooleanValue(
525                             configManager->getCurrentValue("enableHttpsConnection"));
526 kumpf          1.2  
527                         // Make sure at least one connection is enabled
528 h.sterling     1.16 #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
529 kumpf          1.2      if (!enableHttpConnection && !enableHttpsConnection)
530                         {
531 kumpf          1.33         MessageLoaderParms parms(
532                                 "src.Server.cimserver.HTTP_NOT_ENABLED_SERVER_NOT_STARTING",
533                                 "Neither HTTP nor HTTPS connection is enabled.");
534 kumpf          1.39         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
535                                 parms);
536 mateus.baur    1.17         cerr << MessageLoader::getMessage(parms) << endl;
537 kumpf          1.33         return 1;
538 kumpf          1.2      }
539                     #endif
540                     
541 kumpf          1.1      try
542                         {
543                             //
544                             // Check to see if we should Pegasus as a daemon
545                             //
546                     
547 kumpf          1.25         daemonOption = ConfigManager::parseBooleanValue(
548                                 configManager->getCurrentValue("daemon"));
549 ouyang.jian    1.31  
550 kumpf          1.3          logsDirectory = 
551 h.sterling     1.16         ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
552 kumpf          1.1  
553                             // Set up the Logger. This does not open the logs
554                             // Might be more logical to clean before set.
555                             // ATTN: Need tool to completely disable logging.
556                     
557 ouyang.jian    1.31 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
558 kumpf          1.1          Logger::setHomeDirectory(logsDirectory);
559                     #endif
560                     
561                             //
562                             // Check to see if we need to shutdown CIMOM 
563                             //
564                             if (shutdownOption)
565                             {
566                                 String configTimeout = 
567                                     configManager->getCurrentValue("shutdownTimeout");
568 mateus.baur    1.36             Uint32 timeoutValue = strtol(
569                                     configTimeout.getCString(), (char **)0, 10);
570 kumpf          1.30 
571                                 ServerShutdownClient serverShutdownClient(&_serverRunStatus);
572                                 serverShutdownClient.shutdown(timeoutValue);
573 kumpf          1.1  
574 kumpf          1.30             MessageLoaderParms parms(
575                                     "src.Server.cimserver.SERVER_STOPPED",
576                                     "CIM Server stopped.");
577 mateus.baur    1.17 
578                                 cout << MessageLoader::getMessage(parms) << endl;
579                                 return(0);
580 kumpf          1.1          }
581                     
582 kumpf          1.30 #if defined(PEGASUS_DEBUG) && !defined(PEGASUS_USE_SYSLOGS)
583 kumpf          1.1          // Leave this in until people get familiar with the logs.
584 mateus.baur    1.17         MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY",
585                                                      "Logs Directory = ");
586                             cout << MessageLoader::getMessage(parms) << logsDirectory << endl;
587 kumpf          1.1  #endif
588                         }
589 kumpf          1.5      catch (UnrecognizedConfigProperty& e)
590 kumpf          1.1      {
591 mateus.baur    1.17     //l10n
592                         //cout << "Error: " << e.getMessage() << endl;
593                         MessageLoaderParms parms("src.Server.cimserver.ERROR",
594                                                  "Error: $0",
595                                                  e.getMessage());
596                         cout << MessageLoader::getMessage(parms) << endl;
597 kumpf          1.1      }
598                     
599 mateus.baur    1.36     // Bug 2148 - Here is the order of operations for determining the server 
600                         // HTTP and HTTPS ports.
601 mateus.baur    1.17     // 1) If the user explicitly specified a port, use it.
602 mateus.baur    1.36     // 2) If the user did not specify a port, get the port from the 
603                         //    services file.
604                         // 3) If no value is specified in the services file, use the IANA WBEM 
605                         //    default port.
606 mateus.baur    1.17     // Note that 2 and 3 are done within the System::lookupPort method
607 mateus.baur    1.36     // An empty string from the ConfigManager implies that the user did 
608                         // not specify a port.
609 mateus.baur    1.17 
610                         Uint32 portNumberHttps=0;
611                         Uint32 portNumberHttp=0;
612                         Uint32 portNumberExportHttps=0;
613 kumpf          1.1  
614 kumpf          1.2      if (enableHttpsConnection)
615 kumpf          1.1      {
616 kumpf          1.2          String httpsPort = configManager->getCurrentValue("httpsPort");
617 mateus.baur    1.17         if (httpsPort == String::EMPTY)
618                             {
619                                 //
620                                 // Look up the WBEM-HTTPS port number
621                                 //
622 mateus.baur    1.36             portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, 
623                                     WBEM_DEFAULT_HTTPS_PORT);
624 mateus.baur    1.17 
625                             } else
626                             {        
627                                 //
628                                 // user-specified
629                                 //
630                                 CString portString = httpsPort.getCString();
631                                 char* end = 0;
632                                 portNumberHttps = strtol(portString, &end, 10);
633                                 if(!(end != 0 && *end == '\0'))
634                                 {
635 mateus.baur    1.18                 InvalidPropertyValue e("httpsPort", httpsPort);
636                                     cerr << e.getMessage() << endl;
637 mateus.baur    1.17                 exit(1);
638                                 }
639                             }
640 kumpf          1.1      }
641 kumpf          1.2  
642                         if (enableHttpConnection)
643 kumpf          1.1      {
644 kumpf          1.2          String httpPort = configManager->getCurrentValue("httpPort");
645 mateus.baur    1.17         if (httpPort == String::EMPTY)
646                             {
647                                 //
648                                 // Look up the WBEM-HTTP port number
649                                 //
650 mateus.baur    1.36             portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, 
651                                     WBEM_DEFAULT_HTTP_PORT);
652 kumpf          1.1  
653 mateus.baur    1.17         } else
654                             {
655                                 //
656                                 // user-specified
657                                 //
658                                 CString portString = httpPort.getCString();
659                                 char* end = 0;
660                                 portNumberHttp = strtol(portString, &end, 10);
661                                 if(!(end != 0 && *end == '\0'))
662                                 {
663 mateus.baur    1.18                 InvalidPropertyValue e("httpPort", httpPort);
664                                     cerr << e.getMessage() << endl;
665 mateus.baur    1.17                 exit(1);
666                                 }
667                             }
668 kumpf          1.1      }
669                     
670 mateus.baur    1.17 #if defined(PEGASUS_DEBUG)
671 kumpf          1.1      // Put out startup up message.
672 kumpf          1.33     cout << _cimServerProcess->getProductName() << " " <<
673                             _cimServerProcess->getVersion() << endl;
674 mateus.baur    1.17 #endif
675                     
676 kumpf          1.33     // reset message loading to NON-process locale
677                         MessageLoader::_useProcessLocale = false; 
678 kumpf          1.3  
679 mateus.baur    1.17     // Get the parent's PID before forking
680 kumpf          1.30     _serverRunStatus.setParentPid(System::getPID());
681 mateus.baur    1.17     
682 kumpf          1.1      // do we need to run as a daemon ?
683                         if (daemonOption)
684                         {
685 mateus.baur    1.17         if(-1 == _cimServerProcess->cimserver_fork())
686                         {
687                             return(-1);
688 h.sterling     1.16     }
689 kumpf          1.1      }
690                     
691 mateus.baur    1.17 // l10n
692                         // Now we are after the fork...
693                         // Create a dummy Thread object that can be used to store the
694 kumpf          1.22     // AcceptLanguageList object for CIM requests that are serviced
695 mateus.baur    1.17     // by this thread (initial thread of server).  Need to do this
696                         // because this thread is not in a ThreadPool, but is used
697                         // to service CIM requests.
698                         // The run function for the dummy Thread should never be called,
699                         Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false);
700                         Thread::setCurrent(dummyInitialThread); 
701 kumpf          1.38     try
702                         {
703                              Thread::setLanguages(LanguageParser::getDefaultAcceptLanguages());
704                         }
705                         catch(InvalidAcceptLanguageHeader& e)
706                         {
707 mateus.baur    1.17           Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
708 kumpf          1.39               MessageLoaderParms(
709 mateus.baur    1.17                   "src.Server.cimserver.FAILED_TO_SET_PROCESS_LOCALE",
710 mateus.baur    1.36                   "Could not convert the system process locale into "
711 kumpf          1.39                         "a valid AcceptLanguage format."));
712 mateus.baur    1.17           Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
713                                                  e.getMessage()); 
714                         }
715                         
716                     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \
717 r.kieninger    1.40 || defined(PEGASUS_OS_ZOS) || defined(PEGASUS_OS_AIX) \
718 jim.wunderlich 1.19 || defined(PEGASUS_OS_SOLARIS) || defined (PEGASUS_OS_VMS)
719 kumpf          1.1      umask(S_IWGRP|S_IWOTH);
720 kumpf          1.2  
721                         //
722                         // check if CIMServer is already running
723                         // if CIMServer is already running, print message and 
724                         // notify parent process (if there is a parent process) to terminate
725                         //
726 kumpf          1.30     if (_serverRunStatus.isServerRunning())
727 kumpf          1.2      {
728 kumpf          1.30         MessageLoaderParms parms(
729                                 "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING",
730                                 "Unable to start CIMServer.\nCIMServer is already running.");
731                             PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) <<
732                                 PEGASUS_STD(endl);
733 kumpf          1.2  
734 kumpf          1.30         //
735 kumpf          1.2          // notify parent process (if there is a parent process) to terminate
736                             //
737                             if (daemonOption)
738 kumpf          1.30         {
739                                 _cimServerProcess->notify_parent(1);
740                             }
741 kumpf          1.2  
742 kumpf          1.30         return 1;
743 kumpf          1.2      }
744                          
745 kumpf          1.1  #endif
746                     
747                         // try loop to bind the address, and run the server
748                         try
749                         {
750 kumpf          1.34         _cimServer = new CIMServer();
751 mateus.baur    1.17 
752 kumpf          1.2  
753                             if (enableHttpConnection)
754                             {
755 dave.sudlik    1.35 #ifdef PEGASUS_ENABLE_IPV6
756                                 _cimServer->addAcceptor(HTTPAcceptor::IPV6_CONNECTION,
757                                     portNumberHttp, false);
758                     #endif
759                     
760                     #if !defined (PEGASUS_ENABLE_IPV6) || defined (PEGASUS_OS_TYPE_WINDOWS)
761                                 _cimServer->addAcceptor(HTTPAcceptor::IPV4_CONNECTION,
762                                     portNumberHttp, false);
763                     #endif
764 kumpf          1.30 
765                                 Logger::put_l(
766                                     Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
767 kumpf          1.39                 MessageLoaderParms(
768                                         "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
769                                         "Listening on HTTP port $0.", portNumberHttp));
770 kumpf          1.2          }
771 kumpf          1.30 
772 kumpf          1.2          if (enableHttpsConnection)
773                             {
774 dave.sudlik    1.35 #ifdef PEGASUS_ENABLE_IPV6
775                                 _cimServer->addAcceptor(HTTPAcceptor::IPV6_CONNECTION,
776                                     portNumberHttps, true);
777                     #endif
778                     
779                     #if !defined (PEGASUS_ENABLE_IPV6) || defined (PEGASUS_OS_TYPE_WINDOWS)
780                                 _cimServer->addAcceptor(HTTPAcceptor::IPV4_CONNECTION,
781                                     portNumberHttps, true);
782                     #endif
783 kumpf          1.30 
784                                 Logger::put_l(
785                                     Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
786 kumpf          1.39                 MessageLoaderParms(
787                                         "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
788                                         "Listening on HTTPS port $0.", portNumberHttps));
789 mateus.baur    1.17         }
790 kumpf          1.9  
791 h.sterling     1.16 #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
792 dave.sudlik    1.35         _cimServer->addAcceptor(HTTPAcceptor::LOCAL_CONNECTION, 0, false);
793                     
794 kumpf          1.30         Logger::put_l(
795                                 Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
796 kumpf          1.39             MessageLoaderParms(
797                                     "src.Server.cimserver.LISTENING_ON_LOCAL",
798                                     "Listening on local connection socket."));
799 kumpf          1.1  #endif
800                     
801 mateus.baur    1.17 #if defined(PEGASUS_DEBUG)
802 kumpf          1.2          if (enableHttpConnection)
803                             {
804 kumpf          1.30             MessageLoaderParms parms(
805                                     "src.Server.cimserver.LISTENING_ON_HTTP_PORT",
806                                     "Listening on HTTP port $0.", portNumberHttp);
807 mateus.baur    1.17             cout << MessageLoader::getMessage(parms) << endl;
808 kumpf          1.2          }
809                             if (enableHttpsConnection)
810                             {
811 kumpf          1.30             MessageLoaderParms parms(
812                                     "src.Server.cimserver.LISTENING_ON_HTTPS_PORT",
813                                     "Listening on HTTPS port $0.", portNumberHttps);
814 mateus.baur    1.17             cout << MessageLoader::getMessage(parms) << endl;
815                             }
816 kumpf          1.9  
817 h.sterling     1.16 # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET
818 kumpf          1.30         MessageLoaderParms parms(
819                                 "src.Server.cimserver.LISTENING_ON_LOCAL",
820                                 "Listening on local connection socket.");
821 mateus.baur    1.17         cout << MessageLoader::getMessage(parms) << endl;
822 kumpf          1.3  # endif
823 kumpf          1.1  #endif
824                     
825 kumpf          1.3          // bind throws an exception if the bind fails
826 kumpf          1.37         _cimServer->bind();
827 kumpf          1.1  
828 kumpf          1.30         // notify parent process (if there is a parent process) to terminate 
829 kumpf          1.3          // so user knows that there is cimserver ready to serve CIM requests.
830 kumpf          1.30         if (daemonOption)
831                             {
832                                 _cimServerProcess->notify_parent(0);
833                             }
834 kumpf          1.2  
835 kumpf          1.30 #if defined(PEGASUS_OS_HPUX) || \
836                         defined(PEGASUS_OS_LINUX) || \
837 r.kieninger    1.40     defined(PEGASUS_OS_ZOS) || \
838 kumpf          1.30     defined(PEGASUS_OS_AIX) || \
839                         defined(PEGASUS_OS_SOLARIS) || \
840                         defined(PEGASUS_OS_VMS)
841 kumpf          1.1          //
842                             // create a file to indicate that the cimserver has started and
843                             // save the process id of the cimserver process in the file
844                             //
845 kumpf          1.30         _serverRunStatus.setServerRunning();
846 kumpf          1.1  #endif
847 kumpf          1.3  
848 mateus.baur    1.17 #if defined(PEGASUS_DEBUG)
849 h.sterling     1.16     cout << "Started. " << endl;
850 kumpf          1.1  #endif
851 mateus.baur    1.17     
852 kumpf          1.1          // Put server started message to the logger
853 mateus.baur    1.17         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
854                                 Logger::INFORMATION,
855 kumpf          1.39             MessageLoaderParms(
856                                     "src.Server.cimserver.STARTED_VERSION",
857                                     "Started $0 version $1.",
858                                     _cimServerProcess->getProductName(), 
859                                     _cimServerProcess->getVersion()));
860 kumpf          1.1  
861 kumpf          1.3          //
862 kumpf          1.1          // Loop to call CIMServer's runForever() method until CIMServer
863                             // has been shutdown
864                             //
865 mateus.baur    1.17     while( !_cimServer->terminated() )
866 h.sterling     1.16     {
867 mateus.baur    1.17 
868                           _cimServer->runForever();
869                     
870 h.sterling     1.16     }
871 kumpf          1.1  
872                             //
873                             // normal termination
874 mateus.baur    1.17         //
875 kumpf          1.12 
876 kumpf          1.1          // Put server shutdown message to the logger
877 mateus.baur    1.17         Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
878 kumpf          1.39             Logger::INFORMATION,
879                                 MessageLoaderParms(
880                                     "src.Server.cimserver.STOPPED",
881                                     "$0 stopped.", _cimServerProcess->getProductName()));
882 kumpf          1.1      }
883 kumpf          1.33     catch (Exception& e)
884 kumpf          1.1      {
885 kumpf          1.37         MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED",
886                                 "cimserver not started: $0", e.getMessage());
887 kumpf          1.39         Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
888                                 parms);
889 kumpf          1.37         cerr << MessageLoader::getMessage(parms) << endl;
890 mateus.baur    1.17 
891 kumpf          1.33         //
892 kumpf          1.3          // notify parent process (if there is a parent process) to terminate
893 kumpf          1.2          //
894                             if (daemonOption)
895 mateus.baur    1.17                 _cimServerProcess->notify_parent(1);
896 kumpf          1.2  
897 mateus.baur    1.17         deleteCIMServer();
898 kumpf          1.1          return 1;
899                         }
900                     
901 mateus.baur    1.17     deleteCIMServer();
902 kumpf          1.1      return 0;
903                     }
904 mateus.baur    1.17 

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2