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

  1 kumpf 1.1 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3           // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4           // The Open Group, Tivoli Systems
  5           //
  6           // Permission is hereby granted, free of charge, to any person obtaining a copy
  7           // of this software and associated documentation files (the "Software"), to
  8           // deal in the Software without restriction, including without limitation the
  9           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10           // sell copies of the Software, and to permit persons to whom the Software is
 11           // furnished to do so, subject to the following conditions:
 12           // 
 13           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21           //
 22 kumpf 1.1 //==============================================================================
 23           //
 24           // Author: Mike Brasher (mbrasher@bmc.com)
 25           //
 26           // Modified By: Mike Day (mdday@us.ibm.com) 
 27           //
 28           // Modified By:	Karl Schopmeyer (k.schopmeyer@opengroup.org)
 29           //
 30           // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
 31           //
 32           // Modified By: Jenny Yu (jenny_yu@hp.com)
 33           //
 34           // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
 35 kumpf 1.2 //              Carol Ann Krug Graves, Hewlett-Packard Company
 36           //                (carolann_graves@hp.com)
 37           //		Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
 38 kumpf 1.1 //
 39           //%/////////////////////////////////////////////////////////////////////////////
 40           
 41           
 42           //////////////////////////////////////////////////////////////////////
 43           //
 44           // Notes on deamon operation (Unix) and service operation (Win 32):
 45           //
 46           // To run pegasus as a daemon on Unix platforms: 
 47           //
 48           // cimserver
 49           //
 50           // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
 51           // property to false:
 52           //
 53           // cimserver daemon=false
 54           //
 55           // The daemon config property has no effect on windows operation. 
 56           //
 57           // To shutdown pegasus, use the -s option:
 58           // 
 59 kumpf 1.1 // cimserver -s 
 60           //
 61           // To run pegasus as an NT service, there are FOUR  different possibilities:
 62           //
 63           // To INSTALL the Pegasus service, 
 64           //
 65           // cimserver -install
 66           //
 67           // To REMOVE the Pegasus service, 
 68           //
 69           // cimserver -remove
 70           //
 71           // To START the Pegasus service, 
 72           //
 73           // net start cimserver
 74           //
 75           // To STOP the Pegasus service, 
 76           //
 77           // net stop cimserver
 78           //
 79           // Alternatively, you can use the windows service manager. Pegasus shows up 
 80 kumpf 1.1 // in the service database as "Pegasus CIM Object Manager"
 81           //
 82           // Mike Day, mdday@us.ibm.com
 83           // 
 84           //////////////////////////////////////////////////////////////////////
 85           
 86           
 87           #include <Pegasus/Common/Config.h>
 88           #include <Pegasus/Common/Constants.h>
 89           #include <iostream>
 90           #include <cassert>
 91           #include <cstdlib>
 92           #include <fstream>
 93           #include <Pegasus/Common/FileSystem.h>
 94           #include <Pegasus/Common/Monitor.h>
 95           #include <WMIMapper/PegServer/CIMServer.h>
 96           #include <Pegasus/Common/PegasusVersion.h>
 97           #include <Pegasus/Common/Logger.h>
 98           #include <Pegasus/Common/System.h>
 99           #include <Pegasus/Common/Tracer.h>
