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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2