(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 kumpf 1.72 //              Carol Ann Krug Graves, Hewlett-Packard Company
 36            //                (carolann_graves@hp.com)
 37 kumpf 1.38 //
 38 mike  1.32 //%/////////////////////////////////////////////////////////////////////////////
 39            
 40            
 41            //////////////////////////////////////////////////////////////////////
 42            //
 43            // Notes on deamon operation (Unix) and service operation (Win 32):
 44            //
 45 kumpf 1.60 // To run pegasus as a daemon on Unix platforms: 
 46 mike  1.32 //
 47 kumpf 1.60 // cimserver
 48 mike  1.32 //
 49 kumpf 1.60 // To NOT run pegasus as a daemon on Unix platforms, set the daemon config
 50            // property to false:
 51            //
 52            // cimserver daemon=false
 53            //
 54            // The daemon config property has no effect on windows operation. 
 55 mike  1.32 //
 56 mike  1.35 // To shutdown pegasus, use the -s option:
 57            // 
 58 kumpf 1.60 // cimserver -s 
 59 mike  1.35 //
 60 mike  1.32 // To run pegasus as an NT service, there are FOUR  different possibilities:
 61            //
 62            // To INSTALL the Pegasus service, 
 63            //
 64            // cimserver -install
 65            //
 66            // To REMOVE the Pegasus service, 
 67            //
 68            // cimserver -remove
 69            //
 70            // To START the Pegasus service, 
 71            //
 72            // net start cimserver
 73            //
 74            // To STOP the Pegasus service, 
 75            //
 76            // net stop cimserver
 77            //
 78            // Alternatively, you can use the windows service manager. Pegasus shows up 
 79            // in the service database as "Pegasus CIM Object Manager"
 80            //
 81 mike  1.32 // Mike Day, mdday@us.ibm.com
 82            // 
 83            //////////////////////////////////////////////////////////////////////
 84            
 85            
 86 mike  1.35 #include <Pegasus/Common/Config.h>
 87 kumpf 1.59 #include <Pegasus/Common/Constants.h>
 88 mike  1.32 #include <iostream>
 89 mike  1.35 #include <cassert>
 90 mike  1.32 #include <cstdlib>
 91 kumpf 1.45 #include <fstream>
 92 mike  1.32 #include <Pegasus/Common/FileSystem.h>
 93 mike  1.35 #include <Pegasus/Common/Monitor.h>
 94 mike  1.32 #include <Pegasus/Server/CIMServer.h>
 95            #include <Pegasus/Common/PegasusVersion.h>
 96            #include <Pegasus/Common/Logger.h>
 97            #include <Pegasus/Common/System.h>
 98 mike  1.35 #include <Pegasus/Common/Tracer.h>
 99            #include <Pegasus/Config/ConfigManager.h>
100            #include <Pegasus/Client/CIMClient.h>
101            #include <Pegasus/Server/ShutdownService.h>
102 kumpf 1.38 #include <Pegasus/Common/Destroyer.h>
103 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
104 mike  1.32 #include <slp/slp.h>
105 mike  1.35 #endif
106 mike  1.32 
107            
108            #if defined(PEGASUS_OS_TYPE_WINDOWS)
109            # include "cimserver_windows.cpp"
110            #elif defined(PEGASUS_OS_TYPE_UNIX)
111 chuck 1.66 # if defined(PEGASUS_OS_OS400)
112            #  include "cimserver_os400.cpp"
113            # else
114            #  include "cimserver_unix.cpp"
115            #endif
116 mike  1.32 #else
117            # error "Unsupported platform"
118            #endif
119            
120            PEGASUS_USING_PEGASUS;
121            PEGASUS_USING_STD;
122            
123 mike  1.35 //
124            //  The command name.
125            //
126            static const char COMMAND_NAME []    = "cimserver";
127            
128            //
129            //  The constant defining usage string.
130            //
131            static const char USAGE []           = "Usage: ";
132            
133            /**
134            Constants representing the command line options.
135            */
136            static const char OPTION_VERSION     = 'v';
137            
138            static const char OPTION_HELP        = 'h';
139            
140            static const char OPTION_HOME        = 'D';
141            
142            static const char OPTION_SHUTDOWN    = 's';
143            
144 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
145            static const char OPTION_BINDVERBOSE = 'X';
146            #endif
147            
148 kumpf 1.54 static const String PROPERTY_TIMEOUT = "shutdownTimeout";
149 kumpf 1.63 static const String CIMSERVERSTART_FILE = "/etc/opt/wbem/cimserver_start.conf";
150 mike  1.35 
151            ConfigManager*    configManager;
152            
153 mike  1.32 /** GetOptions function - This function defines the Options Table
154 mike  1.35     and sets up the options from that table using the config manager.
155 mike  1.32 */
156            void GetOptions(
157 mike  1.35     ConfigManager* cm,
158 mike  1.32     int& argc,
159                char** argv,
160                const String& pegasusHome)
161            {
162 mike  1.35     try
163 mike  1.32     {
164 kumpf 1.38         cm->mergeConfigFiles();
165 mike  1.33 
166 mike  1.35         cm->mergeCommandLine(argc, argv);
167                }
168                catch (NoSuchFile nsf)
169                {
170                    throw nsf;
171                }
172                catch (FileNotReadable fnr)
173                {
174                    throw fnr;
175                }
176                catch (CannotRenameFile ftrf)
177                {
178                    throw ftrf;
179                }
180                catch (ConfigFileSyntaxError cfse)
181                {
182                    throw cfse;
183                }
184                catch(UnrecognizedConfigProperty ucp)
185                {
186                    throw ucp;
187 mike  1.35     }
188                catch(InvalidPropertyValue ipv)
189                {
190                    throw ipv;
191                }
192 mike  1.32 }
193            
194            /* PrintHelp - This is temporary until we expand the options manager to allow
195               options help to be defined with the OptionRow entries and presented from
196               those entries.
197            */
198            void PrintHelp(const char* arg0)
199            {
200 mike  1.35     /**
201                    Build the usage string for the config command.
202                */
203                String usage = String (USAGE);
204                usage.append (COMMAND_NAME);
205                usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n");
206                usage.append ("  options\n");
207 kumpf 1.60     usage.append ("    -v          - displays CIM Server version number\n");
208 mike  1.35     usage.append ("    -h          - prints this help message\n");
209 kumpf 1.60     usage.append ("    -s          - shuts down CIM Server\n");
210            #ifndef PEGASUS_OS_HPUX
211 mike  1.35     usage.append ("    -D [home]   - sets pegasus home directory\n");
212 kumpf 1.60 #endif
213            #if defined(PEGASUS_OS_TYPE_WINDOWS)
214 mike  1.35     usage.append ("    -install    - installs pegasus as a Windows NT Service\n");
215                usage.append ("    -remove     - removes pegasus as a Windows NT Service\n");
216 kumpf 1.54 #endif
217 mike  1.35     usage.append ("  configProperty=value\n");
218 kumpf 1.60     usage.append ("                - sets CIM Server configuration property\n");
219 mike  1.35 
220                cout << endl;
221 kumpf 1.63 #if defined(PEGASUS_OS_HPUX)
222                cout << PLATFORM_PRODUCT_NAME << " " << PLATFORM_PRODUCT_VERSION << endl;
223            #else
224 mike  1.32     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
225 kumpf 1.63 #endif
226 mike  1.32     cout << endl;
227 mike  1.35     cout << usage << endl;
228            }
229            
230 kumpf 1.52 void shutdownCIMOM(Uint32 timeoutValue)
231 mike  1.35 {
232                //
233                // Create CIMClient object
234                //
235 kumpf 1.42     CIMClient client;
236 mike  1.35 
237                //
238 kumpf 1.53     // Get local host name
239 mike  1.35     //
240                String hostStr = System::getHostName();
241            
242                //
243                // open connection to CIMOM 
244                //
245                try
246                {
247 kumpf 1.43         client.connectLocal();
248 kumpf 1.52 
249                    //
250 kumpf 1.63         // set client timeout to 2 seconds
251 kumpf 1.52         //
252 kumpf 1.71         client.setTimeout(2000);
253 mike  1.35     }
254 kumpf 1.64     catch(Exception& e)
255 mike  1.35     {
256 kumpf 1.52         PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl);
257                    PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl);
258 chuck 1.66 #ifdef PEGASUS_OS_OS400
259                    // The server job may still be active but not responding.
260                    // Kill the job if it exists.
261            	cimserver_kill();
262            #endif
263 kumpf 1.45         exit(0);
264 mike  1.35     }
265            
266                try
267                {
268                    //
269 kumpf 1.52         // construct CIMObjectPath
270 mike  1.35         //
271                    String referenceStr = "//";
272                    referenceStr.append(hostStr);
273 chuck 1.70         referenceStr.append("/");  
274 kumpf 1.72         referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString());
275 kumpf 1.53         referenceStr.append(":");
276 kumpf 1.72         referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString());
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 kumpf 1.59             PEGASUS_NAMESPACENAME_SHUTDOWN,
294 mike  1.35             reference,
295                        "shutdown",
296                        inParams,
297                        outParams);
298 kumpf 1.43     }
299 kumpf 1.65     catch(CIMException& e)
300 kumpf 1.46     {
301                    PEGASUS_STD(cerr) << "Failed to shutdown server: ";
302 kumpf 1.63         if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
303                    {
304                        PEGASUS_STD(cerr) << "The repository may be empty.";
305                        PEGASUS_STD(cerr) << PEGASUS_STD(endl);
306                    }
307                    else
308                    {
309                        PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
310                    }
311 chuck 1.66 #ifdef PEGASUS_OS_OS400
312                    // Kill the server job.
313            	cimserver_kill();
314            #endif
315 kumpf 1.46         exit(1);
316                }
317 kumpf 1.65     catch(Exception& e)
318 kumpf 1.45     {
319                    //
320 kumpf 1.54         // This may mean the CIM Server has been terminated and returns a 
321                    // "Empty HTTP response message" HTTP error response.  To be sure
322                    // CIM Server gets shutdown, if CIM Server is still running at 
323                    // this time, we will kill the cimserver process.
324 kumpf 1.45         //
325 kumpf 1.56         // give CIM Server some time to finish up
326                    //
327 kumpf 1.63         //System::sleep(1);
328                    //cimserver_kill();
329            
330                    //
331                    // Check to see if CIMServer is still running.  If CIMServer
332                    // is still running and the shutdown timeout has not expired,
333                    // loop and wait one second until either CIM Server is
334                    // terminated or until timeout expires.  If timeout expires
335                    // and CIMServer is still running, kill the CIMServer
336                    // process.
337                    //
338                    Uint32 maxWaitTime = timeoutValue - 2;
339                    Boolean running = isCIMServerRunning();
340                    while ( running && maxWaitTime > 0 )
341                    {
342                        System::sleep(1);
343                        running = isCIMServerRunning();
344                        maxWaitTime = maxWaitTime - 1;
345                    }
346            
347                    if (running)
348 kumpf 1.63         {
349                        cimserver_kill();
350                    }
351 kumpf 1.43     }
352 kumpf 1.65     //catch(Exception& e)
353                //{
354                //    PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: ";
355                //    PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
356                //    exit(1);
357                //}
358 mike  1.35 
359                return;
360 mike  1.32 }
361            
362 mike  1.35 
363 mike  1.33 /////////////////////////////////////////////////////////////////////////
364 mike  1.32 //  MAIN
365            //////////////////////////////////////////////////////////////////////////
366            int main(int argc, char** argv)
367            {
368 mike  1.35     String pegasusHome  = String::EMPTY;
369                Boolean pegasusIOLog = false;
370 kumpf 1.53     String httpPort = String::EMPTY;
371                String httpsPort = String::EMPTY;
372 mike  1.35     String logsDirectory = String::EMPTY;
373                Boolean useSLP = false;
374                Boolean useSSL = false;
375                Boolean daemonOption = false;
376                Boolean shutdownOption = false;
377 kumpf 1.60     Uint32 timeoutValue  = 0;
378 mday  1.47 
379 chuck 1.66 #ifdef PEGASUS_OS_OS400
380                // Initialize Pegasus home to the shipped OS/400 directory.
381                pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
382            #endif
383            
384 kumpf 1.38     //
385                // Get environment variables:
386                //
387                const char* tmp = getenv("PEGASUS_HOME");
388            
389                if (tmp)
390                {
391                    pegasusHome = tmp;
392                }
393            
394                FileSystem::translateSlashes(pegasusHome);
395            
396 mike  1.32     // on Windows NT if there are no command-line options, run as a service
397            
398                if (argc == 1 )
399 mike  1.35     {
400                  cim_server_service(argc, argv);
401                }
402                else
403                {
404 kumpf 1.60         // Get help, version, and shutdown options
405 mike  1.35 
406                    for (int i = 1; i < argc; )
407                    {
408                        const char* arg = argv[i];
409            
410                        // Check for -option
411                        if (*arg == '-')
412                        {
413                            // Get the option
414                            const char* option = arg + 1;
415            
416                            //
417                            // Check to see if user asked for the version (-v option):
418                            //
419                            if (*option == OPTION_VERSION)
420                            {
421 kumpf 1.63 #if defined(PEGASUS_OS_HPUX)
422                                cout << PLATFORM_PRODUCT_VERSION << endl;
423            #else
424 mike  1.35                     cout << PEGASUS_VERSION << endl;
425 kumpf 1.63 #endif
426 mike  1.35                     exit(0);
427                            }
428                            //
429                            // Check to see if user asked for help (-h option):
430                            //
431                            else if (*option == OPTION_HELP)
432                            {
433                                PrintHelp(argv[0]);
434                                exit(0);
435                            }
436 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
437 mike  1.35                 else if (*option == OPTION_HOME)
438                            {
439 kumpf 1.60                     if (i + 1 < argc)
440 mike  1.35                     {
441                                    pegasusHome.assign(argv[i + 1]);
442                                }
443                                else
444                                {
445                                    cout << "Missing argument for option -" << option << endl;
446                                    exit(0);
447                                }
448            
449                                memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
450                                argc -= 2;
451                            }
452 kumpf 1.63 #endif
453 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
454                            //
455 kumpf 1.49                 // Check to see if user asked for the version (-X option):
456 kumpf 1.48                 //
457                            if (*option == OPTION_BINDVERBOSE)
458                            {
459            		    System::bindVerbose = true;
460                                cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
461                                     << endl;
462                                // remove the option from the command line
463                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
464                                argc--;   
465                            }
466            #endif
467 mike  1.35                 //
468                            // Check to see if user asked for shutdown (-s option):
469                            //
470                            else if (*option == OPTION_SHUTDOWN)
471                            {
472                                //
473 kumpf 1.52                     // check to see if user is root
474 mike  1.35                     //
475 chuck 1.70 #ifndef PEGASUS_OS_OS400
476 kumpf 1.55                     if (!System::isPrivilegedUser(System::getEffectiveUserName()))
477 mike  1.35                     {
478 kumpf 1.52                         cout << "You must have superuser privilege to run ";
479                                    cout << "cimserver." << endl;
480 mike  1.35                         exit(0);
481                                }
482 chuck 1.70 #endif
483 mike  1.35 
484                                //
485 kumpf 1.52                     // Check to see if shutdown has already been specified:
486 mike  1.35                     //
487 kumpf 1.52                     if (shutdownOption)
488 mike  1.35                     {
489 kumpf 1.52                         cout << "Duplicate shutdown option specified." << endl;
490 mike  1.35                         exit(0);
491                                }
492            
493 kumpf 1.52                     shutdownOption = true;
494 mike  1.35  
495                                // remove the option from the command line
496                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
497                                argc--;   
498                            }
499                            else
500                                i++;
501                        }
502                        else
503                            i++;
504 mike  1.32         }
505                }
506 mike  1.35 
507 kumpf 1.38     //
508                // Set the value for pegasusHome property
509                //
510                ConfigManager::setPegasusHome(pegasusHome);
511 mike  1.32 
512 mike  1.35     //
513                // Get an instance of the Config Manager.
514                //
515                configManager = ConfigManager::getInstance();
516            
517                //
518 mike  1.32     // Get options (from command line and from configuration file); this
519 mike  1.35     // removes corresponding options and their arguments from the command
520 mike  1.32     // line.
521 mike  1.35     //
522 mike  1.32     try
523                {
524 mike  1.35         GetOptions(configManager, argc, argv, pegasusHome);
525 mike  1.32     }
526                catch (Exception& e)
527                {
528 mike  1.35         cerr << argv[0] << ": " << e.getMessage() << endl;
529                    exit(1);
530 mike  1.32     }
531            
532 mike  1.35     try
533 mike  1.32     {
534 mike  1.35         //
535                    // Check to see if we should (can) install as a NT service
536                    //
537            
538                    if (String::equal(configManager->getCurrentValue("install"), "true"))
539                    {
540                        if( 0 != cimserver_install_nt_service( pegasusHome ))
541                        {
542                            cout << "\nPegasus installed as NT Service";
543                            exit(0);
544                        }
545                    }
546 mike  1.32 
547 mike  1.35         //
548                    // Check to see if we should (can) remove Pegasus as an NT service
549                    //
550            
551                    if (String::equal(configManager->getCurrentValue("remove"), "true"))
552                    {
553                        if( 0 != cimserver_remove_nt_service() )
554                        {
555                            cout << "\nPegasus removed as NT Service";
556                            exit(0);
557                        }
558                    }
559 mike  1.32 
560 mike  1.35         //
561                    // Check to see if we should Pegasus as a daemon
562                    //
563            
564                    if (String::equal(configManager->getCurrentValue("daemon"), "true"))
565                    {
566                        daemonOption = true;
567                    }
568 mday  1.62 	
569 mike  1.35         //
570 kumpf 1.36         // Check the log trace options and set global variable
571                    //
572            
573                    if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
574                    {
575                        pegasusIOLog = true;
576                    }
577            
578                    // Get the log file directory definition.
579                    // We put String into Cstring because
580                    // Directory functions only handle Cstring.
581                    // ATTN-KS: create String based directory functions.
582            
583                    logsDirectory = configManager->getCurrentValue("logdir");
584 kumpf 1.38         logsDirectory = 
585            	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
586 kumpf 1.36 
587                    // Set up the Logger. This does not open the logs
588                    // Might be more logical to clean before set.
589                    // ATTN: Need tool to completely disable logging.
590            
591 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
592 kumpf 1.36         Logger::setHomeDirectory(logsDirectory);
593 kumpf 1.57 #endif
594 kumpf 1.36 
595                    //
596 mike  1.35         // Check to see if we need to shutdown CIMOM 
597                    //
598                    if (shutdownOption)
599                    {
600 kumpf 1.60             String configTimeout = 
601                            configManager->getCurrentValue("shutdownTimeout");
602 kumpf 1.69             timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
603 kumpf 1.60             
604 kumpf 1.52             shutdownCIMOM(timeoutValue);
605 kumpf 1.45 
606 kumpf 1.60             cout << "CIM Server stopped." << endl;
607 mike  1.35             exit(0);
608                    }
609 mike  1.32 
610 mike  1.35         //
611 kumpf 1.53         // Get the port numbers
612 mike  1.35         //
613            
614 kumpf 1.53         httpPort = configManager->getCurrentValue("httpPort");
615            
616                    httpsPort = configManager->getCurrentValue("httpsPort");
617 mike  1.35 
618 kumpf 1.36         // Leave this in until people get familiar with the logs.
619 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
620 kumpf 1.36         cout << "Logs Directory = " << logsDirectory << endl;
621 kumpf 1.57 #endif
622 mike  1.35 
623                    if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
624                    {
625                        Logger::clean(logsDirectory);;
626                    }
627 mike  1.32 
628 mike  1.35         if (String::equal(configManager->getCurrentValue("slp"), "true"))
629                    {
630                        useSLP =  true;
631                    }
632 mike  1.32 
633 mike  1.35         if (String::equal(configManager->getCurrentValue("SSL"), "true"))
634                    {
635                        useSSL =  true;
636                    }
637 mike  1.32     }
638 mike  1.35     catch (UnrecognizedConfigProperty e)
639 mike  1.32     {
640 mike  1.35         cout << "Error: " << e.getMessage() << endl;
641 mike  1.32     }
642            
643 kumpf 1.53     Uint32 portNumber;
644            
645                char address[32];
646            
647                if (useSSL)
648                {
649            	char* end = 0;
650 kumpf 1.69         CString portString = httpsPort.getCString();
651            	Uint32 port = strtol(portString, &end, 10);
652 kumpf 1.53 	assert(end != 0 && *end == '\0');
653            
654                    //
655                    // Look up the WBEM-HTTPS port number 
656                    //
657                    portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
658                    sprintf(address, "%u", portNumber);
659                }
660                else
661                {
662            	char* end = 0;
663 kumpf 1.69         CString portString = httpPort.getCString();
664            	Uint32 port = strtol(portString, &end, 10);
665 kumpf 1.53 	assert(end != 0 && *end == '\0');
666            
667                    //
668                    // Look up the WBEM-HTTP port number 
669                    //
670                    portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
671                    sprintf(address, "%u", portNumber);
672                }
673 mike  1.32 
674                // Put out startup up message.
675 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
676 mike  1.32     cout << PEGASUS_NAME << PEGASUS_VERSION <<
677            	 " on port " << address << endl;
678                cout << "Built " << __DATE__ << " " << __TIME__ << endl;
679 kumpf 1.54     cout <<"Starting..."
680 mike  1.32          << (pegasusIOLog ? " Tracing to Log ": " ")
681            	 << (useSLP ? " SLP reg. " : " No SLP ")
682 mike  1.35          << (useSSL ? " Use SSL " : " No SSL ")
683 mike  1.32 	<< endl;
684 kumpf 1.63 #endif
685 mike  1.32 
686 kumpf 1.63     // do we need to run as a daemon ?
687                if (daemonOption)
688                {
689                    if(-1 == cimserver_fork())
690                      exit(-1);
691                }
692 chuck 1.66 
693            #ifdef PEGASUS_OS_OS400
694                // Special server initialization code for OS/400.
695                if (cimserver_initialize() != 0)
696                {
697                   // do some logging here!
698                   exit(-1);
699                } 
700            #endif
701 mday  1.62 
702 kumpf 1.63 #ifdef PEGASUS_OS_HPUX
703                umask(S_IWGRP|S_IWOTH);
704            #endif
705 kumpf 1.51 
706 mike  1.32     // try loop to bind the address, and run the server
707                try
708                {
709 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
710 mike  1.32       	slp_client *discovery = new slp_client() ;;
711                    String serviceURL;
712            	serviceURL.assign("service:cim.pegasus://");
713            	String host_name = slp_get_host_name();
714 kumpf 1.67 	serviceURL.append(host_name);
715            	serviceURL.append(":");
716            	serviceURL.append(address);
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 kumpf 1.69 	      if( discovery != NULL && serviceURL.size() )
779            		discovery->srv_reg_all(serviceURL.getCString(),
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