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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2