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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2