version 1.44, 2002/05/03 18:15:13
|
version 1.53, 2002/05/21 19:08:44
|
|
|
// | // |
// To shutdown pegasus, use the -s option: | // To shutdown pegasus, use the -s option: |
// | // |
// cimserver -s [-f] [-T timeout_value] |
// cimserver -s [-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: |
// | // |
|
|
| |
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
|
#include <Pegasus/suballoc/suballoc.h> |
#include <iostream> | #include <iostream> |
#include <cassert> | #include <cassert> |
#include <cstdlib> | #include <cstdlib> |
|
#include <fstream> |
#include <Pegasus/Common/FileSystem.h> | #include <Pegasus/Common/FileSystem.h> |
#include <Pegasus/Common/Monitor.h> | #include <Pegasus/Common/Monitor.h> |
#include <Pegasus/Server/CIMServer.h> | #include <Pegasus/Server/CIMServer.h> |
|
|
| |
static const char OPTION_TIMEOUT = 'T'; | static const char OPTION_TIMEOUT = 'T'; |
| |
|
#if defined(PEGASUS_OS_HPUX) |
|
static const char OPTION_BINDVERBOSE = 'X'; |
|
#endif |
|
|
static const String NAMESPACE = "root/PG_Internal"; | static const String NAMESPACE = "root/PG_Internal"; |
static const String CLASSNAME_SHUTDOWNSERVICE = "PG_ShutdownService"; | static const String CLASSNAME_SHUTDOWNSERVICE = "PG_ShutdownService"; |
static const String PROPERTY_TIMEOUT = "operationTimeout"; | static const String PROPERTY_TIMEOUT = "operationTimeout"; |
|
static const String CIMSERVERSTART_FILE = "/etc/wbem/cimserver_start.conf"; |
| |
ConfigManager* configManager; | ConfigManager* configManager; |
| |
|
|
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 (" -s [-T timeout] \n"); |
usage.append (" - shuts down pegasus\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"); |
|
|
cout << usage << endl; | cout << usage << endl; |
} | } |
| |
void shutdownCIMOM(Boolean forceOption, Uint32 timeoutValue) |
void shutdownCIMOM(Uint32 timeoutValue) |
{ | { |
// | // |
// Create CIMClient object | // Create CIMClient object |
|
|
CIMClient client; | CIMClient client; |
| |
// | // |
// Get the port number |
// Get local host name |
// | // |
String portNumberStr = configManager->getCurrentValue("port"); |
|
|
|
String hostStr = System::getHostName(); | String hostStr = System::getHostName(); |
hostStr.append(":"); |
|
hostStr.append(portNumberStr); |
|
| |
// Put server shutdown message to the logger | // Put server shutdown message to the logger |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, | Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
"Shutdown $0 on port $1.", PEGASUS_NAME, portNumberStr); |
"Shutdown $0.", PEGASUS_NAME); |
| |
// | // |
// open connection to CIMOM | // open connection to CIMOM |
|
|
try | try |
{ | { |
client.connectLocal(); | client.connectLocal(); |
|
|
|
// |
|
// set client timeout to 10 seconds more than the shutdown timeout |
|
// so that the command client does not timeout before the cimserver |
|
// terminates |
|
// |
|
client.setTimeOut( (timeoutValue + 10)*1000 ); |
} | } |
catch(CIMClientException& e) | catch(CIMClientException& e) |
{ | { |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, | Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
"Failed to connect to $0 $1.", PEGASUS_NAME, e.getMessage()); | "Failed to connect to $0 $1.", PEGASUS_NAME, e.getMessage()); |
| |
PEGASUS_STD(cerr) << "Failed to connect to server: " << e.getMessage() << PEGASUS_STD(endl); |
PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl); |
exit(1); |
PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl); |
|
//PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); |
|
exit(0); |
} | } |
| |
try | try |
{ | { |
// | // |
// construct CIMReference |
// construct CIMObjectPath |
// | // |
String referenceStr = "//"; | String referenceStr = "//"; |
referenceStr.append(hostStr); | referenceStr.append(hostStr); |
referenceStr.append("/root/cimv2:PG_ShutdownService"); |
referenceStr.append(PEGASUS_NAMESPACENAME_CIMV2); |
CIMReference reference(referenceStr); |
referenceStr.append(":"); |
|
referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN); |
|
CIMObjectPath reference(referenceStr); |
| |
// | // |
// issue the invokeMethod request on the shutdown method | // issue the invokeMethod request on the shutdown method |
|
|
Array<CIMParamValue> inParams; | Array<CIMParamValue> inParams; |
Array<CIMParamValue> outParams; | Array<CIMParamValue> outParams; |
| |
|
// set force option to true for now |
inParams.append(CIMParamValue("force", | inParams.append(CIMParamValue("force", |
CIMValue(Boolean(forceOption)))); |
CIMValue(Boolean(true)))); |
| |
inParams.append(CIMParamValue("timeout", | inParams.append(CIMParamValue("timeout", |
CIMValue(Uint32(timeoutValue)))); | CIMValue(Uint32(timeoutValue)))); |
|
|
| |
// Put server shutdown message to the logger | // Put server shutdown message to the logger |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, | Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
"$0 terminated on port $1.", PEGASUS_NAME, portNumberStr); |
"$0 terminated.", PEGASUS_NAME); |
| |
} | } |
catch(CIMClientCIMException& e) | catch(CIMClientCIMException& e) |
{ | { |
PEGASUS_STD(cerr) << "Failed to shutdown server: " << e.getMessage() << PEGASUS_STD(endl); |
PEGASUS_STD(cerr) << "Failed to shutdown server: "; |
|
PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); |
exit(1); | exit(1); |
} | } |
catch(CIMClientException& e) | catch(CIMClientException& e) |
{ | { |
// this may mean the cimserver has been terminated |
// |
|
// This may mean the cimserver has been terminated and returns the |
|
// "Empty HTTP response message" HTTP error response. To be sure, |
|
// we need to check if cimserver is indeed terminated. |
|
// |
|
#ifdef PEGASUS_OS_TYPE_UNIX |
|
System::sleep(1); |
|
int ret = system("ps -ef | grep cimserver | grep -v grep | grep -v cimserverd >/dev/null"); |
|
if (ret == 0) |
|
{ |
|
// cimserver has been terminated |
|
// Put server shutdown message to the logger |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"$0 terminated.", PEGASUS_NAME); |
|
} |
|
else |
|
{ |
|
// cimserver is still running |
|
PEGASUS_STD(cerr) << "Failed to shutdown server: "; |
|
PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); |
|
exit(1); |
|
} |
|
#endif |
} | } |
catch(Exception& e) | catch(Exception& e) |
{ | { |
PEGASUS_STD(cerr) << "Failed to shutdown server: " << e.getMessage() << PEGASUS_STD(endl); |
PEGASUS_STD(cerr) << "Failed to shutdown server: "; |
|
PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); |
exit(1); | exit(1); |
} | } |
| |
|
|
String pegasusHome = String::EMPTY; | String pegasusHome = String::EMPTY; |
Boolean pegasusIOTrace = false; | Boolean pegasusIOTrace = false; |
Boolean pegasusIOLog = false; | Boolean pegasusIOLog = false; |
String portOption = String::EMPTY; |
String httpPort = String::EMPTY; |
|
String httpsPort = String::EMPTY; |
String logsDirectory = String::EMPTY; | String logsDirectory = String::EMPTY; |
Boolean useSLP = false; | Boolean useSLP = false; |
Boolean useSSL = false; | Boolean useSSL = false; |
Boolean daemonOption = false; | Boolean daemonOption = false; |
Boolean shutdownOption = false; | Boolean shutdownOption = false; |
Boolean forceOption = false; |
|
Boolean timeoutOption = false; | Boolean timeoutOption = false; |
String timeoutStr = String::EMPTY; | String timeoutStr = String::EMPTY; |
long timeoutValue = 0; | long timeoutValue = 0; |
|
|
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; |
} | } |
|
#if defined(PEGASUS_OS_HPUX) |
// | // |
// Check to see if user asked for shutdown (-s option): |
// Check to see if user asked for the version (-X option): |
// |
|
else if (*option == OPTION_SHUTDOWN) |
|
{ |
|
// |
|
// Check to see if shutdown has already been specified: |
|
// | // |
if (shutdownOption) |
if (*option == OPTION_BINDVERBOSE) |
{ | { |
cout << "Duplicate shutdown option specified." << endl; |
System::bindVerbose = true; |
exit(0); |
cout << "Unsupported debug option, BIND_VERBOSE, enabled." |
} |
<< endl; |
shutdownOption = true; |
|
|
|
// remove the option from the command line | // remove the option from the command line |
memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*)); | memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*)); |
argc--; | argc--; |
} | } |
else if (*option == OPTION_FORCE) |
#endif |
|
// |
|
// Check to see if user asked for shutdown (-s option): |
|
// |
|
else if (*option == OPTION_SHUTDOWN) |
{ | { |
|
|
// | // |
// Check to see if shutdown has been specified: |
// check to see if user is root |
// | // |
if (!shutdownOption) |
if (!System::isPrivilegedUser()) |
{ | { |
cout << "Invalid option -" << option << endl; |
cout << "You must have superuser privilege to run "; |
|
cout << "cimserver." << endl; |
exit(0); | exit(0); |
} | } |
| |
// | // |
// Check to see if force has already been specified: |
// Check to see if shutdown has already been specified: |
// | // |
if (forceOption) |
if (shutdownOption) |
{ | { |
cout << "Duplicate force option specified." << endl; |
cout << "Duplicate shutdown option specified." << endl; |
exit(0); | exit(0); |
} | } |
| |
forceOption = true; |
shutdownOption = true; |
| |
// remove the option from the command line | // remove the option from the command line |
memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*)); | memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*)); |
|
|
} | } |
} | } |
| |
shutdownCIMOM(forceOption, timeoutValue); |
shutdownCIMOM(timeoutValue); |
|
|
cout << "Pegasus CIM Server terminated." << endl; | cout << "Pegasus CIM Server terminated." << endl; |
exit(0); | exit(0); |
} | } |
| |
// | // |
// Grab the port option: |
// Get the port numbers |
// | // |
| |
portOption = configManager->getCurrentValue("port"); |
httpPort = configManager->getCurrentValue("httpPort"); |
|
|
|
httpsPort = configManager->getCurrentValue("httpsPort"); |
| |
// | // |
// Check the trace options and set global variable | // Check the trace options and set global variable |
|
|
cout << "Error: " << e.getMessage() << endl; | cout << "Error: " << e.getMessage() << endl; |
} | } |
| |
char* address = portOption.allocateCString(); |
Uint32 portNumber; |
|
|
|
char address[32]; |
|
|
|
if (useSSL) |
|
{ |
|
char* p = httpsPort.allocateCString(); |
|
char* end = 0; |
|
Uint32 port = strtol(p, &end, 10); |
|
assert(end != 0 && *end == '\0'); |
|
delete [] p; |
|
|
|
// |
|
// Look up the WBEM-HTTPS port number |
|
// |
|
portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, port); |
|
sprintf(address, "%u", portNumber); |
|
} |
|
else |
|
{ |
|
char* p = httpPort.allocateCString(); |
|
char* end = 0; |
|
Uint32 port = strtol(p, &end, 10); |
|
assert(end != 0 && *end == '\0'); |
|
delete [] p; |
|
|
|
// |
|
// Look up the WBEM-HTTP port number |
|
// |
|
portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME, port); |
|
sprintf(address, "%u", portNumber); |
|
} |
| |
// Put out startup up message. | // Put out startup up message. |
cout << PEGASUS_NAME << PEGASUS_VERSION << | cout << PEGASUS_NAME << PEGASUS_VERSION << |
|
|
<< (useSSL ? " Use SSL " : " No SSL ") | << (useSSL ? " Use SSL " : " No SSL ") |
<< endl; | << endl; |
| |
|
// do we need to run as a daemon ? |
|
if (daemonOption) |
|
{ |
|
if(-1 == cimserver_fork()) |
|
exit(-1); |
|
} |
|
|
// 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 $4 $5", | "Start $0 $1 port $2 $3 $4 $5", |
|
|
(useSLP ? " SLP on " : " SLP off "), | (useSLP ? " SLP on " : " SLP off "), |
(useSSL ? " Use SSL " : " No SSL ")); | (useSSL ? " Use SSL " : " No SSL ")); |
| |
// do we need to run as a daemon ? |
|
if (daemonOption) |
|
{ |
|
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 |
{ | { |
|
|
cout << "Binding to " << address << endl; | cout << "Binding to " << address << endl; |
#endif | #endif |
| |
char* end = 0; |
|
long portNumber = strtol(address, &end, 10); |
|
assert(end != 0 && *end == '\0'); |
|
server.bind(portNumber); | server.bind(portNumber); |
| |
delete [] address; |
|
|
|
time_t last = 0; | time_t last = 0; |
| |
|
#if defined(PEGASUS_OS_HPUX) |
|
// |
|
// create a file to indicate that the cimserver has started |
|
// |
|
fstream fs; |
|
ArrayDestroyer<char> p(CIMSERVERSTART_FILE.allocateCString()); |
|
fs.open(p.getPointer(), ios::in | ios::out); |
|
if (!fs) |
|
{ |
|
// |
|
// failed to create the file, write an entry to the log file |
|
// and proceed |
|
// |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Failed to open the $0 file needed by cimserverd.", |
|
CIMSERVERSTART_FILE); |
|
} |
|
else |
|
{ |
|
fs.close(); |
|
} |
|
#endif |
|
|
// | // |
// Loop to call CIMServer's runForever() method until CIMServer | // Loop to call CIMServer's runForever() method until CIMServer |
// has been shutdown | // has been shutdown |
|
|
server.runForever(); | server.runForever(); |
} | } |
| |
// This statement is unrechable! |
|
// | // |
// Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
// normal termination |
// "Normal Termination"); |
// |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Normal Termination"); |
|
|
|
#if defined(PEGASUS_OS_HPUX) |
|
// |
|
// close the file at startup time to indicate that the cimserver |
|
// has terminated normally. |
|
// |
|
FileSystem::removeFile(CIMSERVERSTART_FILE); |
|
#endif |
} | } |
catch(Exception& e) | catch(Exception& e) |
{ | { |