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

  1 mike  1.32 //%/////////////////////////////////////////////////////////////////////////////
  2            //
  3 kumpf 1.58 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4            // The Open Group, Tivoli Systems
  5 mike  1.32 //
  6            // Permission is hereby granted, free of charge, to any person obtaining a copy
  7 kumpf 1.58 // 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 mike  1.32 // 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 kumpf 1.58 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14 mike  1.32 // 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 kumpf 1.58 // 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 mike  1.32 // 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            //==============================================================================
 23            //
 24            // Author: Mike Brasher (mbrasher@bmc.com)
 25            //
 26            // Modified By: Mike Day (mdday@us.ibm.com) 
 27 mike  1.33 //
 28 mike  1.32 // Modified By:	Karl Schopmeyer (k.schopmeyer@opengroup.org)
 29            //
 30 mike  1.35 // Modified By: Nag Boranna (nagaraja_boranna@hp.com)
 31            //
 32            // Modified By: Jenny Yu (jenny_yu@hp.com)
 33            //
 34 kumpf 1.38 // Modified By: Sushma Fernandes (sushma_fernandes@hp.com)
 35            //
 36 mike  1.32 //%/////////////////////////////////////////////////////////////////////////////
 37            
 38            
 39            //////////////////////////////////////////////////////////////////////
 40            //
 41            // Notes on deamon operation (Unix) and service operation (Win 32):
 42            //
 43 kumpf 1.60 // To run pegasus as a daemon on Unix platforms: 
 44 mike  1.32 //
 45 kumpf 1.60 // cimserver
 46 mike  1.32 //
 47 kumpf 1.60 // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
 48            // property to false:
 49            //
 50            // cimserver daemon=false
 51            //
 52            // The daemon config property has no effect on windows operation. 
 53 mike  1.32 //
 54 mike  1.35 // To shutdown pegasus, use the -s option:
 55            // 
 56 kumpf 1.60 // cimserver -s 
 57 mike  1.35 //
 58 mike  1.32 // To run pegasus as an NT service, there are FOUR  different possibilities:
 59            //
 60            // To INSTALL the Pegasus service, 
 61            //
 62            // cimserver -install
 63            //
 64            // To REMOVE the Pegasus service, 
 65            //
 66            // cimserver -remove
 67            //
 68            // To START the Pegasus service, 
 69            //
 70            // net start cimserver
 71            //
 72            // To STOP the Pegasus service, 
 73            //
 74            // net stop cimserver
 75            //
 76            // Alternatively, you can use the windows service manager. Pegasus shows up 
 77            // in the service database as "Pegasus CIM Object Manager"
 78            //
 79 mike  1.32 // Mike Day, mdday@us.ibm.com
 80            // 
 81            //////////////////////////////////////////////////////////////////////
 82            
 83            
 84 mike  1.35 #include <Pegasus/Common/Config.h>
 85 kumpf 1.59 #include <Pegasus/Common/Constants.h>
 86 mday  1.47 #include <Pegasus/suballoc/suballoc.h>
 87 mike  1.32 #include <iostream>
 88 mike  1.35 #include <cassert>
 89 mike  1.32 #include <cstdlib>
 90 kumpf 1.45 #include <fstream>
 91 mike  1.32 #include <Pegasus/Common/FileSystem.h>
 92 mike  1.35 #include <Pegasus/Common/Monitor.h>
 93 mike  1.32 #include <Pegasus/Server/CIMServer.h>
 94            #include <Pegasus/Common/PegasusVersion.h>
 95            #include <Pegasus/Common/Logger.h>
 96            #include <Pegasus/Common/System.h>
 97 mike  1.35 #include <Pegasus/Common/Tracer.h>
 98            #include <Pegasus/Config/ConfigManager.h>
 99            #include <Pegasus/Client/CIMClient.h>
