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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2