(file) Return to cimserver.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Server

Diff for /pegasus/src/Server/cimserver.cpp between version 1.6 and 1.34

version 1.6, 2001/05/03 20:18:23 version 1.34, 2001/07/17 00:49:05
Line 1 
Line 1 
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a  // Permission is hereby granted, free of charge, to any person obtaining a copy
 // copy of this software and associated documentation files (the "Software"),  // of this software and associated documentation files (the "Software"), to
 // to deal in the Software without restriction, including without limitation  // deal in the Software without restriction, including without limitation the
 // the rights to use, copy, modify, merge, publish, distribute, sublicense,  // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 // and/or sell copies of the Software, and to permit persons to whom the  // sell copies of the Software, and to permit persons to whom the Software is
 // Software is furnished to do so, subject to the following conditions:  // furnished to do so, subject to the following conditions:
 //  //
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 // DEALINGS IN THE SOFTWARE.  // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com) // Author: Mike Brasher (mbrasher@bmc.com)
 // //
 // Modified By:  // Modified By: Mike Day (mdday@us.ibm.com)
   //
   // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
   
   //////////////////////////////////////////////////////////////////////
   //
   // Notes on deamon operation (Unix) and service operation (Win 32):
   //
   // To run pegasus as a daemon on Unix platforms, use the -d option:
   //
   // cimserver -d
   //
   // The -d option has no effect on windows operation.
   //
   // To run pegasus as an NT service, there are FOUR  different possibilities:
   //
   // To INSTALL the Pegasus service,
   //
   // cimserver -install
   //
   // To REMOVE the Pegasus service,
   //
   // cimserver -remove
   //
   // To START the Pegasus service,
   //
   // net start cimserver
   //
   // To STOP the Pegasus service,
   //
   // net stop cimserver
   //
   // Alternatively, you can use the windows service manager. Pegasus shows up
   // in the service database as "Pegasus CIM Object Manager"
   //
   // Mike Day, mdday@us.ibm.com
   //
   //////////////////////////////////////////////////////////////////////
   
   
 #include <iostream> #include <iostream>
 #include <cstdlib> #include <cstdlib>
 #include <Pegasus/Common/FileSystem.h> #include <Pegasus/Common/FileSystem.h>