100            #include <Pegasus/Server/ShutdownService.h>
101 kumpf 1.38 #include <Pegasus/Common/Destroyer.h>
102 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
103 mike  1.32 #include <slp/slp.h>
104 mike  1.35 #endif
105 mike  1.32 
106            
107            #if defined(PEGASUS_OS_TYPE_WINDOWS)
108            # include "cimserver_windows.cpp"
109            #elif defined(PEGASUS_OS_TYPE_UNIX)
110            # include "cimserver_unix.cpp"
111            #else
112            # error "Unsupported platform"
113            #endif
114            
115            PEGASUS_USING_PEGASUS;
116            PEGASUS_USING_STD;
117            
118 mike  1.35 //
119            //  The command name.
120            //
121            static const char COMMAND_NAME []    = "cimserver";
122            
123            //
124            //  The constant defining usage string.
125            //
126            static const char USAGE []           = "Usage: ";
127            
128            /**
129            Constants representing the command line options.
130            */
131            static const char OPTION_VERSION     = 'v';
132            
133            static const char OPTION_HELP        = 'h';
134            
135            static const char OPTION_HOME        = 'D';
136            
137            static const char OPTION_SHUTDOWN    = 's';
138            
139 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
140            static const char OPTION_BINDVERBOSE = 'X';
141            #endif
142            
143 kumpf 1.54 static const String PROPERTY_TIMEOUT = "shutdownTimeout";
144 kumpf 1.45 static const String CIMSERVERSTART_FILE = "/etc/wbem/cimserver_start.conf";
145 mike  1.35 
146            ConfigManager*    configManager;
147            
148 mike  1.32 /** GetOptions function - This function defines the Options Table
149 mike  1.35     and sets up the options from that table using the config manager.
150 mike  1.32 */
151            void GetOptions(
152 mike  1.35     ConfigManager* cm,
153 mike  1.32     int& argc,
154                char** argv,
155                const String& pegasusHome)
156            {
157 mike  1.35     try
158 mike  1.32     {
159 kumpf 1.38         cm->mergeConfigFiles();
160 mike  1.33 
161 mike  1.35         cm->mergeCommandLine(argc, argv);
162                }
163                catch (NoSuchFile nsf)
164                {
165                    throw nsf;
166                }
167                catch (FileNotReadable fnr)
168                {
169                    throw fnr;
170                }
171                catch (CannotRenameFile ftrf)
172                {
173                    throw ftrf;
174                }
175                catch (ConfigFileSyntaxError cfse)
176                {
177                    throw cfse;
178                }
179                catch(UnrecognizedConfigProperty ucp)
180                {
181                    throw ucp;
182 mike  1.35     }
183                catch(InvalidPropertyValue ipv)
184                {
185                    throw ipv;
186                }
187 mike  1.32 }
188            
189            /* PrintHelp - This is temporary until we expand the options manager to allow
190               options help to be defined with the OptionRow entries and presented from
191               those entries.
192            */
193            void PrintHelp(const char* arg0)
194            {
195 mike  1.35     /**
196                    Build the usage string for the config command.
197                */
198                String usage = String (USAGE);
199                usage.append (COMMAND_NAME);
200                usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
201                usage.append ("  options\n");
202 kumpf 1.60     usage.append ("    -v          - displays CIM Server version number\n");
203 mike  1.35     usage.append ("    -h          - prints this help message\n");
204 kumpf 1.60     usage.append ("    -s          - shuts down CIM Server\n");
205            #ifndef PEGASUS_OS_HPUX
206 mike  1.35     usage.append ("    -D [home]   - sets pegasus home directory\n");
207 kumpf 1.60 #endif
208            #if defined(PEGASUS_OS_TYPE_WINDOWS)
209 mike  1.35     usage.append ("    -install    - installs pegasus as a Windows NT Service\n");
210                usage.append ("    -remove     - removes pegasus as a Windows NT Service\n");
211 kumpf 1.54 #endif
212 mike  1.35     usage.append ("  configProperty=value\n");
213 kumpf 1.60     usage.append ("                - sets CIM Server configuration property\n");
214 mike  1.35 
215                cout << endl;
216 mike  1.32     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
217                cout << endl;
218 mike  1.35     cout << usage << endl;
219            }
220            
221 kumpf 1.52 void shutdownCIMOM(Uint32 timeoutValue)
222 mike  1.35 {
223                //
224                // Create CIMClient object
225                //
226 kumpf 1.42     CIMClient client;
227 mike  1.35 
228                //
229 kumpf 1.53     // Get local host name
230 mike  1.35     //
231                String hostStr = System::getHostName();
232            
233                //
234                // open connection to CIMOM 
235                //
236                try
237                {
238 kumpf 1.43         client.connectLocal();
239 kumpf 1.52 
240                    //
241 kumpf 1.54         // set client timeout to 2 seconds more than the shutdown timeout
242 kumpf 1.52         // so that the command client does not timeout before the cimserver 
243                    // terminates
244                    //
245 kumpf 1.60         client.setTimeOut( (timeoutValue+2)*1000 );
246 mike  1.35     }
247 kumpf 1.43     catch(CIMClientException& e)
248 mike  1.35     {
249 kumpf 1.52         PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
250                    PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
251 kumpf 1.45         exit(0);
252 mike  1.35     }
253            
254                try
255                {
256                    //
257 kumpf 1.52         // construct CIMObjectPath
258 mike  1.35         //
259                    String referenceStr = "//";
260                    referenceStr.append(hostStr);
261 kumpf 1.59         referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN);
262 kumpf 1.53         referenceStr.append(":");
263                    referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN);
264 kumpf 1.50         CIMObjectPath reference(referenceStr);
265 mike  1.35 
266                    //
267                    // issue the invokeMethod request on the shutdown method
268                    //
269                    Array<CIMParamValue> inParams;
270                    Array<CIMParamValue> outParams;
271            
272 kumpf 1.52         // set force option to true for now
273 kumpf 1.40         inParams.append(CIMParamValue("force",
274 kumpf 1.52             CIMValue(Boolean(true))));
275 mike  1.35 
276 kumpf 1.40         inParams.append(CIMParamValue("timeout",
277 kumpf 1.39             CIMValue(Uint32(timeoutValue))));
278 mike  1.35 
279                    CIMValue retValue = client.invokeMethod(
280 kumpf 1.59             PEGASUS_NAMESPACENAME_SHUTDOWN,
281 mike  1.35             reference,
282                        "shutdown",
283                        inParams,
284                        outParams);
285 kumpf 1.43     }
286 kumpf 1.46     catch(CIMClientCIMException& e)
287                {
288                    PEGASUS_STD(cerr) << "Failed to shutdown server: ";
289                    PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
290                    exit(1);
291                }
292 kumpf 1.45     catch(CIMClientException& e)
293                {
294                    //
295 kumpf 1.54         // This may mean the CIM Server has been terminated and returns a 
296                    // "Empty HTTP response message" HTTP error response.  To be sure
297                    // CIM Server gets shutdown, if CIM Server is still running at 
298                    // this time, we will kill the cimserver process.
299 kumpf 1.45         //
300 kumpf 1.56         // give CIM Server some time to finish up
301                    //
302 kumpf 1.45         System::sleep(1);
303 kumpf 1.56         cimserver_kill();
304 kumpf 1.43     }
305 mike  1.35     catch(Exception& e)
306                {
307 kumpf 1.56         PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: ";
308 kumpf 1.45         PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
309 mike  1.35         exit(1);
310                }
311            
312                return;
313 mike  1.32 }
314            
315 mike  1.35 
316 mike  1.33 /////////////////////////////////////////////////////////////////////////
317 mike  1.32 //  MAIN
318            //////////////////////////////////////////////////////////////////////////
319            int main(int argc, char** argv)
320            {
321 mike  1.35     String pegasusHome  = String::EMPTY;
322                Boolean pegasusIOLog = false;
323 kumpf 1.53     String httpPort = String::EMPTY;
324                String httpsPort = String::EMPTY;
325 mike  1.35     String logsDirectory = String::EMPTY;
326                Boolean useSLP = false;
327                Boolean useSSL = false;
328                Boolean daemonOption = false;
329                Boolean shutdownOption = false;
330 kumpf 1.60     Uint32 timeoutValue  = 0;
331 mday  1.47 
332 kumpf 1.38     //
333                // Get environment variables:
334                //
335                const char* tmp = getenv("PEGASUS_HOME");
336            
337                if (tmp)
338                {
339                    pegasusHome = tmp;
340                }
341            
342                FileSystem::translateSlashes(pegasusHome);
343            
344 mike  1.32     // on Windows NT if there are no command-line options, run as a service
345            
346                if (argc == 1 )
347 mike  1.35     {
348                  cim_server_service(argc, argv);
349                }
350                else
351                {
352 kumpf 1.60         // Get help, version, and shutdown options
353 mike  1.35 
354                    for (int i = 1; i < argc; )
355                    {
356                        const char* arg = argv[i];
357            
358                        // Check for -option
359                        if (*arg == '-')
360                        {
361                            // Get the option
362                            const char* option = arg + 1;
363            
364                            //
365                            // Check to see if user asked for the version (-v option):
366                            //
367                            if (*option == OPTION_VERSION)
368                            {
369                                cout << PEGASUS_VERSION << endl;
370                                exit(0);
371                            }
372                            //
373                            // Check to see if user asked for help (-h option):
374 mike  1.35                 //
375                            else if (*option == OPTION_HELP)
376                            {
377                                PrintHelp(argv[0]);
378                                exit(0);
379                            }
380                            else if (*option == OPTION_HOME)
381                            {
382 kumpf 1.60                     if (i + 1 < argc)
383 mike  1.35                     {
384                                    pegasusHome.assign(argv[i + 1]);
385                                }
386                                else
387                                {
388                                    cout << "Missing argument for option -" << option << endl;
389                                    exit(0);
390                                }
391            
392                                memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
393                                argc -= 2;
394                            }
395 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
396                            //
397 kumpf 1.49                 // Check to see if user asked for the version (-X option):
398 kumpf 1.48                 //
399                            if (*option == OPTION_BINDVERBOSE)
400                            {
401            		    System::bindVerbose = true;
402                                cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
403                                     << endl;
404                                // remove the option from the command line
405                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
406                                argc--;   
407                            }
408            #endif
409 mike  1.35                 //
410                            // Check to see if user asked for shutdown (-s option):
411                            //
412                            else if (*option == OPTION_SHUTDOWN)
413                            {
414                                //
415 kumpf 1.52                     // check to see if user is root
416 mike  1.35                     //
417 kumpf 1.55                     if (!System::isPrivilegedUser(System::getEffectiveUserName()))
418 mike  1.35                     {
419 kumpf 1.52                         cout << "You must have superuser privilege to run ";
420                                    cout << "cimserver." << endl;
421 mike  1.35                         exit(0);
422                                }
423            
424                                //
425 kumpf 1.52                     // Check to see if shutdown has already been specified:
426 mike  1.35                     //
427 kumpf 1.52                     if (shutdownOption)
428 mike  1.35                     {
429 kumpf 1.52                         cout << "Duplicate shutdown option specified." << endl;
430 mike  1.35                         exit(0);
431                                }
432            
433 kumpf 1.52                     shutdownOption = true;
434 mike  1.35  
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                                i++;
441                        }
442                        else
443                            i++;
444 mike  1.32         }
445                }
446 mike  1.35 
447 kumpf 1.38     //
448                // Set the value for pegasusHome property
449                //
450                ConfigManager::setPegasusHome(pegasusHome);
451 mike  1.32 
452 mike  1.35     //
453                // Get an instance of the Config Manager.
454                //
455                configManager = ConfigManager::getInstance();
456            
457                //
458 mike  1.32     // Get options (from command line and from configuration file); this
459 mike  1.35     // removes corresponding options and their arguments from the command
460 mike  1.32     // line.
461 mike  1.35     //
462 mike  1.32     try
463                {
464 mike  1.35         GetOptions(configManager, argc, argv, pegasusHome);
465 mike  1.32     }
466                catch (Exception& e)
467                {
468 mike  1.35         cerr << argv[0] << ": " << e.getMessage() << endl;
469                    exit(1);
470 mike  1.32     }
471            
472 mike  1.35     try
473 mike  1.32     {
474 mike  1.35         //
475                    // Check to see if we should (can) install as a NT service
476                    //
477            
478                    if (String::equal(configManager->getCurrentValue("install"), "true"))
479                    {
480                        if( 0 != cimserver_install_nt_service( pegasusHome ))
481                        {
482                            cout << "\nPegasus installed as NT Service";
483                            exit(0);
484                        }
485                    }
486 mike  1.32 
487 mike  1.35         //
488                    // Check to see if we should (can) remove Pegasus as an NT service
489                    //
490            
491                    if (String::equal(configManager->getCurrentValue("remove"), "true"))
492                    {
493                        if( 0 != cimserver_remove_nt_service() )
494                        {
495                            cout << "\nPegasus removed as NT Service";
496                            exit(0);
497                        }
498                    }
499 mike  1.32 
500 mike  1.35         //
501                    // Check to see if we should Pegasus as a daemon
502                    //
503            
504                    if (String::equal(configManager->getCurrentValue("daemon"), "true"))
505                    {
506                        daemonOption = true;
507                    }
508 mike  1.32 
509 mike  1.35         //
510 kumpf 1.36         // Check the log trace options and set global variable
511                    //
512            
513                    if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
514                    {
515                        pegasusIOLog = true;
516                    }
517            
518                    // Get the log file directory definition.
519                    // We put String into Cstring because
520                    // Directory functions only handle Cstring.
521                    // ATTN-KS: create String based directory functions.
522            
523                    logsDirectory = configManager->getCurrentValue("logdir");
524 kumpf 1.38         logsDirectory = 
525            	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
526 kumpf 1.36 
527                    // Set up the Logger. This does not open the logs
528                    // Might be more logical to clean before set.
529                    // ATTN: Need tool to completely disable logging.
530            
531 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
532 kumpf 1.36         Logger::setHomeDirectory(logsDirectory);
533 kumpf 1.57 #endif
534 kumpf 1.36 
535                    //
536 mike  1.35         // Check to see if we need to shutdown CIMOM 
537                    //
538                    if (shutdownOption)
539                    {
540 kumpf 1.60             String configTimeout = 
541                            configManager->getCurrentValue("shutdownTimeout");
542                        ArrayDestroyer<char> timeoutCString(configTimeout.allocateCString());
543                        timeoutValue = strtol(timeoutCString.getPointer(), (char **)0, 10);
544                        
545 kumpf 1.52             shutdownCIMOM(timeoutValue);
546 kumpf 1.45 
547 kumpf 1.60             cout << "CIM Server stopped." << endl;
548 mike  1.35             exit(0);
549                    }
550 mike  1.32 
551 mike  1.35         //
552 kumpf 1.53         // Get the port numbers
553 mike  1.35         //
554            
555 kumpf 1.53         httpPort = configManager->getCurrentValue("httpPort");
556            
557                    httpsPort = configManager->getCurrentValue("httpsPort");
558 mike  1.35 
559 kumpf 1.36         // Leave this in until people get familiar with the logs.
560 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
561 kumpf 1.36         cout << "Logs Directory = " << logsDirectory << endl;
562 kumpf 1.57 #endif
563 mike  1.35 
564                    if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
565                    {
566                        Logger::clean(logsDirectory);;
567                    }
568 mike  1.32 
569 mike  1.35         if (String::equal(configManager->getCurrentValue("slp"), "true"))
570                    {
571                        useSLP =  true;
572                    }
573 mike  1.32 
574 mike  1.35         if (String::equal(configManager->getCurrentValue("SSL"), "true"))
575                    {
576                        useSSL =  true;
577                    }
578 mike  1.32     }
579 mike  1.35     catch (UnrecognizedConfigProperty e)
580 mike  1.32     {
581 mike  1.35         cout << "Error: " << e.getMessage() << endl;
582 mike  1.32     }
583            
584 kumpf 1.53     Uint32 portNumber;
585            
586                char address[32];
587            
588                if (useSSL)
589                {
590                    char* p = httpsPort.allocateCString();
591            	char* end = 0;
592            	Uint32 port = strtol(p, &end, 10);
593            	assert(end != 0 && *end == '\0');
594            	delete [] p;
595            
596                    //
597                    // Look up the WBEM-HTTPS port number 
598                    //
599                    portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
600                    sprintf(address, "%u", portNumber);
601                }
602                else
603                {
604                    char* p = httpPort.allocateCString();
605 kumpf 1.53 	char* end = 0;
606            	Uint32 port = strtol(p, &end, 10);
607            	assert(end != 0 && *end == '\0');
608            	delete [] p;
609            
610                    //
611                    // Look up the WBEM-HTTP port number 
612                    //
613                    portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
614                    sprintf(address, "%u", portNumber);
615                }
616 mike  1.32 
617                // Put out startup up message.
618                cout << PEGASUS_NAME << PEGASUS_VERSION <<
619            	 " on port " << address << endl;
620                cout << "Built " << __DATE__ << " " << __TIME__ << endl;
621 kumpf 1.54     cout <<"Starting..."
622 mike  1.32          << (pegasusIOLog ? " Tracing to Log ": " ")
623            	 << (useSLP ? " SLP reg. " : " No SLP ")
624 mike  1.35          << (useSSL ? " Use SSL " : " No SSL ")
625 mike  1.32 	<< endl;
626            
627 kumpf 1.51     // do we need to run as a daemon ?
628                if (daemonOption)
629                {
630                    if(-1 == cimserver_fork())
631                      exit(-1);
632                }
633            
634 mike  1.32     // try loop to bind the address, and run the server
635                try
636                {
637 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
638 mike  1.32       	slp_client *discovery = new slp_client() ;;
639                    String serviceURL;
640            	serviceURL.assign("service:cim.pegasus://");
641            	String host_name = slp_get_host_name();
642            	serviceURL += host_name;
643            	serviceURL += ":";
644            	serviceURL += address;
645            	char *url = serviceURL.allocateCString();
646            	//	free(host_name);
647 mike  1.35 #endif
648 mike  1.32 
649 mike  1.35 	Monitor monitor;
650 kumpf 1.38 	CIMServer server(&monitor, useSSL);
651 kumpf 1.41 
652            	// bind throws an exception if the bind fails
653            #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
654            	cout << "Binding to domain socket" << endl;
655            #else
656 mike  1.33 	cout << "Binding to " << address << endl;
657 kumpf 1.41 #endif
658 mike  1.35 
659            	server.bind(portNumber);
660 mike  1.32 
661            	time_t last = 0;
662 mike  1.35 
663 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
664                    //
665 kumpf 1.56         // create a file to indicate that the cimserver has started and
666                    // save the process id of the cimserver process in the file
667 kumpf 1.45         //
668 kumpf 1.56 
669                    // remove the old file if it exists
670                    System::removeFile(fname);
671            
672                    // open the file
673                    FILE *pid_file = fopen(fname, "w");
674                    if (pid_file)
675 kumpf 1.45         {
676 kumpf 1.56             // save the pid in the file
677                        fprintf(pid_file, "%ld\n", (long)server_pid);
678                        fclose(pid_file);
679 kumpf 1.45         }
680            #endif
681 kumpf 1.54 	cout << "Started. " << endl;
682            
683                    // Put server started message to the logger
684                    Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
685 kumpf 1.57                     "Started $0 version $1 on port $2.",
686                                PEGASUS_NAME, PEGASUS_VERSION, address);
687            
688 kumpf 1.45 
689 mike  1.35         //
690                    // Loop to call CIMServer's runForever() method until CIMServer
691                    // has been shutdown
692                    //
693            	while( !server.terminated() )
694 mike  1.32 	{
695 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
696 mike  1.32 	  if(useSLP  ) 
697            	  {
698            	    if(  (time(NULL) - last ) > 60 ) 
699            	    {
700            	      if( discovery != NULL && url != NULL )
701            		discovery->srv_reg_all(url,  
702 mike  1.35 				       "(namespace=root/cimv2)",
703 mike  1.32 				       "service:cim.pegasus", 
704            				       "DEFAULT", 
705            				       70) ;
706            	      time(&last);
707            	    }
708            	  
709            	    discovery->service_listener();
710            	  }
711 mike  1.35 #endif
712 mike  1.32 	  server.runForever();
713            	}
714            
715 kumpf 1.45         //
716                    // normal termination
717 mike  1.34 	//
718 kumpf 1.54         // Put server shutdown message to the logger
719                    Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
720                        "$0 stopped.", PEGASUS_NAME);
721 kumpf 1.45 
722            #if defined(PEGASUS_OS_HPUX)
723                    //
724 kumpf 1.56         // close the file created at startup time to indicate that the 
725                    // cimserver has terminated normally.
726 kumpf 1.45         //
727                    FileSystem::removeFile(CIMSERVERSTART_FILE);
728            #endif
729 mike  1.32     }
730                catch(Exception& e)
731                {
732            	PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
733 kumpf 1.54         return 1;
734 mike  1.32     }
735            
736                return 0;
737            }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2