(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                String logsDirectory = String::EMPTY;
374                Boolean useSLP = 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.80 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
422 kumpf 1.63                     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.80 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
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 kumpf 1.81.4.1     // The "SSL" property overrides the enableHttp*Connection properties and
533                    // enables only the HTTPS connection.
534                    Boolean enableHttpConnection = (String::equal(
535                        configManager->getCurrentValue("enableHttpConnection"), "true") &&
536                        !String::equal(configManager->getCurrentValue("SSL"), "true"));
537                    Boolean enableHttpsConnection = (String::equal(
538                        configManager->getCurrentValue("enableHttpsConnection"), "true") ||
539                        String::equal(configManager->getCurrentValue("SSL"), "true"));
540                
541                    // Make sure at least one connection is enabled
542                #ifndef PEGASUS_LOCAL_DOMAIN_SOCKET
543                    if (!enableHttpConnection && !enableHttpsConnection)
544                    {
545                        Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
546                            "Neither HTTP nor HTTPS connection is enabled.  "
547                            "CIMServer will not be started.");
548                        cerr << "Neither HTTP nor HTTPS connection is enabled.  "
549                            "CIMServer will not be started." << endl;
550                        exit(1);
551                    }
552                #endif
553 kumpf 1.81.4.1 
554 mike  1.35         try
555 mike  1.32         {
556 mike  1.35             //
557                        // Check to see if we should (can) install as a NT service
558                        //
559                
560                        if (String::equal(configManager->getCurrentValue("install"), "true"))
561                        {
562                            if( 0 != cimserver_install_nt_service( pegasusHome ))
563                            {
564                                cout << "\nPegasus installed as NT Service";
565                                exit(0);
566                            }
567                        }
568 mike  1.32     
569 mike  1.35             //
570                        // Check to see if we should (can) remove Pegasus as an NT service
571                        //
572                
573                        if (String::equal(configManager->getCurrentValue("remove"), "true"))
574                        {
575                            if( 0 != cimserver_remove_nt_service() )
576                            {
577                                cout << "\nPegasus removed as NT Service";
578                                exit(0);
579                            }
580                        }
581 mike  1.32     
582 mike  1.35             //
583                        // Check to see if we should Pegasus as a daemon
584                        //
585                
586                        if (String::equal(configManager->getCurrentValue("daemon"), "true"))
587                        {
588                            daemonOption = true;
589                        }
590 mday  1.62     	
591 mike  1.35             //
592 kumpf 1.36             // Check the log trace options and set global variable
593                        //
594                
595                        if (String::equal(configManager->getCurrentValue("logtrace"), "true"))
596                        {
597                            pegasusIOLog = true;
598                        }
599                
600                        // Get the log file directory definition.
601                        // We put String into Cstring because
602                        // Directory functions only handle Cstring.
603                        // ATTN-KS: create String based directory functions.
604                
605                        logsDirectory = configManager->getCurrentValue("logdir");
606 kumpf 1.38             logsDirectory = 
607                	    ConfigManager::getHomedPath(configManager->getCurrentValue("logdir"));
608 kumpf 1.36     
609                        // Set up the Logger. This does not open the logs
610                        // Might be more logical to clean before set.
611                        // ATTN: Need tool to completely disable logging.
612                
613 kumpf 1.80     #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
614 kumpf 1.36             Logger::setHomeDirectory(logsDirectory);
615 kumpf 1.57     #endif
616 kumpf 1.36     
617                        //
618 mike  1.35             // Check to see if we need to shutdown CIMOM 
619                        //
620                        if (shutdownOption)
621                        {
622 kumpf 1.60                 String configTimeout = 
623                                configManager->getCurrentValue("shutdownTimeout");
624 kumpf 1.69                 timeoutValue = strtol(configTimeout.getCString(), (char **)0, 10);
625 kumpf 1.60                 
626 kumpf 1.52                 shutdownCIMOM(timeoutValue);
627 kumpf 1.45     
628 kumpf 1.60                 cout << "CIM Server stopped." << endl;
629 diane 1.81     #ifdef PEGASUS_OS_OS400
630                	    return(0);
631                #endif
632 mike  1.35                 exit(0);
633                        }
634 mike  1.32     
635 kumpf 1.36             // Leave this in until people get familiar with the logs.
636 kumpf 1.80     #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
637 kumpf 1.36             cout << "Logs Directory = " << logsDirectory << endl;
638 kumpf 1.57     #endif
639 mike  1.35     
640                        if (String::equal(configManager->getCurrentValue("cleanlogs"), "true"))
641                        {
642                            Logger::clean(logsDirectory);;
643                        }
644 mike  1.32     
645 mike  1.35             if (String::equal(configManager->getCurrentValue("slp"), "true"))
646                        {
647                            useSLP =  true;
648                        }
649 mike  1.32         }
650 mike  1.35         catch (UnrecognizedConfigProperty e)
651 mike  1.32         {
652 mike  1.35             cout << "Error: " << e.getMessage() << endl;
653 mike  1.32         }
654                
655 kumpf 1.81.4.1     Uint32 portNumberHttps;
656                    Uint32 portNumberHttp;
657 kumpf 1.53     
658 kumpf 1.81.4.1     if (enableHttpsConnection)
659 kumpf 1.53         {
660 kumpf 1.81.4.1         String httpsPort = configManager->getCurrentValue("httpsPort");
661 kumpf 1.69             CString portString = httpsPort.getCString();
662 kumpf 1.81.4.1 	char* end = 0;
663 kumpf 1.69     	Uint32 port = strtol(portString, &end, 10);
664 kumpf 1.53     	assert(end != 0 && *end == '\0');
665                
666                        //
667                        // Look up the WBEM-HTTPS port number 
668                        //
669 kumpf 1.81.4.1         portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port);
670 kumpf 1.53         }
671 kumpf 1.81.4.1 
672                    if (enableHttpConnection)
673 kumpf 1.53         {
674 kumpf 1.81.4.1         String httpPort = configManager->getCurrentValue("httpPort");
675 kumpf 1.69             CString portString = httpPort.getCString();
676 kumpf 1.81.4.1 	char* end = 0;
677 kumpf 1.69     	Uint32 port = strtol(portString, &end, 10);
678 kumpf 1.53     	assert(end != 0 && *end == '\0');
679                
680                        //
681                        // Look up the WBEM-HTTP port number 
682                        //
683 kumpf 1.81.4.1         portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port);
684 kumpf 1.53         }
685 mike  1.32     
686                    // Put out startup up message.
687 kumpf 1.80     #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
688 kumpf 1.81.4.1     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
689 mike  1.32         cout << "Built " << __DATE__ << " " << __TIME__ << endl;
690 kumpf 1.54         cout <<"Starting..."
691 mike  1.32              << (pegasusIOLog ? " Tracing to Log ": " ")
692                	 << (useSLP ? " SLP reg. " : " No SLP ")
693                	<< endl;
694 kumpf 1.63     #endif
695 mike  1.32     
696 kumpf 1.63         // do we need to run as a daemon ?
697                    if (daemonOption)
698                    {
699                        if(-1 == cimserver_fork())
700 diane 1.81     #ifndef PEGASUS_OS_OS400
701 kumpf 1.63               exit(-1);
702 diane 1.81     #else
703                          return(-1);
704                	else
705                	  return(0);
706                #endif
707 kumpf 1.63         }
708 chuck 1.66     
709                #ifdef PEGASUS_OS_OS400
710                    // Special server initialization code for OS/400.
711                    if (cimserver_initialize() != 0)
712                    {
713                       // do some logging here!
714                       exit(-1);
715                    } 
716                #endif
717 mday  1.62     
718 kumpf 1.63     #ifdef PEGASUS_OS_HPUX
719                    umask(S_IWGRP|S_IWOTH);
720 kumpf 1.79     
721                    //
722                    // check if CIMServer is already running
723                    // if CIMServer is already running, print message and 
724                    // notify parent process (if there is a parent process) to terminate
725                    //
726                    if(isCIMServerRunning())
727                    {
728                	cout << "Unable to start CIMServer." << endl;
729                	cout << "CIMServer is already running." << endl;
730                
731                	//
732                        // notify parent process (if there is a parent process) to terminate
733                        //
734                        if (daemonOption)
735                                notify_parent();
736                
737                        exit(1);
738                    }
739                     
740 kumpf 1.63     #endif
741 kumpf 1.51     
742 mike  1.32         // try loop to bind the address, and run the server
743                    try
744                    {
745 kumpf 1.75     #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
746 kumpf 1.81.4.1         char slp_address[32];
747 mike  1.32           	slp_client *discovery = new slp_client() ;;
748                        String serviceURL;
749                	serviceURL.assign("service:cim.pegasus://");
750                	String host_name = slp_get_host_name();
751 kumpf 1.67     	serviceURL.append(host_name);
752                	serviceURL.append(":");
753 kumpf 1.81.4.1         // ATTN: Fix this to work for multiple connections
754                        sprintf(slp_address, "%u",
755                                enableHttpConnection ? portNumberHttp : portNumberHttps);
756                	serviceURL.append(slp_address);
757 mike  1.35     #endif
758 mike  1.32     
759 mday  1.61     	Monitor monitor(true);
760 kumpf 1.81.4.1 	CIMServer server(&monitor);
761 kumpf 1.41     
762 kumpf 1.81.4.1         if (enableHttpConnection)
763                        {
764                            server.addAcceptor(false, portNumberHttp, false);
765                            Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
766                                        "Listening on HTTP port $0.", portNumberHttp);
767                        }
768                        if (enableHttpsConnection)
769                        {
770                            server.addAcceptor(false, portNumberHttps, true);
771                            Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
772                                        "Listening on HTTPS port $0.", portNumberHttps);
773                        }
774 kumpf 1.41     #ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
775 kumpf 1.81.4.1         server.addAcceptor(true, 0, false);
776                        Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
777                                    "Listening on local connection socket.");
778 kumpf 1.41     #endif
779 mike  1.35     
780 kumpf 1.81.4.1 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
781                        if (enableHttpConnection)
782                        {
783                            cout << "Listening on HTTP port " << portNumberHttp << endl;
784                        }
785                        if (enableHttpsConnection)
786                        {
787                            cout << "Listening on HTTPS port " << portNumberHttps << endl;
788                        }
789                # ifdef PEGASUS_LOCAL_DOMAIN_SOCKET
790                        cout << "Listening on local connection socket" << endl;
791                # endif
792                #endif
793                
794                	// bind throws an exception if the bind fails
795                        server.bind();
796 kumpf 1.73     
797 dan   1.76     	// notify parent process (if there is a parent process) to terminate 
798                        // so user knows that cimserver is ready to serve CIM requests.
799                	if (daemonOption)
800                		notify_parent();
801 mike  1.32     
802                	time_t last = 0;
803 mike  1.35     
804 kumpf 1.45     #if defined(PEGASUS_OS_HPUX)
805                        //
806 kumpf 1.56             // create a file to indicate that the cimserver has started and
807                        // save the process id of the cimserver process in the file
808 kumpf 1.45             //
809 kumpf 1.56     
810                        // remove the old file if it exists
811                        System::removeFile(fname);
812                
813                        // open the file
814                        FILE *pid_file = fopen(fname, "w");
815                        if (pid_file)
816 kumpf 1.45             {
817 kumpf 1.56                 // save the pid in the file
818                            fprintf(pid_file, "%ld\n", (long)server_pid);
819                            fclose(pid_file);
820 kumpf 1.45             }
821                #endif
822 kumpf 1.80     #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
823 kumpf 1.54     	cout << "Started. " << endl;
824 kumpf 1.63     #endif
825 kumpf 1.54     
826                        // Put server started message to the logger
827 kumpf 1.80     #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
828 kumpf 1.63             Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
829 kumpf 1.81.4.1                     "Started $0 version $1.",
830                                    PLATFORM_PRODUCT_NAME, PLATFORM_PRODUCT_VERSION);
831 kumpf 1.63     #else
832 kumpf 1.54             Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
833 kumpf 1.81.4.1                     "Started $0 version $1.",
834                                    PEGASUS_NAME, PEGASUS_VERSION);
835 kumpf 1.63     #endif
836 kumpf 1.45     
837 mday  1.62     	
838 mike  1.35             //
839                        // Loop to call CIMServer's runForever() method until CIMServer
840                        // has been shutdown
841                        //
842                	while( !server.terminated() )
843 mike  1.32     	{
844 kumpf 1.75     #if !defined(PEGASUS_OS_ZOS) && ! defined(PEGASUS_OS_HPUX) && ! defined(PEGASUS_NO_SLP)
845 mike  1.32     	  if(useSLP  ) 
846                	  {
847                	    if(  (time(NULL) - last ) > 60 ) 
848                	    {
849 kumpf 1.69     	      if( discovery != NULL && serviceURL.size() )
850                		discovery->srv_reg_all(serviceURL.getCString(),
851 mike  1.35     				       "(namespace=root/cimv2)",
852 mike  1.32     				       "service:cim.pegasus", 
853                				       "DEFAULT", 
854                				       70) ;
855                	      time(&last);
856                	    }
857                	  
858                	    discovery->service_listener();
859                	  }
860 mike  1.35     #endif
861 mike  1.32     	  server.runForever();
862                	}
863                
864 kumpf 1.45             //
865                        // normal termination
866 mike  1.34     	//
867 kumpf 1.54             // Put server shutdown message to the logger
868 kumpf 1.81.4.1 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_IA64_GNU)
869                        Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
870                            "$0 stopped.", PLATFORM_PRODUCT_NAME);
871                #else
872 kumpf 1.54             Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
873                            "$0 stopped.", PEGASUS_NAME);
874 kumpf 1.81.4.1 #endif
875 kumpf 1.45     
876                #if defined(PEGASUS_OS_HPUX)
877                        //
878 kumpf 1.56             // close the file created at startup time to indicate that the 
879                        // cimserver has terminated normally.
880 kumpf 1.45             //
881                        FileSystem::removeFile(CIMSERVERSTART_FILE);
882                #endif
883 mike  1.32         }
884                    catch(Exception& e)
885                    {
886                	PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
887 kumpf 1.81.4.1         Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::WARNING,
888                            "Error: $0", e.getMessage());
889 kumpf 1.77     
890                	//
891                        // notify parent process (if there is a parent process) to terminate
892                        //
893                        if (daemonOption)
894                                notify_parent();
895                
896 kumpf 1.54             return 1;
897 mike  1.32         }
898                
899                    return 0;
900                }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2