100           #include <Pegasus/Config/ConfigManager.h>
101 kumpf 1.1 #include <Pegasus/Client/CIMClient.h>
102           #include <Pegasus/Server/ShutdownService.h>
103           #include <Pegasus/Common/Destroyer.h>
104 kumpf 1.2 
105           #if !defined(PEGASUS_OS_ZOS) && !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_NO_SLP)
106 kumpf 1.1 #include <slp/slp.h>
107           #endif
108           
109           #if defined(PEGASUS_OS_TYPE_WINDOWS)
110           # include "cimserver_windows.cpp"
111           #elif defined(PEGASUS_OS_TYPE_UNIX)
112           # if defined(PEGASUS_OS_OS400)
113           #  include "cimserver_os400.cpp"
114           # else
115           #  include "cimserver_unix.cpp"
116           #endif
117           #else
118           # error "Unsupported platform"
119           #endif
120           
121           PEGASUS_USING_PEGASUS;
122           PEGASUS_USING_STD;
123           
124           //
125           //  The command name.
126           //
127 kumpf 1.1 static const char COMMAND_NAME []    = "cimserver";
128           
129           //
130           //  The constant defining usage string.
131           //
132           static const char USAGE []           = "Usage: ";
133           
134           /**
135           Constants representing the command line options.
136           */
137           static const char OPTION_VERSION     = 'v';
138           
139           static const char OPTION_HELP        = 'h';
140           
141           static const char OPTION_HOME        = 'D';
142           
143           static const char OPTION_SHUTDOWN    = 's';
144           
145           #if defined(PEGASUS_OS_HPUX)
146           static const char OPTION_BINDVERBOSE = 'X';
147           #endif
148 kumpf 1.1 
149           static const String PROPERTY_TIMEOUT = "shutdownTimeout";
150           static const String CIMSERVERSTART_FILE = "/etc/opt/wbem/cimserver_start.conf";
151           
152           ConfigManager*    configManager;
153           
154           /** GetOptions function - This function defines the Options Table
155               and sets up the options from that table using the config manager.
156           */
157           void GetOptions(
158               ConfigManager* cm,
159               int& argc,
160               char** argv,
161               const String& pegasusHome)
162           {
163               try
164               {
165                   cm->mergeConfigFiles();
166           
167                   cm->mergeCommandLine(argc, argv);
168               }
169 kumpf 1.1     catch (NoSuchFile nsf)
170               {
171                   throw nsf;
172               }
173               catch (FileNotReadable fnr)
174               {
175                   throw fnr;
176               }
177               catch (CannotRenameFile ftrf)
178               {
179                   throw ftrf;
180               }
181               catch (ConfigFileSyntaxError cfse)
182               {
183                   throw cfse;
184               }
185               catch(UnrecognizedConfigProperty ucp)
186               {
187                   throw ucp;
188               }
189               catch(InvalidPropertyValue ipv)
190 kumpf 1.1     {
191                   throw ipv;
192               }
193           }
194           
195           /* PrintHelp - This is temporary until we expand the options manager to allow
196              options help to be defined with the OptionRow entries and presented from
197              those entries.
198           */
199           void PrintHelp(const char* arg0)
200           {
201               /**
202                   Build the usage string for the config command.
203               */
204               String usage = String (USAGE);
205               usage.append (COMMAND_NAME);
206               usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
207               usage.append ("  options\n");
208               usage.append ("    -v          - displays CIM Server version number\n");
209               usage.append ("    -h          - prints this help message\n");
210               usage.append ("    -s          - shuts down CIM Server\n");
211 kumpf 1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
212 kumpf 1.1     usage.append ("    -D [home]   - sets pegasus home directory\n");
213           #endif
214           #if defined(PEGASUS_OS_TYPE_WINDOWS)
215               usage.append ("    -install    - installs pegasus as a Windows NT Service\n");
216               usage.append ("    -remove     - removes pegasus as a Windows NT Service\n");
217           #endif
218               usage.append ("  configProperty=value\n");
219               usage.append ("                - sets CIM Server configuration property\n");
220           
221               cout << endl;
222 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
223 kumpf 1.1     cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
224           #else
225               cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
226           #endif
227               cout << endl;
228               cout << usage << endl;
229           }
230           
231           void shutdownCIMOM(Uint32 timeoutValue)
232           {
233               //
234               // Create CIMClient object
235               //
236               CIMClient client;
237           
238               //
239               // Get local host name
240               //
241               String hostStr = System::getHostName();
242           
243               //
244 kumpf 1.1     // open connection to CIMOM 
245               //
246               try
247               {
248                   client.connectLocal();
249           
250                   //
251                   // set client timeout to 2 seconds
252                   //
253                   client.setTimeout(2000);
254               }
255               catch(Exception& e)
256               {
257                   PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
258                   PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
259           #ifdef PEGASUS_OS_OS400
260                   // The server job may still be active but not responding.
261                   // Kill the job if it exists.
262           	cimserver_kill();
263 kumpf 1.2 	return;
264 kumpf 1.1 #endif
265                   exit(0);
266               }
267           
268               try
269               {
270                   //
271                   // construct CIMObjectPath
272                   //
273                   String referenceStr = "//";
274                   referenceStr.append(hostStr);
275 kumpf 1.2         referenceStr.append("/");  
276                   referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
277 kumpf 1.1         referenceStr.append(":");
278 kumpf 1.2         referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
279 kumpf 1.1         CIMObjectPath reference(referenceStr);
280           
281                   //
282                   // issue the invokeMethod request on the shutdown method
283                   //
284                   Array<CIMParamValue> inParams;
285                   Array<CIMParamValue> outParams;
286           
287                   // set force option to true for now
288                   inParams.append(CIMParamValue("force",
289                       CIMValue(Boolean(true))));
290           
291                   inParams.append(CIMParamValue("timeout",
292                       CIMValue(Uint32(timeoutValue))));
293           
294                   CIMValue retValue = client.invokeMethod(
295                       PEGASUS_NAMESPACENAME_SHUTDOWN,
296                       reference,
297                       "shutdown",
298                       inParams,
299                       outParams);
300 kumpf 1.1     }
301               catch(CIMException& e)
302               {
303                   PEGASUS_STD(cerr) << "Failed to shutdown server: ";
304                   if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
305                   {
306                       PEGASUS_STD(cerr) << "The repository may be empty.";
307                       PEGASUS_STD(cerr) << PEGASUS_STD(endl);
308                   }
309                   else
310                   {
311                       PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
312                   }
313           #ifdef PEGASUS_OS_OS400
314                   // Kill the server job.
315           	cimserver_kill();
316 kumpf 1.2 	return;
317 kumpf 1.1 #endif
318                   exit(1);
319               }
320               catch(Exception& e)
321               {
322                   //
323                   // This may mean the CIM Server has been terminated and returns a 
324                   // "Empty HTTP response message" HTTP error response.  To be sure
325                   // CIM Server gets shutdown, if CIM Server is still running at 
326                   // this time, we will kill the cimserver process.
327                   //
328                   // give CIM Server some time to finish up
329                   //
330                   //System::sleep(1);
331                   //cimserver_kill();
332           
333                   //
334                   // Check to see if CIMServer is still running.  If CIMServer
335                   // is still running and the shutdown timeout has not expired,
336                   // loop and wait one second until either CIM Server is
337                   // terminated or until timeout expires.  If timeout expires
338 kumpf 1.1         // and CIMServer is still running, kill the CIMServer
339                   // process.
340                   //
341                   Uint32 maxWaitTime = timeoutValue - 2;
342                   Boolean running = isCIMServerRunning();
343                   while ( running && maxWaitTime > 0 )
344                   {
345                       System::sleep(1);
346                       running = isCIMServerRunning();
347                       maxWaitTime = maxWaitTime - 1;
348                   }
349           
350                   if (running)
351                   {
352                       cimserver_kill();
353                   }
354               }
355               //catch(Exception& e)
356               //{
357               //    PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: ";
358               //    PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
359 kumpf 1.1     //    exit(1);
360               //}
361           
362               return;
363           }
364           
365           
366           /////////////////////////////////////////////////////////////////////////
367           //  MAIN
368           //////////////////////////////////////////////////////////////////////////
369           int main(int argc, char** argv)
370           {
371               String pegasusHome  = String::EMPTY;
372               Boolean pegasusIOLog = false;
373               String logsDirectory = String::EMPTY;
374               Boolean useSLP = false;
375               Boolean daemonOption = false;
376               Boolean shutdownOption = false;
377               Uint32 timeoutValue  = 0;
378           
379           #ifdef PEGASUS_OS_OS400
380 kumpf 1.1     // Initialize Pegasus home to the shipped OS/400 directory.
381               pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
382           #endif
383           
384               //
385               // Get environment variables:
386               //
387               const char* tmp = getenv("PEGASUS_HOME");
388           
389               if (tmp)
390               {
391                   pegasusHome = tmp;
392               }
393           
394               FileSystem::translateSlashes(pegasusHome);
395           
396               // on Windows NT if there are no command-line options, run as a service
397           
398               if (argc == 1 )
399               {
400 kumpf 1.2 		cim_server_service(argc, argv);
401 kumpf 1.1     }
402               else
403               {
404                   // Get help, version, and shutdown options
405                   for (int i = 1; i < argc; )
406                   {
407                       const char* arg = argv[i];
408           
409                       // Check for -option
410                       if (*arg == '-')
411                       {
412                           // Get the option
413                           const char* option = arg + 1;
414           
415                           //
416                           // Check to see if user asked for the version (-v option):
417                           //
418                           if (*option == OPTION_VERSION)
419                           {
420 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
421 kumpf 1.1                     cout << PLATFORM_PRODUCT_VERSION << endl;
422           #else
423                               cout << PEGASUS_VERSION << endl;
424           #endif
425                               exit(0);
426                           }
427                           //
428                           // Check to see if user asked for help (-h option):
429                           //
430                           else if (*option == OPTION_HELP)
431                           {
432                               PrintHelp(argv[0]);
433                               exit(0);
434                           }
435 kumpf 1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
436 kumpf 1.1                 else if (*option == OPTION_HOME)
437                           {
438                               if (i + 1 < argc)
439                               {
440                                   pegasusHome.assign(argv[i + 1]);
441                               }
442                               else
443                               {
444                                   cout << "Missing argument for option -" << option << endl;
445                                   exit(0);
446                               }
447           
448                               memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
449                               argc -= 2;
450                           }
451           #endif
452           #if defined(PEGASUS_OS_HPUX)
453                           //
454                           // Check to see if user asked for the version (-X option):
455                           //
456                           if (*option == OPTION_BINDVERBOSE)
457 kumpf 1.1                 {
458 kumpf 1.2 					System::bindVerbose = true;
459 kumpf 1.1                     cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
460                                    << endl;
461                               // remove the option from the command line
462                               memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
463                               argc--;   
464                           }
465           #endif
466                           //
467                           // Check to see if user asked for shutdown (-s option):
468                           //
469                           else if (*option == OPTION_SHUTDOWN)
470                           {
471                               //
472                               // check to see if user is root
473                               //
474 kumpf 1.2 #ifndef PEGASUS_OS_OS400
475 kumpf 1.1                     if (!System::isPrivilegedUser(System::getEffectiveUserName()))
476                               {
477                                   cout << "You must have superuser privilege to run ";
478                                   cout << "cimserver." << endl;
479                                   exit(0);
480                               }
481 kumpf 1.2 #endif
482 kumpf 1.1 
483                               //
484                               // Check to see if shutdown has already been specified:
485                               //
486                               if (shutdownOption)
487                               {
488                                   cout << "Duplicate shutdown option specified." << endl;
489                                   exit(0);
490                               }
491           
492                               shutdownOption = true;
493            
494                               // remove the option from the command line
495                               memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
496                               argc--;   
497                           }
498                           else
499 kumpf 1.2 					i++;
500 kumpf 1.1             }
501                       else
502 kumpf 1.2 				i++;
503 kumpf 1.1         }
504               }
505           
506               //
507               // Set the value for pegasusHome property
508               //
509               ConfigManager::setPegasusHome(pegasusHome);
510           
511               //
512               // Get an instance of the Config Manager.
513               //
514               configManager = ConfigManager::getInstance();
515           
516               //
517               // Get options (from command line and from configuration file); this
518               // removes corresponding options and their arguments from the command
519               // line.
520               //
521               try
522               {
523                   GetOptions(configManager, argc, argv, pegasusHome);
524 kumpf 1.1     }
525               catch (Exception& e)
526               {
527                   cerr << argv[0] << ": " << e.getMessage() << endl;
528                   exit(1);
529               }
530           
531 kumpf 1.2     // The "SSL" property overrides the enableHttp*Connection properties and
532               // enables only the HTTPS connection.
533               Boolean enableHttpConnection = String::equal(
534           		configManager->getCurrentValue("enableHttpConnection"), "true");
535           
536           	Boolean enableHttpsConnection = String::equal(
537           		configManager->getCurrentValue("enableHttpsConnection"), "true");
538           
539               // Make sure at least one connection is enabled
540           #ifndef PEGASUS_LOCAL_DOMAIN_SOCKET
541               if (!enableHttpConnection && !enableHttpsConnection)
542               {
543                   Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
544                       "Neither HTTP nor HTTPS connection is enabled.  "
545                       "CIMServer will not be started.");
546                   
547           		cerr << "Neither HTTP nor HTTPS connection is enabled.  "
548                       "CIMServer will not be started." << endl;
549                   
550           		exit(1);
551               }
552 kumpf 1.2 #endif
553           
554 kumpf 1.1     try
555               {
556                   //
557                   // Check to see if we should (can) install as a NT service
558                   //
559           
560                   if (String::equal(configManager->getCurrentValue("install"), "true"))
561                   {
562                       if( 0 != cimserver_install_nt_service( pegasusHome ))
563                       {
564                           cout << "\nPegasus installed as NT Service";
565                           exit(0);
566                       }
567                   }
568           
569                   //
570                   // Check to see if we should (can) remove Pegasus as an NT service
571                   //
572           
573                   if (String::equal(configManager->getCurrentValue("remove"), "true"))
574                   {
575 kumpf 1.1             if( 0 != cimserver_remove_nt_service() )
576                       {
577                           cout << "\nPegasus removed as NT Service";
578                           exit(0);
579                       }
580                   }
581           
582                   //
583                   // Check to see if we should Pegasus as a daemon
584                   //
585           
586                   if (String::equal(configManager->getCurrentValue("daemon"), "true"))
587                   {
588                       daemonOption = true;
589                   }
590           	
591                   //
592                   // Check the log trace options and set global variable
593                   //
594           
595                   if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
596 kumpf 1.1         {
597                       pegasusIOLog = true;
598                   }
599           
600                   // Get the log file directory definition.
601                   // We put String into Cstring because
602                   // Directory functions only handle Cstring.
603                   // ATTN-KS: create String based directory functions.
604           
605                   logsDirectory = configManager->getCurrentValue("logdir");
606 kumpf 1.2         logsDirectory = ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
607 kumpf 1.1 
608                   // Set up the Logger. This does not open the logs
609                   // Might be more logical to clean before set.
610                   // ATTN: Need tool to completely disable logging.
611           
612 kumpf 1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
613 kumpf 1.1         Logger::setHomeDirectory(logsDirectory);
614           #endif
615           
616                   //
617                   // Check to see if we need to shutdown CIMOM 
618                   //
619                   if (shutdownOption)
620                   {
621                       String configTimeout = 
622                           configManager->getCurrentValue("shutdownTimeout");
623                       timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
624                       
625                       shutdownCIMOM(timeoutValue);
626           
627                       cout << "CIM Server stopped." << endl;
628 kumpf 1.2 #ifdef PEGASUS_OS_OS400
629           			return(0);
630           #endif
631 kumpf 1.1             exit(0);
632                   }
633           
634                   // Leave this in until people get familiar with the logs.
635 kumpf 1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
636 kumpf 1.1         cout << "Logs Directory = " << logsDirectory << endl;
637           #endif
638           
639                   if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
640                   {
641                       Logger::clean(logsDirectory);;
642                   }
643           
644                   if (String::equal(configManager->getCurrentValue("slp"), "true"))
645                   {
646                       useSLP =  true;
647                   }
648               }
649               catch (UnrecognizedConfigProperty e)
650               {
651                   cout << "Error: " << e.getMessage() << endl;
652               }
653           
654 kumpf 1.2     Uint32 portNumberHttps;
655               Uint32 portNumberHttp;
656 kumpf 1.1 
657 kumpf 1.2     if (enableHttpsConnection)
658 kumpf 1.1     {
659 kumpf 1.2         String httpsPort = configManager->getCurrentValue("httpsPort");
660 kumpf 1.1         CString portString = httpsPort.getCString();
661 kumpf 1.2 		char* end = 0;
662           		Uint32 port = strtol(portString, &end, 10);
663           		assert(end != 0 && *end == '\0');
664 kumpf 1.1 
665                   //
666                   // Look up the WBEM-HTTPS port number 
667                   //
668 kumpf 1.2         portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
669 kumpf 1.1     }
670 kumpf 1.2 
671               if (enableHttpConnection)
672 kumpf 1.1     {
673 kumpf 1.2         String httpPort = configManager->getCurrentValue("httpPort");
674 kumpf 1.1         CString portString = httpPort.getCString();
675 kumpf 1.2 		char* end = 0;
676           		Uint32 port = strtol(portString, &end, 10);
677           		assert(end != 0 && *end == '\0');
678 kumpf 1.1 
679                   //
680                   // Look up the WBEM-HTTP port number 
681                   //
682 kumpf 1.2         portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
683 kumpf 1.1     }
684           
685               // Put out startup up message.
686 kumpf 1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
687               cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
688 kumpf 1.1     cout << "Built " << __DATE__ << " " << __TIME__ << endl;
689 kumpf 1.2     cout << "Starting..."
690 kumpf 1.1          << (pegasusIOLog ? " Tracing to Log ": " ")
691 kumpf 1.2 	     << (useSLP ? " SLP reg. " : " No SLP ")
692           	     << endl;
693 kumpf 1.1 #endif
694               // do we need to run as a daemon ?
695               if (daemonOption)
696               {
697                   if(-1 == cimserver_fork())
698 kumpf 1.2 #ifndef PEGASUS_OS_OS400
699 kumpf 1.1           exit(-1);
700 kumpf 1.2 #else
701                     return(-1);
702           	else
703           	  return(0);
704           #endif
705 kumpf 1.1     }
706           
707           #ifdef PEGASUS_OS_OS400
708               // Special server initialization code for OS/400.
709               if (cimserver_initialize() != 0)
710               {
711                  // do some logging here!
712                  exit(-1);
713               } 
714           #endif
715           
716           #ifdef PEGASUS_OS_HPUX
717               umask(S_IWGRP|S_IWOTH);
718 kumpf 1.2 
719               //
720               // check if CIMServer is already running
721               // if CIMServer is already running, print message and 
722               // notify parent process (if there is a parent process) to terminate
723               //
724               if(isCIMServerRunning())
725               {
726           	cout << "Unable to start CIMServer." << endl;
727           	cout << "CIMServer is already running." << endl;
728           
729           	//
730                   // notify parent process (if there is a parent process) to terminate
731                   //
732                   if (daemonOption)
733                           notify_parent();
734           
735                   exit(1);
736               }
737                
738 kumpf 1.1 #endif
739           
740               // try loop to bind the address, and run the server
741               try
742               {
743 kumpf 1.2 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
744           		char slp_address[32];
745 kumpf 1.1       	slp_client *discovery = new slp_client() ;;
746                   String serviceURL;
747 kumpf 1.2 		serviceURL.assign("service:cim.pegasus://");
748           		String host_name = slp_get_host_name();
749           		serviceURL.append(host_name);
750           		serviceURL.append(":");
751                   // ATTN: Fix this to work for multiple connections
752                   sprintf(slp_address, 
753           				"%u",
754                           enableHttpConnection ? portNumberHttp : portNumberHttps);
755           		serviceURL.append(slp_address);
756           #endif
757           		Monitor monitor(true);
758           		CIMServer server(&monitor);
759           
760                   if (enableHttpConnection)
761                   {
762                       server.addAcceptor(false, portNumberHttp, false);
763                       Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
764                                   "Listening on HTTP port $0.", portNumberHttp);
765                   }
766                   if (enableHttpsConnection)
767                   {
768 kumpf 1.2             server.addAcceptor(false, portNumberHttps, true);
769                       Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
770                                   "Listening on HTTPS port $0.", portNumberHttps);
771                   }
772           #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
773                   server.addAcceptor(true, 0, false);
774                   Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
775                               "Listening on local connection socket.");
776 kumpf 1.1 #endif
777           
778 kumpf 1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
779                   if (enableHttpConnection)
780                   {
781                       cout << "Listening on HTTP port " << portNumberHttp << endl;
782                   }
783                   if (enableHttpsConnection)
784                   {
785                       cout << "Listening on HTTPS port " << portNumberHttps << endl;
786                   }
787 kumpf 1.1 #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
788 kumpf 1.2         cout << "Listening on local connection socket" << endl;
789           #endif
790 kumpf 1.1 #endif
791           
792 kumpf 1.2 		// bind throws an exception if the bind fails
793           		server.bind();
794 kumpf 1.1 
795 kumpf 1.2 		// notify parent process (if there is a parent process) to terminate 
796                   // so user knows that cimserver is ready to serve CIM requests.
797           		if (daemonOption)
798           			notify_parent();
799           
800           		time_t last = 0;
801 kumpf 1.1 
802           #if defined(PEGASUS_OS_HPUX)
803                   //
804                   // create a file to indicate that the cimserver has started and
805                   // save the process id of the cimserver process in the file
806                   //
807           
808                   // remove the old file if it exists
809                   System::removeFile(fname);
810           
811                   // open the file
812                   FILE *pid_file = fopen(fname, "w");
813                   if (pid_file)
814                   {
815                       // save the pid in the file
816                       fprintf(pid_file, "%ld\n", (long)server_pid);
817                       fclose(pid_file);
818                   }
819           #endif
820 kumpf 1.2 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
821           		cout << "Started. " << endl;
822 kumpf 1.1 #endif
823           
824                   // Put server started message to the logger
825 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
826 kumpf 1.1         Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
827 kumpf 1.2                     "Started $0 version $1.",
828                               PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
829 kumpf 1.1 #else
830                   Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
831 kumpf 1.2                     "Started $0 version $1.",
832                               PEGASUS_NAME, PEGASUS_VERSION);
833 kumpf 1.1 #endif
834           
835 kumpf 1.2 		//
836 kumpf 1.1         // Loop to call CIMServer's runForever() method until CIMServer
837                   // has been shutdown
838                   //
839 kumpf 1.2 		while(!server.terminated())
840           		{
841           #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
842           			if(useSLP) 
843           			{
844           				if((time(NULL) - last) > 60) 
845           				{
846           					if(discovery != NULL && serviceURL.size())
847           						discovery->srv_reg_all(serviceURL.getCString(),
848           											   "(namespace=root/cimv2)",
849           											   "service:cim.pegasus", 
850           											   "DEFAULT", 
851           											   70) ;
852           					time(&last);
853           				}
854           
855           	  			discovery->service_listener();
856           			}
857 kumpf 1.1 #endif
858 kumpf 1.2 			server.runForever();
859           		}
860 kumpf 1.1 
861                   //
862                   // normal termination
863 kumpf 1.2 		//
864 kumpf 1.1         // Put server shutdown message to the logger
865 kumpf 1.2 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
866                   Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
867                       "$0 stopped.", PLATFORM_PRODUCT_NAME);
868           #else
869 kumpf 1.1         Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
870                       "$0 stopped.", PEGASUS_NAME);
871 kumpf 1.2 #endif
872 kumpf 1.1 
873           #if defined(PEGASUS_OS_HPUX)
874                   //
875                   // close the file created at startup time to indicate that the 
876                   // cimserver has terminated normally.
877                   //
878                   FileSystem::removeFile(CIMSERVERSTART_FILE);
879           #endif
880               }
881               catch(Exception& e)
882               {
883 kumpf 1.2 		PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
884                   Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
885                       "Error: $0", e.getMessage());
886           
887           		//
888           		// notify parent process (if there is a parent process) to terminate
889                   //
890                   if (daemonOption)
891           			notify_parent();
892           
893 kumpf 1.1         return 1;
894               }
895           
896               return 0;
897           }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2