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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2