(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.71         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 chuck 1.70         referenceStr.append("/");  
272 kumpf 1.59         referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN);
273 kumpf 1.53         referenceStr.append(":");
274                    referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN);
275 kumpf 1.50         CIMObjectPath reference(referenceStr);
276 mike  1.35 
277                    //
278                    // issue the invokeMethod request on the shutdown method
279                    //
280                    Array<CIMParamValue> inParams;
281                    Array<CIMParamValue> outParams;
282            
283 kumpf 1.52         // set force option to true for now
284 kumpf 1.40         inParams.append(CIMParamValue("force",
285 kumpf 1.52             CIMValue(Boolean(true))));
286 mike  1.35 
287 kumpf 1.40         inParams.append(CIMParamValue("timeout",
288 kumpf 1.39             CIMValue(Uint32(timeoutValue))));
289 mike  1.35 
290                    CIMValue retValue = client.invokeMethod(
291 kumpf 1.59             PEGASUS_NAMESPACENAME_SHUTDOWN,
292 mike  1.35             reference,
293                        "shutdown",
294                        inParams,
295                        outParams);
296 kumpf 1.43     }
297 kumpf 1.65     catch(CIMException& e)
298 kumpf 1.46     {
299                    PEGASUS_STD(cerr) << "Failed to shutdown server: ";
300 kumpf 1.63         if (e.getCode() == CIM_ERR_INVALID_NAMESPACE)
301                    {
302                        PEGASUS_STD(cerr) << "The repository may be empty.";
303                        PEGASUS_STD(cerr) << PEGASUS_STD(endl);
304                    }
305                    else
306                    {
307                        PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
308                    }
309 chuck 1.66 #ifdef PEGASUS_OS_OS400
310                    // Kill the server job.
311            	cimserver_kill();
312            #endif
313 kumpf 1.46         exit(1);
314                }
315 kumpf 1.65     catch(Exception& e)
316 kumpf 1.45     {
317                    //
318 kumpf 1.54         // This may mean the CIM Server has been terminated and returns a 
319                    // "Empty HTTP response message" HTTP error response.  To be sure
320                    // CIM Server gets shutdown, if CIM Server is still running at 
321                    // this time, we will kill the cimserver process.
322 kumpf 1.45         //
323 kumpf 1.56         // give CIM Server some time to finish up
324                    //
325 kumpf 1.63         //System::sleep(1);
326                    //cimserver_kill();
327            
328                    //
329                    // Check to see if CIMServer is still running.  If CIMServer
330                    // is still running and the shutdown timeout has not expired,
331                    // loop and wait one second until either CIM Server is
332                    // terminated or until timeout expires.  If timeout expires
333                    // and CIMServer is still running, kill the CIMServer
334                    // process.
335                    //
336                    Uint32 maxWaitTime = timeoutValue - 2;
337                    Boolean running = isCIMServerRunning();
338                    while ( running && maxWaitTime > 0 )
339                    {
340                        System::sleep(1);
341                        running = isCIMServerRunning();
342                        maxWaitTime = maxWaitTime - 1;
343                    }
344            
345                    if (running)
346 kumpf 1.63         {
347                        cimserver_kill();
348                    }
349 kumpf 1.43     }
350 kumpf 1.65     //catch(Exception& e)
351                //{
352                //    PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: ";
353                //    PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl);
354                //    exit(1);
355                //}
356 mike  1.35 
357                return;
358 mike  1.32 }
359            
360 mike  1.35 
361 mike  1.33 /////////////////////////////////////////////////////////////////////////
362 mike  1.32 //  MAIN
363            //////////////////////////////////////////////////////////////////////////
364            int main(int argc, char** argv)
365            {
366 mike  1.35     String pegasusHome  = String::EMPTY;
367                Boolean pegasusIOLog = false;
368 kumpf 1.53     String httpPort = String::EMPTY;
369                String httpsPort = String::EMPTY;
370 mike  1.35     String logsDirectory = String::EMPTY;
371                Boolean useSLP = false;
372                Boolean useSSL = false;
373                Boolean daemonOption = false;
374                Boolean shutdownOption = false;
375 kumpf 1.60     Uint32 timeoutValue  = 0;
376 mday  1.47 
377 chuck 1.66 #ifdef PEGASUS_OS_OS400
378                // Initialize Pegasus home to the shipped OS/400 directory.
379                pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
380            #endif
381            
382 kumpf 1.38     //
383                // Get environment variables:
384                //
385                const char* tmp = getenv("PEGASUS_HOME");
386            
387                if (tmp)
388                {
389                    pegasusHome = tmp;
390                }
391            
392                FileSystem::translateSlashes(pegasusHome);
393            
394 mike  1.32     // on Windows NT if there are no command-line options, run as a service
395            
396                if (argc == 1 )
397 mike  1.35     {
398                  cim_server_service(argc, argv);
399                }
400                else
401                {
402 kumpf 1.60         // Get help, version, and shutdown options
403 mike  1.35 
404                    for (int i = 1; i < argc; )
405                    {
406                        const char* arg = argv[i];
407            
408                        // Check for -option
409                        if (*arg == '-')
410                        {
411                            // Get the option
412                            const char* option = arg + 1;
413            
414                            //
415                            // Check to see if user asked for the version (-v option):
416                            //
417                            if (*option == OPTION_VERSION)
418                            {
419 kumpf 1.63 #if defined(PEGASUS_OS_HPUX)
420                                cout << PLATFORM_PRODUCT_VERSION << endl;
421            #else
422 mike  1.35                     cout << PEGASUS_VERSION << endl;
423 kumpf 1.63 #endif
424 mike  1.35                     exit(0);
425                            }
426                            //
427                            // Check to see if user asked for help (-h option):
428                            //
429                            else if (*option == OPTION_HELP)
430                            {
431                                PrintHelp(argv[0]);
432                                exit(0);
433                            }
434 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
435 mike  1.35                 else if (*option == OPTION_HOME)
436                            {
437 kumpf 1.60                     if (i + 1 < argc)
438 mike  1.35                     {
439                                    pegasusHome.assign(argv[i + 1]);
440                                }
441                                else
442                                {
443                                    cout << "Missing argument for option -" << option << endl;
444                                    exit(0);
445                                }
446            
447                                memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*));
448                                argc -= 2;
449                            }
450 kumpf 1.63 #endif
451 kumpf 1.48 #if defined(PEGASUS_OS_HPUX)
452                            //
453 kumpf 1.49                 // Check to see if user asked for the version (-X option):
454 kumpf 1.48                 //
455                            if (*option == OPTION_BINDVERBOSE)
456                            {
457            		    System::bindVerbose = true;
458                                cout << "Unsupported debug option, BIND_VERBOSE, enabled." 
459                                     << endl;
460                                // remove the option from the command line
461                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
462                                argc--;   
463                            }
464            #endif
465 mike  1.35                 //
466                            // Check to see if user asked for shutdown (-s option):
467                            //
468                            else if (*option == OPTION_SHUTDOWN)
469                            {
470                                //
471 kumpf 1.52                     // check to see if user is root
472 mike  1.35                     //
473 chuck 1.70 #ifndef PEGASUS_OS_OS400
474 kumpf 1.55                     if (!System::isPrivilegedUser(System::getEffectiveUserName()))
475 mike  1.35                     {
476 kumpf 1.52                         cout << "You must have superuser privilege to run ";
477                                    cout << "cimserver." << endl;
478 mike  1.35                         exit(0);
479                                }
480 chuck 1.70 #endif
481 mike  1.35 
482                                //
483 kumpf 1.52                     // Check to see if shutdown has already been specified:
484 mike  1.35                     //
485 kumpf 1.52                     if (shutdownOption)
486 mike  1.35                     {
487 kumpf 1.52                         cout << "Duplicate shutdown option specified." << endl;
488 mike  1.35                         exit(0);
489                                }
490            
491 kumpf 1.52                     shutdownOption = true;
492 mike  1.35  
493                                // remove the option from the command line
494                                memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*));
495                                argc--;   
496                            }
497                            else
498                                i++;
499                        }
500                        else
501                            i++;
502 mike  1.32         }
503                }
504 mike  1.35 
505 kumpf 1.38     //
506                // Set the value for pegasusHome property
507                //
508                ConfigManager::setPegasusHome(pegasusHome);
509 mike  1.32 
510 mike  1.35     //
511                // Get an instance of the Config Manager.
512                //
513                configManager = ConfigManager::getInstance();
514            
515                //
516 mike  1.32     // Get options (from command line and from configuration file); this
517 mike  1.35     // removes corresponding options and their arguments from the command
518 mike  1.32     // line.
519 mike  1.35     //
520 mike  1.32     try
521                {
522 mike  1.35         GetOptions(configManager, argc, argv, pegasusHome);
523 mike  1.32     }
524                catch (Exception& e)
525                {
526 mike  1.35         cerr << argv[0] << ": " << e.getMessage() << endl;
527                    exit(1);
528 mike  1.32     }
529            
530 mike  1.35     try
531 mike  1.32     {
532 mike  1.35         //
533                    // Check to see if we should (can) install as a NT service
534                    //
535            
536                    if (String::equal(configManager->getCurrentValue("install"), "true"))
537                    {
538                        if( 0 != cimserver_install_nt_service( pegasusHome ))
539                        {
540                            cout << "\nPegasus installed as NT Service";
541                            exit(0);
542                        }
543                    }
544 mike  1.32 
545 mike  1.35         //
546                    // Check to see if we should (can) remove Pegasus as an NT service
547                    //
548            
549                    if (String::equal(configManager->getCurrentValue("remove"), "true"))
550                    {
551                        if( 0 != cimserver_remove_nt_service() )
552                        {
553                            cout << "\nPegasus removed as NT Service";
554                            exit(0);
555                        }
556                    }
557 mike  1.32 
558 mike  1.35         //
559                    // Check to see if we should Pegasus as a daemon
560                    //
561            
562                    if (String::equal(configManager->getCurrentValue("daemon"), "true"))
563                    {
564                        daemonOption = true;
565                    }
566 mday  1.62 	
567 mike  1.35         //
568 kumpf 1.36         // Check the log trace options and set global variable
569                    //
570            
571                    if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
572                    {
573                        pegasusIOLog = true;
574                    }
575            
576                    // Get the log file directory definition.
577                    // We put String into Cstring because
578                    // Directory functions only handle Cstring.
579                    // ATTN-KS: create String based directory functions.
580            
581                    logsDirectory = configManager->getCurrentValue("logdir");
582 kumpf 1.38         logsDirectory = 
583            	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
584 kumpf 1.36 
585                    // Set up the Logger. This does not open the logs
586                    // Might be more logical to clean before set.
587                    // ATTN: Need tool to completely disable logging.
588            
589 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
590 kumpf 1.36         Logger::setHomeDirectory(logsDirectory);
591 kumpf 1.57 #endif
592 kumpf 1.36 
593                    //
594 mike  1.35         // Check to see if we need to shutdown CIMOM 
595                    //
596                    if (shutdownOption)
597                    {
598 kumpf 1.60             String configTimeout = 
599                            configManager->getCurrentValue("shutdownTimeout");
600 kumpf 1.69             timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
601 kumpf 1.60             
602 kumpf 1.52             shutdownCIMOM(timeoutValue);
603 kumpf 1.45 
604 kumpf 1.60             cout << "CIM Server stopped." << endl;
605 mike  1.35             exit(0);
606                    }
607 mike  1.32 
608 mike  1.35         //
609 kumpf 1.53         // Get the port numbers
610 mike  1.35         //
611            
612 kumpf 1.53         httpPort = configManager->getCurrentValue("httpPort");
613            
614                    httpsPort = configManager->getCurrentValue("httpsPort");
615 mike  1.35 
616 kumpf 1.36         // Leave this in until people get familiar with the logs.
617 kumpf 1.57 #ifndef PEGASUS_OS_HPUX
618 kumpf 1.36         cout << "Logs Directory = " << logsDirectory << endl;
619 kumpf 1.57 #endif
620 mike  1.35 
621                    if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
622                    {
623                        Logger::clean(logsDirectory);;
624                    }
625 mike  1.32 
626 mike  1.35         if (String::equal(configManager->getCurrentValue("slp"), "true"))
627                    {
628                        useSLP =  true;
629                    }
630 mike  1.32 
631 mike  1.35         if (String::equal(configManager->getCurrentValue("SSL"), "true"))
632                    {
633                        useSSL =  true;
634                    }
635 mike  1.32     }
636 mike  1.35     catch (UnrecognizedConfigProperty e)
637 mike  1.32     {
638 mike  1.35         cout << "Error: " << e.getMessage() << endl;
639 mike  1.32     }
640            
641 kumpf 1.53     Uint32 portNumber;
642            
643                char address[32];
644            
645                if (useSSL)
646                {
647            	char* end = 0;
648 kumpf 1.69         CString portString = httpsPort.getCString();
649            	Uint32 port = strtol(portString, &end, 10);
650 kumpf 1.53 	assert(end != 0 && *end == '\0');
651            
652                    //
653                    // Look up the WBEM-HTTPS port number 
654                    //
655                    portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
656                    sprintf(address, "%u", portNumber);
657                }
658                else
659                {
660            	char* end = 0;
661 kumpf 1.69         CString portString = httpPort.getCString();
662            	Uint32 port = strtol(portString, &end, 10);
663 kumpf 1.53 	assert(end != 0 && *end == '\0');
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.35 #endif
716 mike  1.32 
717 mday  1.61 	Monitor monitor(true);
718 kumpf 1.38 	CIMServer server(&monitor, useSSL);
719 kumpf 1.41 
720            	// bind throws an exception if the bind fails
721            #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
722            	cout << "Binding to domain socket" << endl;
723 kumpf 1.63 #elif !defined(PEGASUS_OS_HPUX)
724 mike  1.33 	cout << "Binding to " << address << endl;
725 kumpf 1.41 #endif
726 mike  1.35 
727            	server.bind(portNumber);
728 mike  1.32 
729            	time_t last = 0;
730 mike  1.35 
731 kumpf 1.45 #if defined(PEGASUS_OS_HPUX)
732                    //
733 kumpf 1.56         // create a file to indicate that the cimserver has started and
734                    // save the process id of the cimserver process in the file
735 kumpf 1.45         //
736 kumpf 1.56 
737                    // remove the old file if it exists
738                    System::removeFile(fname);
739            
740                    // open the file
741                    FILE *pid_file = fopen(fname, "w");
742                    if (pid_file)
743 kumpf 1.45         {
744 kumpf 1.56             // save the pid in the file
745                        fprintf(pid_file, "%ld\n", (long)server_pid);
746                        fclose(pid_file);
747 kumpf 1.45         }
748            #endif
749 kumpf 1.63 #ifndef PEGASUS_OS_HPUX
750 kumpf 1.54 	cout << "Started. " << endl;
751 kumpf 1.63 #endif
752 kumpf 1.54 
753                    // Put server started message to the logger
754 kumpf 1.63 #ifdef PEGASUS_OS_HPUX
755                    Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
756                                "Started $0 version $1 on port $2.",
757                                PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION, address);
758            #else
759 kumpf 1.54         Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
760 kumpf 1.57                     "Started $0 version $1 on port $2.",
761                                PEGASUS_NAME, PEGASUS_VERSION, address);
762 kumpf 1.63 #endif
763 kumpf 1.45 
764 mday  1.62 	
765 mike  1.35         //
766                    // Loop to call CIMServer's runForever() method until CIMServer
767                    // has been shutdown
768                    //
769            	while( !server.terminated() )
770 mike  1.32 	{
771 kumpf 1.44 #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX)
772 mike  1.32 	  if(useSLP  ) 
773            	  {
774            	    if(  (time(NULL) - last ) > 60 ) 
775            	    {
776 kumpf 1.69 	      if( discovery != NULL && serviceURL.size() )
777            		discovery->srv_reg_all(serviceURL.getCString(),
778 mike  1.35 				       "(namespace=root/cimv2)",
779 mike  1.32 				       "service:cim.pegasus", 
780            				       "DEFAULT", 
781            				       70) ;
782            	      time(&last);
783            	    }
784            	  
785            	    discovery->service_listener();
786            	  }
787 mike  1.35 #endif
788 mike  1.32 	  server.runForever();
789            	}
790            
791 kumpf 1.45         //
792                    // normal termination
793 mike  1.34 	//
794 kumpf 1.54         // Put server shutdown message to the logger
795                    Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
796                        "$0 stopped.", PEGASUS_NAME);
797 kumpf 1.45 
798            #if defined(PEGASUS_OS_HPUX)
799                    //
800 kumpf 1.56         // close the file created at startup time to indicate that the 
801                    // cimserver has terminated normally.
802 kumpf 1.45         //
803                    FileSystem::removeFile(CIMSERVERSTART_FILE);
804            #endif
805 mike  1.32     }
806                catch(Exception& e)
807                {
808            	PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
809 kumpf 1.54         return 1;
810 mike  1.32     }
811            
812                return 0;
813            }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2