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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2