Line 32 
Line 72 
 #include <Pegasus/Common/OptionManager.h> #include <Pegasus/Common/OptionManager.h>
 #include <Pegasus/Server/CIMServer.h> #include <Pegasus/Server/CIMServer.h>
 #include <Pegasus/Common/PegasusVersion.h> #include <Pegasus/Common/PegasusVersion.h>
   #include <Pegasus/Protocol/Handler.h>
   #include <Pegasus/Common/Logger.h>
   #include <Pegasus/Common/System.h>
   #include <slp/slp.h>
   
   
  
 using namespace Pegasus;  #if defined(PEGASUS_OS_TYPE_WINDOWS)
 using namespace std;  # include "cimserver_windows.cpp"
   #elif defined(PEGASUS_OS_TYPE_UNIX)
   # include "cimserver_unix.cpp"
   #else
   # error "Unsupported platform"
   #endif
  
 // const char PEGASUS_VERSION[]  = "Pegasus CIM Server - Version 0.7";  PEGASUS_USING_PEGASUS;
   PEGASUS_USING_STD;
  
 void GetEnvironmentVariables( void GetEnvironmentVariables(
     const char* arg0,     const char* arg0,
Line 56 
Line 108 
     FileSystem::translateSlashes(pegasusHome);     FileSystem::translateSlashes(pegasusHome);
 } }
  
   /** GetOptions function - This function defines the Options Table
       and sets up the options from that table using the option manager.
   */
 void GetOptions( void GetOptions(
     OptionManager& om,     OptionManager& om,
     int& argc,     int& argc,
     char** argv,     char** argv,
     const String& pegasusHome)     const String& pegasusHome)
 { {
     static struct OptionRow options[] =      static struct OptionRow optionsTable[] =
     {     {
         {"port", "8888", false, Option::WHOLE_NUMBER, 0, 0, "port"},          {"home", "/etc/pegasus", false, Option::STRING, 0, 0, "D",
         {"trace", "false", false, Option::BOOLEAN, 0, 0, "trace"},                      "Sets the pegasus home directory"},
         {"version", "false", false, Option::BOOLEAN, 0, 0, "v"},          {"port", "5988", false, Option::WHOLE_NUMBER, 0, 0, "port",
         {"help", "false", false, Option::BOOLEAN, 0, 0, "h"}                          "specifies port number to listen on" },
           {"trace", "false", false, Option::BOOLEAN, 0, 0, "t",
                           "turns on trace of Client IO to console "},
           {"logtrace", "false", false, Option::BOOLEAN, 0, 0, "l",
                           "Turns on trace of Client IO to trace log "},
           {"options", "false", false, Option::BOOLEAN, 0, 0, "options",
                           " Displays the settings of the Options "},
           {"severity", "ALL", false, Option::STRING, 0, 0, "s",
   
                       "Sets the severity level that will be logged "},
           {"logs", "ALL", false, Option::STRING, 0, 0, "X",
                           "Not Used "},
           {"daemon", "false", false, Option::BOOLEAN, 0, 0, "d",
               "Detach Pegasus from the console and run it in the background "},
           {"logdir", "./logs", false, Option::STRING, 0, 0, "logdir",
                           "Directory for log files"},
           {"cleanlogs", "false", false, Option::BOOLEAN, 0, 0, "clean",
                           "Clears the log files at startup"},
           {"version", "false", false, Option::BOOLEAN, 0, 0, "v",
                           "Displays Pegasus Version "},
           {"help", "false", false, Option::BOOLEAN, 0, 0, "h",
                       "Prints help message with command line options "},
           {"install", "false", false, Option::BOOLEAN, 0, 0, "install",
                       "Installs Pegasus as a Windows NT Service "},
           {"remove", "false", false, Option::BOOLEAN, 0, 0, "remove",
                       "Removes Pegasus as a Windows NT Service "},
           {"debug", "false", false, Option::BOOLEAN, 0, 0, "d",
                           "Not Used "},
           {"slp", "false", false, Option::BOOLEAN, 0, 0, "slp",
                           "Register Pegasus as a Service with SLP"}
     };     };
     const Uint32 NUM_OPTIONS = sizeof(options) / sizeof(options[0]);      const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]);
  
     om.registerOptions(options, NUM_OPTIONS);      om.registerOptions(optionsTable, NUM_OPTIONS);
  
     String configFile = pegasusHome + "/cimserver.conf";      String configFile = pegasusHome + "/testclient.conf";
   
       cout << "Config file from " << configFile << endl;
  
     if (FileSystem::exists(configFile))     if (FileSystem::exists(configFile))
         om.mergeFile(configFile);         om.mergeFile(configFile);
       if(argc && argv != NULL)
     om.mergeCommandLine(argc, argv);     om.mergeCommandLine(argc, argv);
  
     om.checkRequiredOptions();     om.checkRequiredOptions();
   
 } }
  
   /* PrintHelp - This is temporary until we expand the options manager to allow
      options help to be defined with the OptionRow entries and presented from
      those entries.
   */
 void PrintHelp(const char* arg0) void PrintHelp(const char* arg0)
 { {
     cout << '\n';     cout << '\n';
     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;     cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
     cout << '\n';     cout << '\n';
     cout << "Usage: " << arg0 << " [-port <port_num> -t -h -v]\n";      cout << "Usage: " << arg0 << endl;
     cout << '\n';  
     cout << "    -h - prints this help message\n";  
     cout << "    -port - specifies port number to listen on\n";  
     cout << "    -v - prints out the version number\n";  
     cout << "    -t - turns on trace mode\n";  
     cout << endl;     cout << endl;
 } }
  
   /////////////////////////////////////////////////////////////////////////
   //  MAIN
   //////////////////////////////////////////////////////////////////////////
 int main(int argc, char** argv) int main(int argc, char** argv)
 { {
     // Get environment variables:      // on Windows NT if there are no command-line options, run as a service
   
       if (argc == 1 )
         cim_server_service(argc, argv) ;
   
       // Get environment variables
  
     String pegasusHome;     String pegasusHome;
   
       for (int i=0; i < argc; i++) {
           if (!strcmp(argv[i],"-D")) {
               i++;
               if (i < argc) pegasusHome = argv[i];
               break;
           }
       }
       if (pegasusHome.size() == 0)
     GetEnvironmentVariables(argv[0], pegasusHome);     GetEnvironmentVariables(argv[0], pegasusHome);
  
     // Get options (from command line and from configuration file); this     // Get options (from command line and from configuration file); this
Line 134 
Line 237 
         exit(1);         exit(1);
     }     }
  
       // Check to see if we should (can) install as a NT service
   
       String installOption;
       if(om.lookupValue("install", installOption) && installOption == "true")
         {
           if( 0 != cimserver_install_nt_service( pegasusHome ))
             cout << "\nPegasus installed as NT Service";
           exit(0);
         }
   
       // Check to see if we should (can) remove Pegasus as an NT service
   
       String removeOption;
       if(om.lookupValue("remove", removeOption) && removeOption == "true")
         {
           if( 0 != cimserver_remove_nt_service() )
             cout << "\nPegasus removed as NT Service";
           exit(0);
   
         }
   
     // Check to see if user asked for the version (-v otpion):     // Check to see if user asked for the version (-v otpion):
  
     String versionOption;     String versionOption;
