version 1.15, 2001/06/03 17:05:03
|
version 1.17, 2001/06/07 12:24:21
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the | // and/or sell copies of the Software, and to permit persons to whom the |
// Software is furnished to do so, subject to the following conditions: | // Software is furnished to do so, subject to the following conditions: |
// | // |
|
// The above copyright notice and this permission notice shall be included in |
|
// all copies or substantial portions of the Software. |
|
// |
|
// |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
|
// | // |
// 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> |
|
|
#include <Pegasus/Common/Logger.h> | #include <Pegasus/Common/Logger.h> |
#include <Pegasus/Common/System.h> | #include <Pegasus/Common/System.h> |
| |
PEGASUS_USING_PEGASUS; |
|
PEGASUS_USING_STD; |
|
| |
|
#if defined(PEGASUS_OS_TYPE_WINDOWS) |
|
# include "cimserver_windows.cpp" |
|
#elif defined(PEGASUS_OS_TYPE_UNIX) |
|
# include "cimserver_unix.cpp" |
|
#else |
|
# error "Unsupported platform" |
|
#endif |
| |
|
PEGASUS_USING_PEGASUS; |
|
PEGASUS_USING_STD; |
| |
void GetEnvironmentVariables( | void GetEnvironmentVariables( |
const char* arg0, | const char* arg0, |
|
|
{"options", "false", false, Option::BOOLEAN, 0, 0, "options", | {"options", "false", false, Option::BOOLEAN, 0, 0, "options", |
" Displays the settings of the Options "}, | " Displays the settings of the Options "}, |
{"severity", "ALL", false, Option::STRING, 0, 0, "s", | {"severity", "ALL", false, Option::STRING, 0, 0, "s", |
|
|
"Sets the severity level that will be logged "}, | "Sets the severity level that will be logged "}, |
{"logs", "ALL", false, Option::STRING, 0, 0, "X", | {"logs", "ALL", false, Option::STRING, 0, 0, "X", |
"Not Used "}, | "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", | {"logdir", "./logs", false, Option::STRING, 0, 0, "logdir", |
"Directory for log files"}, | "Directory for log files"}, |
{"clearlogs", "false", false, Option::BOOLEAN, 0, 0, "cl", |
{"cleanlogs", "false", false, Option::BOOLEAN, 0, 0, "clean", |
"Clears the log files at startup"}, | "Clears the log files at startup"}, |
{"daemon", "false", false, Option::BOOLEAN, 0, 0, "d", | {"daemon", "false", false, Option::BOOLEAN, 0, 0, "d", |
"Not Used "}, | "Not Used "}, |
|
|
"Displays Pegasus Version "}, | "Displays Pegasus Version "}, |
{"help", "false", false, Option::BOOLEAN, 0, 0, "h", | {"help", "false", false, Option::BOOLEAN, 0, 0, "h", |
"Prints help message with command line options "}, | "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", | {"debug", "false", false, Option::BOOLEAN, 0, 0, "d", |
"Not Used "} | "Not Used "} |
}; | }; |
|
|
| |
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(); |
|
|
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// |
int main(int argc, char** argv) | int main(int argc, char** argv) |
{ | { |
|
|
|
// 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: | // Get environment variables: |
| |
String pegasusHome; | String pegasusHome; |
|
|
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 |
|
|
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; |
|
|
} | } |
| |
// 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") |
|
|
String logsDirectory; | String logsDirectory; |
om.lookupValue("logdir", logsDirectory); | om.lookupValue("logdir", logsDirectory); |
| |
char* lgDir = logsDirectory.allocateCString(); |
// Set up the Logger. This does not open the logs |
|
// Might be more logical to clean before set. |
if (!System::isDirectory(lgDir)) |
// ATTN: Need tool to completely disable logging. |
System::makeDirectory(lgDir); |
Logger::setHomeDirectory(logsDirectory); |
| |
if (!System::isDirectory(lgDir)) |
if (om.valueEquals("cleanlogs", "true")) |
cout << "Logging Disabled"; |
{ |
delete [] lgDir; |
Logger::clean(logsDirectory);; |
|
} |
| |
|
// Leave this in until people get familiar with the logs. |
cout << "Logs Directory = " << logsDirectory << endl; | cout << "Logs Directory = " << logsDirectory << endl; |
| |
| |
|
|
if (om.valueEquals("options", "true")) | if (om.valueEquals("options", "true")) |
om.print(); | om.print(); |
| |
// Set up the Logger |
|
Logger::setHomeDirectory(logsDirectory); |
|
|
|
|
|
// Put server start message to the logger | // Put server start message to the logger |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, | Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
"Start $0 $1 port $2 $3 ", 88, PEGASUS_NAME, |
"Start $0 $1 port $2 $3 ", |
PEGASUS_VERSION, address, (pegasusIOTrace ? " Tracing": " ")); |
PEGASUS_NAME, |
|
PEGASUS_VERSION, |
|
address, |
|
(pegasusIOTrace ? " Tracing": " ")); |
|
|
|
// 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 loop to bind the address, and run the server |
try | try |
|
|
server.bind(address); | server.bind(address); |
delete [] address; | delete [] address; |
server.runForever(); | server.runForever(); |
|
|
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Normal Termination"); |
|
|
} | } |
catch(Exception& e) | catch(Exception& e) |
{ | { |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Abnormal Termination $0", e.getMessage()); |
|
|
PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); |
} | } |
| |
return 0; | return 0; |
} | } |
|
|