(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.63 static const String CIMSERVERSTART_FILE = "/etc/opt/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 kumpf 1.63 #if defined(PEGASUS_OS_HPUX)
217                cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
218            #else
219 mike  1.32     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
220 kumpf 1.63 #endif
221 mike  1.32     cout << endl;
222 mike  1.35     cout << usage << endl;
223            }
224            
225 kumpf 1.52 void shutdownCIMOM(Uint32 timeoutValue)
226 mike  1.35 {
227                //
228                // Create CIMClient object
229                //
230 kumpf 1.42     CIMClient client;
231 mike  1.35 
232                //
233 kumpf 1.53     // Get local host name
234 mike  1.35     //
235                String hostStr = System::getHostName();
236            
237                //
238                // open connection to CIMOM 
239                //
240                try
241                {
242 kumpf 1.43         client.connectLocal();
243 kumpf 1.52 
244                    //
245 kumpf 1.63         // set client timeout to 2 seconds
246 kumpf 1.52         //
247 kumpf 1.63         client.setTimeOut(2000);
248 mike  1.35     }
249 kumpf 1.43     catch(CIMClientException& e)
250 mike  1.35     {
251 kumpf 1.52         PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
252                    PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
253 kumpf 1.45         exit(0);
254 mike  1.35     }
255            
256                try
257                {
258                    //
259 kumpf 1.52         // construct CIMObjectPath
260 mike  1.35         //
261                    String referenceStr = "//";
262                    referenceStr.append(hostStr);
263 kumpf 1.59         referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN);
264 kumpf 1.53         referenceStr.append(":");
265                    referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN);
266 kumpf 1.50         CIMObjectPath reference(referenceStr);
267 mike  1.35 
268                    //
269                    // issue the invokeMethod request on the shutdown method
270                    //
271                    Array<CIMParamValue> inParams;
272                    Array<CIMParamValue> outParams;
273            
274 kumpf 1.52         // set force option to true for now
275 kumpf 1.40         inParams.append(CIMParamValue("force",
276 kumpf 1.52             CIMValue(Boolean(true))));
277 mike  1.35 
278 kumpf 1.40         inParams.append(CIMParamValue("timeout",
279 kumpf 1.39             CIMValue(Uint32(timeoutValue))));
280 mike  1.35 
281                    CIMValue retValue = client.invokeMethod(
282 kumpf 1.59             PEGASUS_NAMESPACENAME_SHUTDOWN,
283 mike  1.35             reference,
284                        "shutdown",
285                        inParams,
286                        outParams);
287 kumpf 1.43     }
288 kumpf 1.46     catch(CIMClientCIMException& e)
289                {
290                    PEGASUS_STD(cerr) << "Failed to shutdown server: ";
291 kumpf 1.63         if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
292                    {
293                        PEGASUS_STD(cerr) << "The repository may be empty.";
294                        PEGASUS_STD(cerr) << PEGASUS_STD(endl);
295                    }
296                    else
297                    {
298                        PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
299                    }
300 kumpf 1.46         exit(1);
301                }
302 kumpf 1.45     catch(CIMClientException& e)
303                {
304                    //
305 kumpf 1.54         // This may mean the CIM Server has been terminated and returns a 
306                    // "Empty HTTP response message" HTTP error response.  To be sure
307                    // CIM Server gets shutdown, if CIM Server is still running at 
308                    // this time, we will kill the cimserver process.
309 kumpf 1.45         //
310 kumpf 1.56         // give CIM Server some time to finish up
311                    //
312 kumpf 1.63         //System::sleep(1);
313                    //cimserver_kill();
314            
315                    //
316                    // Check to see if CIMServer is still running.  If CIMServer
317                    // is still running and the shutdown timeout has not expired,
318                    // loop and wait one second until either CIM Server is
319                    // terminated or until timeout expires.  If timeout expires
320                    // and CIMServer is still running, kill the CIMServer
321                    // process.
322                    //
323                    Uint32 maxWaitTime = timeoutValue - 2;
324                    Boolean running = isCIMServerRunning();
325                    while ( running && maxWaitTime > 0 )
326                    {
327                        System::sleep(1);
328                        running = isCIMServerRunning();
329                        maxWaitTime = maxWaitTime - 1;
330                    }
331            
332                    if (running)
333 kumpf 1.63         {
334                        cimserver_kill();
335                    }
336 kumpf 1.43     }
337 mike  1.35     catch(Exception& e)
338                {
339 kumpf 1.56         PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: ";
340 kumpf 1.45         PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
341 mike  1.35         exit(1);
342                }
343            
344                return;
345 mike  1.32 }
346            
347 mike  1.35 
348 mike  1.33 /////////////////////////////////////////////////////////////////////////
349 mike  1.32 //  MAIN
350            //////////////////////////////////////////////////////////////////////////
351            int main(int argc, char** argv)
352            {
353 mike  1.35     String pegasusHome  = String::EMPTY;
354                Boolean pegasusIOLog = false;
355 kumpf 1.53     String httpPort = String::EMPTY;
356                String httpsPort = String::EMPTY;
357 mike  1.35     String logsDirectory = String::EMPTY;
358                Boolean useSLP = false;
359                Boolean useSSL = false;
360                Boolean daemonOption = false;
361                Boolean shutdownOption = false;
362 kumpf 1.60     Uint32 timeoutValue  = 0;
363 mday  1.47 
364 kumpf 1.38     //
365                // Get environment variables:
366                //
367                const char* tmp = getenv("PEGASUS_HOME");
368            
369                if (tmp)
370                {
371                    pegasusHome = tmp;
372                }
373            
374                FileSystem::translateSlashes(pegasusHome);
375            
376 mike  1.32     // on Windows NT if there are no command-line options, run as a service
377            
378                if (argc == 1 )
379 mike  1.35     {
380                  cim_server_service(argc, argv);
381                }
382                else
383                {
384 kumpf 1.60         // Get help, version, and shutdown options
385 mike  1.35 
386                    for (int i = 1; i < argc; )
387                    {
388                        const char* arg = argv[i];
389            
390                        // Check for -option
391                        if (*arg == '-')
392                        {
393                            // Get the option
394                            const char* option = arg + 1;
395            
396                            //
397                            // Check to see if user asked for the version (-v option):
398                            //
399                            if (*option == OPTION_VERSION)
400                            {
401 kumpf 1.63 #if defined(PEGASUS_OS_HPUX)
402                                cout << PLATFORM_PRODUCT_VERSION << endl;
403            #else
404 mike  1.35                     cout << PEGASUS_VERSION << endl;
405 kumpf 1.63 #endif
406 mike  1.35                     exit(0);
407                            }
408                            //
409                            // Check to see if user asked for help (-h option):
410                            //
411                            else if (*option == OPTION_HELP)
412                            {
413                                PrintHelp(argv[0]);
414                                exit(0);
415                            }
416 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
417 mike  1.35                 else if (*option == OPTION_HOME)
418                            {
419 kumpf 1.60                     if (i + 1 < argc)
420 mike  1.35                     {
421                                    pegasusHome.assign(argv[i + 1]);
422                                }
423                                else
424                                {
425                                    cout << "Missing argument for option -" << option << endl;
426                                    exit(0);
427                                }
428            
429                                memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
430                                argc -= 2;
431                            }
432 kumpf 1.63 #endif
433 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
434                            //
435 kumpf 1.49                 // Check to see if user asked for the version (-X option):
436 kumpf 1.48                 //
437                            if (*option == OPTION_BINDVERBOSE)
438                            {
439            		    System::bindVerbose = true;
440                                cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
441                                     << endl;
442                                // remove the option from the command line
443                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
444                                argc--;   
445                            }
446            #endif
447 mike  1.35                 //
448                            // Check to see if user asked for shutdown (-s option):
449                            //
450                            else if (*option == OPTION_SHUTDOWN)
451                            {
452                                //
453 kumpf 1.52                     // check to see if user is root
454 mike  1.35                     //
455 kumpf 1.55                     if (!System::isPrivilegedUser(System::getEffectiveUserName()))
456 mike  1.35                     {
457 kumpf 1.52                         cout << "You must have superuser privilege to run ";
458                                    cout << "cimserver." << endl;
459 mike  1.35                         exit(0);
460                                }
461            
462                                //
463 kumpf 1.52                     // Check to see if shutdown has already been specified:
464 mike  1.35                     //
465 kumpf 1.52                     if (shutdownOption)
466 mike  1.35                     {
467 kumpf 1.52                         cout << "Duplicate shutdown option specified." << endl;
468 mike  1.35                         exit(0);
469                                }
470            
471 kumpf 1.52                     shutdownOption = true;
472 mike  1.35  
473                                // remove the option from the command line
474                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
475                                argc--;   
476                            }
477                            else
478                                i++;
479                        }
480                        else
481                            i++;
482 mike  1.32         }
483                }
484 mike  1.35 
485 kumpf 1.38     //
486                // Set the value for pegasusHome property
487                //
488                ConfigManager::setPegasusHome(pegasusHome);
489 mike  1.32 
490 mike  1.35     //
491                // Get an instance of the Config Manager.
492                //
493                configManager = ConfigManager::getInstance();
494            
495                //
496 mike  1.32     // Get options (from command line and from configuration file); this
497 mike  1.35     // removes corresponding options and their arguments from the command
498 mike  1.32     // line.
499 mike  1.35     //
500 mike  1.32     try
501                {
502 mike  1.35         GetOptions(configManager, argc, argv, pegasusHome);
503 mike  1.32     }
504                catch (Exception& e)
505                {
506 mike  1.35         cerr << argv[0] << ": " << e.getMessage() << endl;
507                    exit(1);
508 mike  1.32     }
509            
510 mike  1.35     try
511 mike  1.32     {
512 mike  1.35         //
513                    // Check to see if we should (can) install as a NT service
514                    //
515            
516                    if (String::equal(configManager->getCurrentValue("install"), "true"))
517                    {
518                        if( 0 != cimserver_install_nt_service( pegasusHome ))
519                        {
520                            cout << "\nPegasus installed as NT Service";
521                            exit(0);
522                        }
523                    }
524 mike  1.32 
525 mike  1.35         //
526                    // Check to see if we should (can) remove Pegasus as an NT service
527                    //
528            
529                    if (String::equal(configManager->getCurrentValue("remove"), "true"))
530                    {
531                        if( 0 != cimserver_remove_nt_service() )
532                        {
533                            cout << "\nPegasus removed as NT Service";
534                            exit(0);
535                        }
536                    }
537 mike  1.32 
538 mike  1.35         //
539                    // Check to see if we should Pegasus as a daemon
540                    //
541            
542                    if (String::equal(configManager->getCurrentValue("daemon"), "true"))
543                    {
544                        daemonOption = true;
545                    }
546 mday  1.62 	
547 mike  1.35         //
548 kumpf 1.36         // Check the log trace options and set global variable
549                    //
550            
551                    if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
552                    {
553                        pegasusIOLog = true;
554                    }
555            
556                    // Get the log file directory definition.
557                    // We put String into Cstring because
558                    // Directory functions only handle Cstring.
559                    // ATTN-KS: create String based directory functions.
560            
561                    logsDirectory = configManager->getCurrentValue("logdir");
562 kumpf 1.38         logsDirectory = 
563            	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
564 kumpf 1.36 
565                    // Set up the Logger. This does not open the logs
566                    // Might be more logical to clean before set.
567                    // ATTN: Need tool to completely disable logging.
568            
569 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
570 kumpf 1.36         Logger::setHomeDirectory(logsDirectory);
571 kumpf 1.57 #endif
572 kumpf 1.36 
573                    //
574 mike  1.35         // Check to see if we need to shutdown CIMOM 
575                    //
576                    if (shutdownOption)
577                    {
578 kumpf 1.60             String configTimeout = 
579                            configManager->getCurrentValue("shutdownTimeout");
580                        ArrayDestroyer<char> timeoutCString(configTimeout.allocateCString());
581                        timeoutValue = strtol(timeoutCString.getPointer(), (char **)0, 10);
582                        
583 kumpf 1.52             shutdownCIMOM(timeoutValue);
584 kumpf 1.45 
585 kumpf 1.60             cout << "CIM Server stopped." << endl;
586 mike  1.35             exit(0);
587                    }
588 mike  1.32 
589 mike  1.35         //
590 kumpf 1.53         // Get the port numbers
591 mike  1.35         //
592            
593 kumpf 1.53         httpPort = configManager->getCurrentValue("httpPort");
594            
595                    httpsPort = configManager->getCurrentValue("httpsPort");
596 mike  1.35 
597 kumpf 1.36         // Leave this in until people get familiar with the logs.
598 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
599 kumpf 1.36         cout << "Logs Directory = " << logsDirectory << endl;
600 kumpf 1.57 #endif
601 mike  1.35 
602                    if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
603                    {
604                        Logger::clean(logsDirectory);;
605                    }
606 mike  1.32 
607 mike  1.35         if (String::equal(configManager->getCurrentValue("slp"), "true"))
608                    {
609                        useSLP =  true;
610                    }
611 mike  1.32 
612 mike  1.35         if (String::equal(configManager->getCurrentValue("SSL"), "true"))
613                    {
614                        useSSL =  true;
615                    }
616 mike  1.32     }
617 mike  1.35     catch (UnrecognizedConfigProperty e)
618 mike  1.32     {
619 mike  1.35         cout << "Error: " << e.getMessage() << endl;
620 mike  1.32     }
621            
622 kumpf 1.53     Uint32 portNumber;
623            
624                char address[32];
625            
626                if (useSSL)
627                {
628                    char* p = httpsPort.allocateCString();
629            	char* end = 0;
630            	Uint32 port = strtol(p, &end, 10);
631            	assert(end != 0 && *end == '\0');
632            	delete [] p;
633            
634                    //
635                    // Look up the WBEM-HTTPS port number 
636                    //
637                    portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
638                    sprintf(address, "%u", portNumber);
639                }
640                else
641                {
642                    char* p = httpPort.allocateCString();
643 kumpf 1.53 	char* end = 0;
644            	Uint32 port = strtol(p, &end, 10);
645            	assert(end != 0 && *end == '\0');
646            	delete [] p;
647            
648                    //
649                    // Look up the WBEM-HTTP port number 
650                    //
651                    portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
652                    sprintf(address, "%u", portNumber);
653                }
654 mike  1.32 
655                // Put out startup up message.
656 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
657 mike  1.32     cout << PEGASUS_NAME << PEGASUS_VERSION <<
658            	 " on port " << address << endl;
659                cout << "Built " << __DATE__ << " " << __TIME__ << endl;
660 kumpf 1.54     cout <<"Starting..."
661 mike  1.32          << (pegasusIOLog ? " Tracing to Log ": " ")
662            	 << (useSLP ? " SLP reg. " : " No SLP ")
663 mike  1.35          << (useSSL ? " Use SSL " : " No SSL ")
664 mike  1.32 	<< endl;
665 kumpf 1.63 #endif
666 mike  1.32 
667 kumpf 1.63     // do we need to run as a daemon ?
668                if (daemonOption)
669                {
670                    if(-1 == cimserver_fork())
671                      exit(-1);
672                }
673 mday  1.62 
674 kumpf 1.63 #ifdef PEGASUS_OS_HPUX
675                umask(S_IWGRP|S_IWOTH);
676            #endif
677 kumpf 1.51 
678 mike  1.32     // try loop to bind the address, and run the server
679                try
680                {
681 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
682 mike  1.32       	slp_client *discovery = new slp_client() ;;
683                    String serviceURL;
684            	serviceURL.assign("service:cim.pegasus://");
685            	String host_name = slp_get_host_name();
686            	serviceURL += host_name;
687            	serviceURL += ":";
688            	serviceURL += address;
689            	char *url = serviceURL.allocateCString();
690            	//	free(host_name);
691 mike  1.35 #endif
692 mike  1.32 
693 mday  1.61 	Monitor monitor(true);
694 kumpf 1.38 	CIMServer server(&monitor, useSSL);
695 kumpf 1.41 
696            	// bind throws an exception if the bind fails
697            #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
698            	cout << "Binding to domain socket" << endl;
699 kumpf 1.63 #elif !defined(PEGASUS_OS_HPUX)
700 mike  1.33 	cout << "Binding to " << address << endl;
701 kumpf 1.41 #endif
702 mike  1.35 
703            	server.bind(portNumber);
704 mike  1.32 
705            	time_t last = 0;
706 mike  1.35 
707 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
708                    //
709 kumpf 1.56         // create a file to indicate that the cimserver has started and
710                    // save the process id of the cimserver process in the file
711 kumpf 1.45         //
712 kumpf 1.56 
713                    // remove the old file if it exists
714                    System::removeFile(fname);
715            
716                    // open the file
717                    FILE *pid_file = fopen(fname, "w");
718                    if (pid_file)
719 kumpf 1.45         {
720 kumpf 1.56             // save the pid in the file
721                        fprintf(pid_file, "%ld\n", (long)server_pid);
722                        fclose(pid_file);
723 kumpf 1.45         }
724            #endif
725 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
726 kumpf 1.54 	cout << "Started. " << endl;
727 kumpf 1.63 #endif
728 kumpf 1.54 
729                    // Put server started message to the logger
730 kumpf 1.63 #ifdef PEGASUS_OS_HPUX
731                    Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
732                                "Started $0 version $1 on port $2.",
733                                PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION, address);
734            #else
735 kumpf 1.54         Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
736 kumpf 1.57                     "Started $0 version $1 on port $2.",
737                                PEGASUS_NAME, PEGASUS_VERSION, address);
738 kumpf 1.63 #endif
739 kumpf 1.45 
740 mday  1.62 	
741 mike  1.35         //
742                    // Loop to call CIMServer's runForever() method until CIMServer
743                    // has been shutdown
744                    //
745            	while( !server.terminated() )
746 mike  1.32 	{
747 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
748 mike  1.32 	  if(useSLP  ) 
749            	  {
750            	    if(  (time(NULL) - last ) > 60 ) 
751            	    {
752            	      if( discovery != NULL && url != NULL )
753            		discovery->srv_reg_all(url,  
754 mike  1.35 				       "(namespace=root/cimv2)",
755 mike  1.32 				       "service:cim.pegasus", 
756            				       "DEFAULT", 
757            				       70) ;
758            	      time(&last);
759            	    }
760            	  
761            	    discovery->service_listener();
762            	  }
763 mike  1.35 #endif
764 mike  1.32 	  server.runForever();
765            	}
766            
767 kumpf 1.45         //
768                    // normal termination
769 mike  1.34 	//
770 kumpf 1.54         // Put server shutdown message to the logger
771                    Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
772                        "$0 stopped.", PEGASUS_NAME);
773 kumpf 1.45 
774            #if defined(PEGASUS_OS_HPUX)
775                    //
776 kumpf 1.56         // close the file created at startup time to indicate that the 
777                    // cimserver has terminated normally.
778 kumpf 1.45         //
779                    FileSystem::removeFile(CIMSERVERSTART_FILE);
780            #endif
781 mike  1.32     }
782                catch(Exception& e)
783                {
784            	PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
785 kumpf 1.54         return 1;
786 mike  1.32     }
787            
788                return 0;
789            }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2