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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2