Line 145 
Line 269 
     }     }
  
     // Check to see if user asked for help (-h otpion):     // Check to see if user asked for help (-h otpion):
   
     String helpOption;     String helpOption;
  
     if (om.lookupValue("help", helpOption) && helpOption == "true")     if (om.lookupValue("help", helpOption) && helpOption == "true")
     {     {
         PrintHelp(argv[0]);         PrintHelp(argv[0]);
           om.printHelp();
         exit(0);         exit(0);
     }     }
  
       // Check the trace options and set global variable
       Boolean pegasusIOTrace = false;
       if (om.valueEquals("trace", "true"))
       {
           Handler::setMessageTrace(true);
           pegasusIOTrace = true;
       }
   
       Boolean pegasusIOLog = false;
       if (om.valueEquals("logtrace", "true"))
       {
           Handler::setMessageLogTrace(true);
           pegasusIOLog = true;
       }
   
     // Grab the port otpion:     // Grab the port otpion:
  
     String portOption;     String portOption;
     om.lookupValue("port", portOption);     om.lookupValue("port", portOption);
  
     try      // Get the log file directory definition.
       // We put String into Cstring because
       // Directory functions only handle Cstring.
       // ATTN-KS: create String based directory functions.
       String logsDirectory;
       om.lookupValue("logdir", logsDirectory);
   
       // Set up the Logger. This does not open the logs
       // Might be more logical to clean before set.
       // ATTN: Need tool to completely disable logging.
       Logger::setHomeDirectory(logsDirectory);
   
       if (om.valueEquals("cleanlogs", "true"))
     {     {
         Selector selector;          Logger::clean(logsDirectory);;
         CIMServer server(&selector, pegasusHome);      }
   
       // Option to Display the options table.  Primarily
       // a diagnostic tool.
       if (om.valueEquals("options", "true"))
           om.print();
   
       // Leave this in until people get familiar with the logs.
       cout << "Logs Directory = " << logsDirectory << endl;
   
       Boolean useSLP = (om.valueEquals("slp", "true")) ? true: false;
  
         char* address = portOption.allocateCString();         char* address = portOption.allocateCString();
  
         // Put out startup up message.         // Put out startup up message.
         // Put to cout if not daemon  
         // ATTN: modify when we add daemon  
         cout << PEGASUS_NAME << PEGASUS_VERSION <<         cout << PEGASUS_NAME << PEGASUS_VERSION <<
              " on port " << address << endl;              " on port " << address << endl;
       cout << "Built " << __DATE__ << " " << __TIME__ << endl;
       cout <<"Started..."
            << (pegasusIOTrace ? " Tracing to Display ": " ")
            << (pegasusIOLog ? " Tracing to Log ": " ")
            << (useSLP ? " SLP reg. " : " No SLP ")
           << endl;
   
       // Put server start message to the logger
       Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
           "Start $0 $1 port $2 $3 $4",
                   PEGASUS_NAME,
                   PEGASUS_VERSION,
                   address,
                   (pegasusIOTrace ? " Tracing": " "),
                   (useSLP ? " SLP on " : " SLP off "));
   
   // do we need to run as a daemon ?
       String daemonOption;
       if(om.lookupValue("daemon", daemonOption) && daemonOption == "true")
         {
           if(-1 == cimserver_fork())
             exit(-1);
         }
   
   
       // try loop to bind the address, and run the server
       try
       {
           slp_client *discovery = new slp_client() ;;
           String serviceURL;
           serviceURL.assign("service:cim.pegasus://");
           String host_name = slp_get_host_name();
           serviceURL += host_name;
           serviceURL += ":";
           serviceURL += address;
           char *url = serviceURL.allocateCString();
           //      free(host_name);
  
           Selector selector;
           CIMServer server(&selector, pegasusHome);
   
           // bind throws an exception of the bind fails
           cout << "Binding to " << address << endl;
         server.bind(address);         server.bind(address);
         delete [] address;         delete [] address;
   
           time_t last = 0;
           while( 1 )
           {
             if(useSLP  )
             {
               if(  (time(NULL) - last ) > 60 )
               {
                 if( discovery != NULL && url != NULL )
                   discovery->srv_reg_all(url,
                                          "(namespace=root/cimv20)",
                                          "service:cim.pegasus",
                                          "DEFAULT",
                                          70) ;
                 time(&last);
               }
   
               discovery->service_listener();
             }
         server.runForever();         server.runForever();
     }     }
   
           // This statement is unrechable!
           //
           // Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
           //   "Normal Termination");
       }
     catch(Exception& e)     catch(Exception& e)
     {     {
         std::cerr << "Error: " << e.getMessage() << std::endl;          Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION,
               "Abnormal Termination $0", e.getMessage());
   
           PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
     }     }
  
     return 0;     return 0;


Legend:
Removed from v.1.6  
changed lines
  Added in v.1.34

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2