(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            // To run pegasus as a daemon on Unix platforms, use the -d option:
 44            //
 45            // cimserver -d
 46            //
 47            // The -d option has no effect on windows operation. 
 48            //
 49 mike  1.35 // To shutdown pegasus, use the -s option:
 50            // 
 51 kumpf 1.54 // cimserver -s [-t timeout_value]
 52 mike  1.35 //
 53 mike  1.32 // To run pegasus as an NT service, there are FOUR  different possibilities:
 54            //
 55            // To INSTALL the Pegasus service, 
 56            //
 57            // cimserver -install
 58            //
 59            // To REMOVE the Pegasus service, 
 60            //
 61            // cimserver -remove
 62            //
 63            // To START the Pegasus service, 
 64            //
 65            // net start cimserver
 66            //
 67            // To STOP the Pegasus service, 
 68            //
 69            // net stop cimserver
 70            //
 71            // Alternatively, you can use the windows service manager. Pegasus shows up 
 72            // in the service database as "Pegasus CIM Object Manager"
 73            //
 74 mike  1.32 // Mike Day, mdday@us.ibm.com
 75            // 
 76            //////////////////////////////////////////////////////////////////////
 77            
 78            
 79 mike  1.35 #include <Pegasus/Common/Config.h>
 80 mday  1.47 #include <Pegasus/suballoc/suballoc.h>
 81 mike  1.32 #include <iostream>
 82 mike  1.35 #include <cassert>
 83 mike  1.32 #include <cstdlib>
 84 kumpf 1.45 #include <fstream>
 85 mike  1.32 #include <Pegasus/Common/FileSystem.h>
 86 mike  1.35 #include <Pegasus/Common/Monitor.h>
 87 mike  1.32 #include <Pegasus/Server/CIMServer.h>
 88            #include <Pegasus/Common/PegasusVersion.h>
 89            #include <Pegasus/Common/Logger.h>
 90            #include <Pegasus/Common/System.h>
 91 mike  1.35 #include <Pegasus/Common/Tracer.h>
 92            #include <Pegasus/Config/ConfigManager.h>
 93            #include <Pegasus/Client/CIMClient.h>
 94            #include <Pegasus/Server/ShutdownService.h>
 95 kumpf 1.38 #include <Pegasus/Common/Destroyer.h>
 96 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
 97 mike  1.32 #include <slp/slp.h>
 98 mike  1.35 #endif
 99 mike  1.32 
100            
101            #if defined(PEGASUS_OS_TYPE_WINDOWS)
102            # include "cimserver_windows.cpp"
103            #elif defined(PEGASUS_OS_TYPE_UNIX)
104            # include "cimserver_unix.cpp"
105            #else
106            # error "Unsupported platform"
107            #endif
108            
109            PEGASUS_USING_PEGASUS;
110            PEGASUS_USING_STD;
111            
112 mike  1.35 //
113            //  The command name.
114            //
115            static const char COMMAND_NAME []    = "cimserver";
116            
117            //
118            //  The constant defining usage string.
119            //
120            static const char USAGE []           = "Usage: ";
121            
122            /**
123            Constants representing the command line options.
124            */
125            static const char OPTION_VERSION     = 'v';
126            
127            static const char OPTION_HELP        = 'h';
128            
129            static const char OPTION_HOME        = 'D';
130            
131            static const char OPTION_SHUTDOWN    = 's';
132            
133 mike  1.35 static const char OPTION_FORCE       = 'f';
134            
135 kumpf 1.54 static const char OPTION_TIMEOUT     = 't';
136 mike  1.35 
137 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
138            static const char OPTION_BINDVERBOSE = 'X';
139            #endif
140            
141 kumpf 1.43 static const String NAMESPACE = "root/PG_Internal";
142 mike  1.35 static const String CLASSNAME_SHUTDOWNSERVICE = "PG_ShutdownService";
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                usage.append ("    -v          - displays pegasus version number\n");
203                usage.append ("    -h          - prints this help message\n");
204                usage.append ("    -D [home]   - sets pegasus home directory\n");
205                usage.append ("    -d          - runs pegasus as a daemon\n");
206 kumpf 1.54     usage.append ("    -s [-t timeout] \n");
207 mike  1.35     usage.append ("                - shuts down pegasus\n");
208 kumpf 1.54 #if !defined(PEGASUS_OS_HPUX)
209 mike  1.35     usage.append ("    -cleanlogs  - clears the log files at startup\n");
210                usage.append ("    -install    - installs pegasus as a Windows NT Service\n");
211                usage.append ("    -remove     - removes pegasus as a Windows NT Service\n");
212                usage.append ("    -slp        - registers pegasus as a service with SLP\n\n");
213                usage.append ("    -SSL        - uses SSL\n\n");
214 kumpf 1.54 #endif
215 mike  1.35     usage.append ("  configProperty=value\n");
216                usage.append ("    port=nnnn            - sets port number to listen on\n");
217                usage.append ("    logdir=/pegasus/logs - directory for log files\n");
218            
219                cout << endl;
220 mike  1.32     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
221                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.54         // set client timeout to 2 seconds more than the shutdown timeout
246 kumpf 1.52         // so that the command client does not timeout before the cimserver 
247                    // terminates
248                    //
249 kumpf 1.54         Uint32 clientTimeout;
250                    if (timeoutValue == 0)
251                    {
252                        String configTimeout = 
253                            configManager->getCurrentValue("shutdownTimeout");
254                       ArrayDestroyer<char> timeoutCString(configTimeout.allocateCString());
255                        clientTimeout = 
256                            ((strtol(timeoutCString.getPointer(), (char **)0,10))+2)*1000;
257                    }
258                    else
259                    {
260                        clientTimeout = (timeoutValue + 2)*1000;
261                    }
262            
263                    client.setTimeOut(clientTimeout);
264 mike  1.35     }
265 kumpf 1.43     catch(CIMClientException& e)
266 mike  1.35     {
267 kumpf 1.52         PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
268                    PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
269 kumpf 1.45         exit(0);
270 mike  1.35     }
271            
272                try
273                {
274                    //
275 kumpf 1.52         // construct CIMObjectPath
276 mike  1.35         //
277                    String referenceStr = "//";
278                    referenceStr.append(hostStr);
279 kumpf 1.53         referenceStr.append(PEGASUS_NAMESPACENAME_CIMV2);
280                    referenceStr.append(":");
281                    referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN);
282 kumpf 1.50         CIMObjectPath reference(referenceStr);
283 mike  1.35 
284                    //
285                    // issue the invokeMethod request on the shutdown method
286                    //
287                    Array<CIMParamValue> inParams;
288                    Array<CIMParamValue> outParams;
289            
290 kumpf 1.52         // set force option to true for now
291 kumpf 1.40         inParams.append(CIMParamValue("force",
292 kumpf 1.52             CIMValue(Boolean(true))));
293 mike  1.35 
294 kumpf 1.40         inParams.append(CIMParamValue("timeout",
295 kumpf 1.39             CIMValue(Uint32(timeoutValue))));
296 mike  1.35 
297                    CIMValue retValue = client.invokeMethod(
298                        NAMESPACE,
299                        reference,
300                        "shutdown",
301                        inParams,
302                        outParams);
303 kumpf 1.43     }
304 kumpf 1.46     catch(CIMClientCIMException& e)
305                {
306                    PEGASUS_STD(cerr) << "Failed to shutdown server: ";
307                    PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
308                    exit(1);
309                }
310 kumpf 1.45     catch(CIMClientException& e)
311                {
312                    //
313 kumpf 1.54         // This may mean the CIM Server has been terminated and returns a 
314                    // "Empty HTTP response message" HTTP error response.  To be sure
315                    // CIM Server gets shutdown, if CIM Server is still running at 
316                    // this time, we will kill the cimserver process.
317 kumpf 1.45         //
318 kumpf 1.56         // give CIM Server some time to finish up
319                    //
320 kumpf 1.45         System::sleep(1);
321 kumpf 1.56         cimserver_kill();
322 kumpf 1.43     }
323 mike  1.35     catch(Exception& e)
324                {
325 kumpf 1.56         PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: ";
326 kumpf 1.45         PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
327 mike  1.35         exit(1);
328                }
329            
330                return;
331 mike  1.32 }
332            
333 mike  1.35 
334 mike  1.33 /////////////////////////////////////////////////////////////////////////
335 mike  1.32 //  MAIN
336            //////////////////////////////////////////////////////////////////////////
337            int main(int argc, char** argv)
338            {
339 mike  1.35     String pegasusHome  = String::EMPTY;
340                Boolean pegasusIOLog = false;
341 kumpf 1.53     String httpPort = String::EMPTY;
342                String httpsPort = String::EMPTY;
343 mike  1.35     String logsDirectory = String::EMPTY;
344                Boolean useSLP = false;
345                Boolean useSSL = false;
346                Boolean daemonOption = false;
347                Boolean shutdownOption = false;
348                Boolean timeoutOption = false;
349                String  timeoutStr  = String::EMPTY;
350                long timeoutValue  = 0;
351 mday  1.47 
352 kumpf 1.38     //
353                // Get environment variables:
354                //
355                const char* tmp = getenv("PEGASUS_HOME");
356            
357                if (tmp)
358                {
359                    pegasusHome = tmp;
360                }
361            
362                FileSystem::translateSlashes(pegasusHome);
363            
364 mike  1.32     // on Windows NT if there are no command-line options, run as a service
365            
366                if (argc == 1 )
367 mike  1.35     {
368                  cim_server_service(argc, argv);
369                }
370                else
371                {
372                    // Get help, version and home options
373            
374                    for (int i = 1; i < argc; )
375                    {
376                        const char* arg = argv[i];
377            
378                        // Check for -option
379                        if (*arg == '-')
380                        {
381                            // Get the option
382                            const char* option = arg + 1;
383            
384                            //
385                            // Check to see if user asked for the version (-v option):
386                            //
387                            if (*option == OPTION_VERSION)
388 mike  1.35                 {
389                                cout << PEGASUS_VERSION << endl;
390                                exit(0);
391                            }
392                            //
393                            // Check to see if user asked for help (-h option):
394                            //
395                            else if (*option == OPTION_HELP)
396                            {
397                                PrintHelp(argv[0]);
398                                exit(0);
399                            }
400                            else if (*option == OPTION_HOME)
401                            {
402                                if (i + 1 < argc) 
403                                {
404                                    pegasusHome.assign(argv[i + 1]);
405                                }
406                                else
407                                {
408                                    cout << "Missing argument for option -" << option << endl;
409 mike  1.35                         exit(0);
410                                }
411            
412                                memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
413                                argc -= 2;
414                            }
415 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
416                            //
417 kumpf 1.49                 // Check to see if user asked for the version (-X option):
418 kumpf 1.48                 //
419                            if (*option == OPTION_BINDVERBOSE)
420                            {
421            		    System::bindVerbose = true;
422                                cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
423                                     << endl;
424                                // remove the option from the command line
425                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
426                                argc--;   
427                            }
428            #endif
429 mike  1.35                 //
430                            // Check to see if user asked for shutdown (-s option):
431                            //
432                            else if (*option == OPTION_SHUTDOWN)
433                            {
434 kumpf 1.52 
435 mike  1.35                     //
436 kumpf 1.52                     // check to see if user is root
437 mike  1.35                     //
438 kumpf 1.55                     if (!System::isPrivilegedUser(System::getEffectiveUserName()))
439 mike  1.35                     {
440 kumpf 1.52                         cout << "You must have superuser privilege to run ";
441                                    cout << "cimserver." << endl;
442 mike  1.35                         exit(0);
443                                }
444            
445                                //
446 kumpf 1.52                     // Check to see if shutdown has already been specified:
447 mike  1.35                     //
448 kumpf 1.52                     if (shutdownOption)
449 mike  1.35                     {
450 kumpf 1.52                         cout << "Duplicate shutdown option specified." << endl;
451 mike  1.35                         exit(0);
452                                }
453            
454 kumpf 1.52                     shutdownOption = true;
455 mike  1.35  
456                                // remove the option from the command line
457                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
458                                argc--;   
459                            }
460                            else if (*option == OPTION_TIMEOUT)
461                            {
462                                //
463                                // Check to see if shutdown has been specified:
464                                //
465                                if (!shutdownOption)
466                                {
467                                    cout << "Invalid option -" << option << endl;
468                                    exit(0);
469                                }
470            
471                                if (timeoutOption)
472                                {
473                                    cout << "Duplicate timeout option specified." << endl;
474                                    exit(0);
475                                }
476 mike  1.35 
477                                timeoutOption = true;
478            
479                                if (i + 1 < argc)
480                                {
481                                    // get timeout value
482                                    timeoutStr.assign(argv[i + 1]);
483            
484                                    // validate timeout value string
485                                    char* tmp = timeoutStr.allocateCString();
486                                    char* end = 0;
487                                    timeoutValue  = strtol(tmp, &end, 10);
488                                  
489                                    if (!end || *end != '\0')
490                                    {
491                                        cout << "invalid timeout value specified: ";
492                                        cout << timeoutStr << endl;
493                                        delete [] tmp;
494                                        exit(0);
495                                    }
496                                }
497 mike  1.35                     else
498                                {
499                                    cout << "Missing argument for option -";
500                                    cout << option << endl;
501                                    exit(0);
502                                }
503            
504                                // remove the option from the command line
505                                memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
506                                argc -= 2;
507                            }
508                            else
509                                i++;
510                        }
511                        else
512                            i++;
513 mike  1.32         }
514                }
515 mike  1.35 
516 kumpf 1.38     //
517                // Set the value for pegasusHome property
518                //
519                ConfigManager::setPegasusHome(pegasusHome);
520 mike  1.32 
521 mike  1.35     //
522                // Get an instance of the Config Manager.
523                //
524                configManager = ConfigManager::getInstance();
525            
526                //
527 mike  1.32     // Get options (from command line and from configuration file); this
528 mike  1.35     // removes corresponding options and their arguments from the command
529 mike  1.32     // line.
530 mike  1.35     //
531 mike  1.32     try
532                {
533 mike  1.35         GetOptions(configManager, argc, argv, pegasusHome);
534 mike  1.32     }
535                catch (Exception& e)
536                {
537 mike  1.35         cerr << argv[0] << ": " << e.getMessage() << endl;
538                    exit(1);
539 mike  1.32     }
540            
541            
542 mike  1.35     try
543 mike  1.32     {
544 mike  1.35         //
545                    // Check to see if we should (can) install as a NT service
546                    //
547            
548                    if (String::equal(configManager->getCurrentValue("install"), "true"))
549                    {
550                        if( 0 != cimserver_install_nt_service( pegasusHome ))
551                        {
552                            cout << "\nPegasus installed as NT Service";
553                            exit(0);
554                        }
555                    }
556 mike  1.32 
557 mike  1.35         //
558                    // Check to see if we should (can) remove Pegasus as an NT service
559                    //
560            
561                    if (String::equal(configManager->getCurrentValue("remove"), "true"))
562                    {
563                        if( 0 != cimserver_remove_nt_service() )
564                        {
565                            cout << "\nPegasus removed as NT Service";
566                            exit(0);
567                        }
568                    }
569 mike  1.32 
570 mike  1.35         //
571                    // Check to see if we should Pegasus as a daemon
572                    //
573            
574                    if (String::equal(configManager->getCurrentValue("daemon"), "true"))
575                    {
576                        daemonOption = true;
577                    }
578 mike  1.32 
579 mike  1.35         //
580 kumpf 1.36         // Check the log trace options and set global variable
581                    //
582            
583                    if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
584                    {
585                        pegasusIOLog = true;
586                    }
587            
588                    // Get the log file directory definition.
589                    // We put String into Cstring because
590                    // Directory functions only handle Cstring.
591                    // ATTN-KS: create String based directory functions.
592            
593                    logsDirectory = configManager->getCurrentValue("logdir");
594 kumpf 1.38         logsDirectory = 
595            	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
596 kumpf 1.36 
597                    // Set up the Logger. This does not open the logs
598                    // Might be more logical to clean before set.
599                    // ATTN: Need tool to completely disable logging.
600            
601 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
602 kumpf 1.36         Logger::setHomeDirectory(logsDirectory);
603 kumpf 1.57 #endif
604 kumpf 1.36 
605                    //
606 mike  1.35         // Check to see if we need to shutdown CIMOM 
607                    //
608                    if (shutdownOption)
609                    {
610                        //
611                        // if timeout was specified, validate the timeout value 
612                        //
613                        if (timeoutOption)
614                        {
615                            Boolean valid = configManager->validatePropertyValue(
616                                                         PROPERTY_TIMEOUT,
617                                                         timeoutStr);
618                            if (!valid)
619                            {
620                                cout << "Invalid timeout value specified: " << timeoutValue;
621                                cout << endl;
622                                exit(1);
623                            }
624                        }
625            
626 kumpf 1.52             shutdownCIMOM(timeoutValue);
627 kumpf 1.45 
628 kumpf 1.54             cout << "Pegasus CIM Server stopped." << endl;
629 mike  1.35             exit(0);
630                    }
631 mike  1.32 
632 mike  1.35         //
633 kumpf 1.53         // Get the port numbers
634 mike  1.35         //
635            
636 kumpf 1.53         httpPort = configManager->getCurrentValue("httpPort");
637            
638                    httpsPort = configManager->getCurrentValue("httpsPort");
639 mike  1.35 
640 kumpf 1.36         // Leave this in until people get familiar with the logs.
641 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
642 kumpf 1.36         cout << "Logs Directory = " << logsDirectory << endl;
643 kumpf 1.57 #endif
644 mike  1.35 
645                    if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
646                    {
647                        Logger::clean(logsDirectory);;
648                    }
649 mike  1.32 
650 mike  1.35         if (String::equal(configManager->getCurrentValue("slp"), "true"))
651                    {
652                        useSLP =  true;
653                    }
654 mike  1.32 
655 mike  1.35         if (String::equal(configManager->getCurrentValue("SSL"), "true"))
656                    {
657                        useSSL =  true;
658                    }
659 mike  1.32     }
660 mike  1.35     catch (UnrecognizedConfigProperty e)
661 mike  1.32     {
662 mike  1.35         cout << "Error: " << e.getMessage() << endl;
663 mike  1.32     }
664            
665 kumpf 1.53     Uint32 portNumber;
666            
667                char address[32];
668            
669                if (useSSL)
670                {
671                    char* p = httpsPort.allocateCString();
672            	char* end = 0;
673            	Uint32 port = strtol(p, &end, 10);
674            	assert(end != 0 && *end == '\0');
675            	delete [] p;
676            
677                    //
678                    // Look up the WBEM-HTTPS port number 
679                    //
680                    portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
681                    sprintf(address, "%u", portNumber);
682                }
683                else
684                {
685                    char* p = httpPort.allocateCString();
686 kumpf 1.53 	char* end = 0;
687            	Uint32 port = strtol(p, &end, 10);
688            	assert(end != 0 && *end == '\0');
689            	delete [] p;
690            
691                    //
692                    // Look up the WBEM-HTTP port number 
693                    //
694                    portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
695                    sprintf(address, "%u", portNumber);
696                }
697 mike  1.32 
698                // Put out startup up message.
699                cout << PEGASUS_NAME << PEGASUS_VERSION <<
700            	 " on port " << address << endl;
701                cout << "Built " << __DATE__ << " " << __TIME__ << endl;
702 kumpf 1.54     cout <<"Starting..."
703 mike  1.32          << (pegasusIOLog ? " Tracing to Log ": " ")
704            	 << (useSLP ? " SLP reg. " : " No SLP ")
705 mike  1.35          << (useSSL ? " Use SSL " : " No SSL ")
706 mike  1.32 	<< endl;
707            
708 kumpf 1.51     // do we need to run as a daemon ?
709                if (daemonOption)
710                {
711                    if(-1 == cimserver_fork())
712                      exit(-1);
713                }
714            
715 mike  1.32     // try loop to bind the address, and run the server
716                try
717                {
718 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
719 mike  1.32       	slp_client *discovery = new slp_client() ;;
720                    String serviceURL;
721            	serviceURL.assign("service:cim.pegasus://");
722            	String host_name = slp_get_host_name();
723            	serviceURL += host_name;
724            	serviceURL += ":";
725            	serviceURL += address;
726            	char *url = serviceURL.allocateCString();
727            	//	free(host_name);
728 mike  1.35 #endif
729 mike  1.32 
730 mike  1.35 	Monitor monitor;
731 kumpf 1.38 	CIMServer server(&monitor, useSSL);
732 kumpf 1.41 
733            	// bind throws an exception if the bind fails
734            #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
735            	cout << "Binding to domain socket" << endl;
736            #else
737 mike  1.33 	cout << "Binding to " << address << endl;
738 kumpf 1.41 #endif
739 mike  1.35 
740            	server.bind(portNumber);
741 mike  1.32 
742            	time_t last = 0;
743 mike  1.35 
744 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
745                    //
746 kumpf 1.56         // create a file to indicate that the cimserver has started and
747                    // save the process id of the cimserver process in the file
748 kumpf 1.45         //
749 kumpf 1.56 
750                    // remove the old file if it exists
751                    System::removeFile(fname);
752            
753                    // open the file
754                    FILE *pid_file = fopen(fname, "w");
755                    if (pid_file)
756 kumpf 1.45         {
757 kumpf 1.56             // save the pid in the file
758                        fprintf(pid_file, "%ld\n", (long)server_pid);
759                        fclose(pid_file);
760 kumpf 1.45         }
761            #endif
762 kumpf 1.54 	cout << "Started. " << endl;
763            
764                    // Put server started message to the logger
765                    Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
766 kumpf 1.57                     "Started $0 version $1 on port $2.",
767                                PEGASUS_NAME, PEGASUS_VERSION, address);
768            
769 kumpf 1.45 
770 mike  1.35         //
771                    // Loop to call CIMServer's runForever() method until CIMServer
772                    // has been shutdown
773                    //
774            	while( !server.terminated() )
775 mike  1.32 	{
776 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
777 mike  1.32 	  if(useSLP  ) 
778            	  {
779            	    if(  (time(NULL) - last ) > 60 ) 
780            	    {
781            	      if( discovery != NULL && url != NULL )
782            		discovery->srv_reg_all(url,  
783 mike  1.35 				       "(namespace=root/cimv2)",
784 mike  1.32 				       "service:cim.pegasus", 
785            				       "DEFAULT", 
786            				       70) ;
787            	      time(&last);
788            	    }
789            	  
790            	    discovery->service_listener();
791            	  }
792 mike  1.35 #endif
793 mike  1.32 	  server.runForever();
794            	}
795            
796 kumpf 1.45         //
797                    // normal termination
798 mike  1.34 	//
799 kumpf 1.54         // Put server shutdown message to the logger
800                    Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
801                        "$0 stopped.", PEGASUS_NAME);
802 kumpf 1.45 
803            #if defined(PEGASUS_OS_HPUX)
804                    //
805 kumpf 1.56         // close the file created at startup time to indicate that the 
806                    // cimserver has terminated normally.
807 kumpf 1.45         //
808                    FileSystem::removeFile(CIMSERVERSTART_FILE);
809            #endif
810 mike  1.32     }
811                catch(Exception& e)
812                {
813            	Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
814 kumpf 1.58 	    "$0. Abnormal Termination.", e.getMessage());
815 mike  1.32 	
816            	PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
817 kumpf 1.54         return 1;
818 mike  1.32     }
819            
820                return 0;
821            }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2