version 1.34.2.9, 2001/09/13 18:01:40
|
version 1.34.2.10, 2001/12/05 23:21:02
|
|
|
// | // |
// Modified By: Nag Boranna (nagaraja_boranna@hp.com) | // Modified By: Nag Boranna (nagaraja_boranna@hp.com) |
// | // |
|
// Modified By: Jenny Yu (jenny_yu@hp.com) |
|
// |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
| |
|
|
// | // |
// The -d option has no effect on windows operation. | // The -d option has no effect on windows operation. |
// | // |
|
// To shutdown pegasus, use the -s option: |
|
// |
|
// cimserver -s [-f] [-T timeout_value] |
|
// |
// To run pegasus as an NT service, there are FOUR different possibilities: | // To run pegasus as an NT service, there are FOUR different possibilities: |
// | // |
// To INSTALL the Pegasus service, | // To INSTALL the Pegasus service, |
|
|
#include <Pegasus/Common/System.h> | #include <Pegasus/Common/System.h> |
#include <Pegasus/Common/Tracer.h> | #include <Pegasus/Common/Tracer.h> |
#include <Pegasus/Config/ConfigManager.h> | #include <Pegasus/Config/ConfigManager.h> |
|
#include <Pegasus/Client/CIMClient.h> |
|
#include <Pegasus/Common/HTTPConnector.h> |
|
#include <Pegasus/Server/ShutdownService.h> |
#ifndef PEGASUS_OS_ZOS | #ifndef PEGASUS_OS_ZOS |
#include <slp/slp.h> | #include <slp/slp.h> |
#endif | #endif |
|
|
| |
static const char OPTION_HOME = 'D'; | static const char OPTION_HOME = 'D'; |
| |
|
static const char OPTION_SHUTDOWN = 's'; |
|
|
|
static const char OPTION_FORCE = 'f'; |
| |
|
static const char OPTION_TIMEOUT = 'T'; |
|
|
|
static const String NAMESPACE = "root/cimv2"; |
|
static const String CLASSNAME_SHUTDOWNSERVICE = "PG_ShutdownService"; |
|
static const String PROPERTY_TIMEOUT = "timeout"; |
|
|
|
ConfigManager* configManager; |
| |
void GetEnvironmentVariables( | void GetEnvironmentVariables( |
const char* arg0, | const char* arg0, |
|
|
usage.append (" -t - turns on trace of client IO to console\n"); | usage.append (" -t - turns on trace of client IO to console\n"); |
usage.append (" -l - turns on trace of client IO to trace file\n"); | usage.append (" -l - turns on trace of client IO to trace file\n"); |
usage.append (" -d - runs pegasus as a daemon\n"); | usage.append (" -d - runs pegasus as a daemon\n"); |
|
usage.append (" -s [-f] [-T timeout] \n"); |
|
usage.append (" - shuts down pegasus\n"); |
usage.append (" -cleanlogs - clears the log files at startup\n"); | usage.append (" -cleanlogs - clears the log files at startup\n"); |
usage.append (" -install - installs pegasus as a Windows NT Service\n"); | usage.append (" -install - installs pegasus as a Windows NT Service\n"); |
usage.append (" -remove - removes pegasus as a Windows NT Service\n"); | usage.append (" -remove - removes pegasus as a Windows NT Service\n"); |
|
|
cout << usage << endl; | cout << usage << endl; |
} | } |
| |
|
void shutdownCIMOM(Boolean forceOption, String timeoutStr) |
|
{ |
|
// |
|
// Create CIMClient object |
|
// |
|
Monitor* monitor = new Monitor; |
|
HTTPConnector* httpConnector = new HTTPConnector(monitor); |
|
CIMClient client(monitor, httpConnector); |
|
|
|
// |
|
// Get the port number |
|
// |
|
String portNumberStr = configManager->getCurrentValue("port"); |
|
|
|
String hostStr = System::getHostName(); |
|
hostStr.append(":"); |
|
hostStr.append(portNumberStr); |
|
|
|
// |
|
// open connection to CIMOM |
|
// |
|
try |
|
{ |
|
client.connect(hostStr.allocateCString()); |
|
} |
|
catch(Exception& e) |
|
{ |
|
PEGASUS_STD(cerr) << "Failed to connect to server: " << e.getMessage() << PEGASUS_STD(endl); |
|
exit(1); |
|
} |
|
|
|
try |
|
{ |
|
// |
|
// construct CIMReference |
|
// |
|
String referenceStr = "//"; |
|
referenceStr.append(hostStr); |
|
referenceStr.append("/root/cimv2:PG_ShutdownService"); |
|
CIMReference reference(referenceStr); |
|
|
|
// |
|
// issue the invokeMethod request on the shutdown method |
|
// |
|
Array<CIMParamValue> inParams; |
|
Array<CIMParamValue> outParams; |
|
|
|
if (forceOption) |
|
{ |
|
inParams.append(CIMParamValue( |
|
CIMParameter("force", CIMType::STRING), |
|
CIMValue("TRUE"))); |
|
} |
|
else |
|
{ |
|
inParams.append(CIMParamValue( |
|
CIMParameter("force", CIMType::STRING), |
|
CIMValue("FALSE"))); |
|
} |
|
|
|
inParams.append(CIMParamValue( |
|
CIMParameter("timeout", CIMType::STRING), |
|
CIMValue(timeoutStr))); |
|
|
|
CIMValue retValue = client.invokeMethod( |
|
NAMESPACE, |
|
reference, |
|
"shutdown", |
|
inParams, |
|
outParams); |
|
} |
|
catch(Exception& e) |
|
{ |
|
PEGASUS_STD(cerr) << "Failed to shutdown server: " << e.getMessage() << PEGASUS_STD(endl); |
|
exit(1); |
|
} |
|
|
|
return; |
|
} |
|
|
|
|
///////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////// |
// MAIN | // MAIN |
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// |
|
|
String logsDirectory = String::EMPTY; | String logsDirectory = String::EMPTY; |
Boolean useSLP = false; | Boolean useSLP = false; |
Boolean daemonOption = false; | Boolean daemonOption = false; |
|
Boolean shutdownOption = false; |
|
Boolean forceOption = false; |
|
Boolean timeoutOption = false; |
|
String timeoutStr = String::EMPTY; |
|
long timeoutValue = 0; |
| |
// on Windows NT if there are no command-line options, run as a service | // on Windows NT if there are no command-line options, run as a service |
| |
if (argc == 1 ) | if (argc == 1 ) |
|
{ |
cim_server_service(argc, argv) ; | cim_server_service(argc, argv) ; |
|
} |
|
else |
|
{ |
// Get help, version and home options | // Get help, version and home options |
| |
for (int i = 0; i < argc; ) |
for (int i = 1; i < argc; ) |
{ | { |
const char* arg = argv[i]; | const char* arg = argv[i]; |
| |
|
|
memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*)); | memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*)); |
argc -= 2; | argc -= 2; |
} | } |
|
// |
|
// Check to see if user asked for shutdown (-s option): |
|
// |
|
else if (*option == OPTION_SHUTDOWN) |
|
{ |
|
// |
|
// Check to see if shutdown has already been specified: |
|
// |
|
if (shutdownOption) |
|
{ |
|
cout << "Duplicate shutdown option specified." << endl; |
|
exit(0); |
|
} |
|
shutdownOption = true; |
|
|
|
// remove the option from the command line |
|
memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*)); |
|
argc--; |
|
} |
|
else if (*option == OPTION_FORCE) |
|
{ |
|
// |
|
// Check to see if shutdown has been specified: |
|
// |
|
if (!shutdownOption) |
|
{ |
|
cout << "Invalid option -" << option << endl; |
|
exit(0); |
|
} |
|
|
|
// |
|
// Check to see if force has already been specified: |
|
// |
|
if (forceOption) |
|
{ |
|
cout << "Duplicate force option specified." << endl; |
|
exit(0); |
|
} |
|
|
|
forceOption = true; |
|
|
|
// remove the option from the command line |
|
memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*)); |
|
argc--; |
|
} |
|
else if (*option == OPTION_TIMEOUT) |
|
{ |
|
// |
|
// Check to see if shutdown has been specified: |
|
// |
|
if (!shutdownOption) |
|
{ |
|
cout << "Invalid option -" << option << endl; |
|
exit(0); |
|
} |
|
|
|
if (timeoutOption) |
|
{ |
|
cout << "Duplicate timeout option specified." << endl; |
|
exit(0); |
|
} |
|
|
|
timeoutOption = true; |
|
|
|
if (i + 1 < argc) |
|
{ |
|
// get timeout value |
|
timeoutStr.assign(argv[i + 1]); |
|
|
|
// validate timeout value string |
|
char* tmp = timeoutStr.allocateCString(); |
|
char* end = 0; |
|
timeoutValue = strtol(tmp, &end, 10); |
|
|
|
if (!end || *end != '\0') |
|
{ |
|
cout << "invalid timeout value specified: "; |
|
cout << timeoutStr << endl; |
|
delete [] tmp; |
|
exit(0); |
|
} |
|
} |
|
else |
|
{ |
|
cout << "Missing argument for option -"; |
|
cout << option << endl; |
|
exit(0); |
|
} |
|
|
|
// remove the option from the command line |
|
memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*)); |
|
argc -= 2; |
|
} |
|
else |
|
i++; |
} | } |
|
else |
i++; | i++; |
} | } |
|
} |
| |
if (pegasusHome.size() == 0) | if (pegasusHome.size() == 0) |
GetEnvironmentVariables(argv[0], pegasusHome); | GetEnvironmentVariables(argv[0], pegasusHome); |
|
|
// | // |
// Get an instance of the Config Manager. | // Get an instance of the Config Manager. |
// | // |
ConfigManager* configManager = ConfigManager::getInstance(); |
configManager = ConfigManager::getInstance(); |
| |
// | // |
// Get options (from command line and from configuration file); this | // Get options (from command line and from configuration file); this |
|
|
} | } |
| |
// | // |
|
// Check to see if we need to shutdown CIMOM |
|
// |
|
if (shutdownOption) |
|
{ |
|
// |
|
// if timeout was specified, validate the timeout value |
|
// |
|
if (timeoutOption) |
|
{ |
|
Boolean valid = configManager->validatePropertyValue( |
|
PROPERTY_TIMEOUT, |
|
timeoutStr); |
|
if (!valid) |
|
{ |
|
cout << "Invalid timeout value specified: " << timeoutValue; |
|
cout << endl; |
|
exit(1); |
|
} |
|
} |
|
|
|
shutdownCIMOM(forceOption, timeoutStr); |
|
cout << "Pegasus CIM Server terminated." << endl; |
|
exit(0); |
|
} |
|
|
|
// |
// Grab the port option: | // Grab the port option: |
// | // |
| |
|
|
delete [] address; | delete [] address; |
| |
time_t last = 0; | time_t last = 0; |
while( 1 ) |
|
|
// |
|
// Loop to call CIMServer's runForever() method until CIMServer |
|
// has been shutdown |
|
// |
|
while( !server.terminated() ) |
{ | { |
#ifndef PEGASUS_OS_ZOS | #ifndef PEGASUS_OS_ZOS |
if(useSLP ) | if(useSLP ) |