version 1.53, 2002/05/21 19:08:44
|
version 1.57, 2002/06/01 00:25:05
|
|
|
// | // |
// To shutdown pegasus, use the -s option: | // To shutdown pegasus, use the -s option: |
// | // |
// cimserver -s [-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: |
// | // |
|
|
| |
static const char OPTION_FORCE = 'f'; | static const char OPTION_FORCE = 'f'; |
| |
static const char OPTION_TIMEOUT = 'T'; |
static const char OPTION_TIMEOUT = 't'; |
| |
#if defined(PEGASUS_OS_HPUX) | #if defined(PEGASUS_OS_HPUX) |
static const char OPTION_BINDVERBOSE = 'X'; | static const char OPTION_BINDVERBOSE = 'X'; |
|
|
| |
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 = "shutdownTimeout"; |
static const String CIMSERVERSTART_FILE = "/etc/wbem/cimserver_start.conf"; | static const String CIMSERVERSTART_FILE = "/etc/wbem/cimserver_start.conf"; |
| |
ConfigManager* configManager; | ConfigManager* configManager; |
|
|
usage.append (" -v - displays pegasus version number\n"); | usage.append (" -v - displays pegasus version number\n"); |
usage.append (" -h - prints this help message\n"); | usage.append (" -h - prints this help message\n"); |
usage.append (" -D [home] - sets pegasus home directory\n"); | usage.append (" -D [home] - sets pegasus home directory\n"); |
usage.append (" -t - turns tracing on\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 (" -d - runs pegasus as a daemon\n"); | usage.append (" -d - runs pegasus as a daemon\n"); |
usage.append (" -s [-T timeout] \n"); |
usage.append (" -s [-t timeout] \n"); |
usage.append (" - shuts down pegasus\n"); | usage.append (" - shuts down pegasus\n"); |
|
#if !defined(PEGASUS_OS_HPUX) |
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"); |
usage.append (" -slp - registers pegasus as a service with SLP\n\n"); | usage.append (" -slp - registers pegasus as a service with SLP\n\n"); |
usage.append (" -SSL - uses SSL\n\n"); | usage.append (" -SSL - uses SSL\n\n"); |
|
#endif |
usage.append (" configProperty=value\n"); | usage.append (" configProperty=value\n"); |
usage.append (" port=nnnn - sets port number to listen on\n"); | usage.append (" port=nnnn - sets port number to listen on\n"); |
usage.append (" logdir=/pegasus/logs - directory for log files\n"); | usage.append (" logdir=/pegasus/logs - directory for log files\n"); |
|
|
// | // |
String hostStr = System::getHostName(); | String hostStr = System::getHostName(); |
| |
// Put server shutdown message to the logger |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Shutdown $0.", PEGASUS_NAME); |
|
|
|
// | // |
// open connection to CIMOM | // open connection to CIMOM |
// | // |
|
|
client.connectLocal(); | client.connectLocal(); |
| |
// | // |
// set client timeout to 10 seconds more than the shutdown timeout |
// set client timeout to 2 seconds more than the shutdown timeout |
// so that the command client does not timeout before the cimserver | // so that the command client does not timeout before the cimserver |
// terminates | // terminates |
// | // |
client.setTimeOut( (timeoutValue + 10)*1000 ); |
Uint32 clientTimeout; |
|
if (timeoutValue == 0) |
|
{ |
|
String configTimeout = |
|
configManager->getCurrentValue("shutdownTimeout"); |
|
ArrayDestroyer<char> timeoutCString(configTimeout.allocateCString()); |
|
clientTimeout = |
|
((strtol(timeoutCString.getPointer(), (char **)0,10))+2)*1000; |
} | } |
catch(CIMClientException& e) |
else |
{ | { |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
clientTimeout = (timeoutValue + 2)*1000; |
"Failed to connect to $0 $1.", PEGASUS_NAME, e.getMessage()); |
} |
| |
|
client.setTimeOut(clientTimeout); |
|
} |
|
catch(CIMClientException& e) |
|
{ |
PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl); |
PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl); |
//PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); |
|
exit(0); | exit(0); |
} | } |
| |
|
|
"shutdown", | "shutdown", |
inParams, | inParams, |
outParams); | outParams); |
|
|
// Put server shutdown message to the logger |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"$0 terminated.", PEGASUS_NAME); |
|
|
|
} | } |
catch(CIMClientCIMException& e) | catch(CIMClientCIMException& e) |
{ | { |
|
|
catch(CIMClientException& e) | catch(CIMClientException& e) |
{ | { |
// | // |
// This may mean the cimserver has been terminated and returns the |
// This may mean the CIM Server has been terminated and returns a |
// "Empty HTTP response message" HTTP error response. To be sure, |
// "Empty HTTP response message" HTTP error response. To be sure |
// we need to check if cimserver is indeed terminated. |
// CIM Server gets shutdown, if CIM Server is still running at |
|
// this time, we will kill the cimserver process. |
|
// |
|
// give CIM Server some time to finish up |
// | // |
#ifdef PEGASUS_OS_TYPE_UNIX |
|
System::sleep(1); | System::sleep(1); |
int ret = system("ps -ef | grep cimserver | grep -v grep | grep -v cimserverd >/dev/null"); |
cimserver_kill(); |
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: "; |
PEGASUS_STD(cerr) << "Error occurred while stopping the CIM Server: "; |
PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); |
exit(1); | exit(1); |
} | } |
|
|
int main(int argc, char** argv) | int main(int argc, char** argv) |
{ | { |
String pegasusHome = String::EMPTY; | String pegasusHome = String::EMPTY; |
Boolean pegasusIOTrace = false; |
|
Boolean pegasusIOLog = false; | Boolean pegasusIOLog = false; |
String httpPort = String::EMPTY; | String httpPort = String::EMPTY; |
String httpsPort = String::EMPTY; | String httpsPort = String::EMPTY; |
|
|
// | // |
// check to see if user is root | // check to see if user is root |
// | // |
if (!System::isPrivilegedUser()) |
if (!System::isPrivilegedUser(System::getEffectiveUserName())) |
{ | { |
cout << "You must have superuser privilege to run "; | cout << "You must have superuser privilege to run "; |
cout << "cimserver." << endl; | cout << "cimserver." << endl; |
|
|
// Might be more logical to clean before set. | // Might be more logical to clean before set. |
// ATTN: Need tool to completely disable logging. | // ATTN: Need tool to completely disable logging. |
| |
|
#ifndef PEGASUS_OS_HPUX |
Logger::setHomeDirectory(logsDirectory); | Logger::setHomeDirectory(logsDirectory); |
|
#endif |
| |
// | // |
// Check to see if we need to shutdown CIMOM | // Check to see if we need to shutdown CIMOM |
|
|
| |
shutdownCIMOM(timeoutValue); | shutdownCIMOM(timeoutValue); |
| |
cout << "Pegasus CIM Server terminated." << endl; |
cout << "Pegasus CIM Server stopped." << endl; |
exit(0); | exit(0); |
} | } |
| |
|
|
| |
httpsPort = configManager->getCurrentValue("httpsPort"); | httpsPort = configManager->getCurrentValue("httpsPort"); |
| |
// |
|
// Check the trace options and set global variable |
|
// |
|
|
|
if (String::equal(configManager->getCurrentValue("trace"), "true")) |
|
{ |
|
pegasusIOTrace = true; |
|
cout << "Trace Set" << endl; |
|
} |
|
|
|
// Leave this in until people get familiar with the logs. | // Leave this in until people get familiar with the logs. |
|
#ifndef PEGASUS_OS_HPUX |
cout << "Logs Directory = " << logsDirectory << endl; | cout << "Logs Directory = " << logsDirectory << endl; |
|
#endif |
| |
if (String::equal(configManager->getCurrentValue("cleanlogs"), "true")) | if (String::equal(configManager->getCurrentValue("cleanlogs"), "true")) |
{ | { |
|
|
cout << PEGASUS_NAME << PEGASUS_VERSION << | cout << PEGASUS_NAME << PEGASUS_VERSION << |
" on port " << address << endl; | " on port " << address << endl; |
cout << "Built " << __DATE__ << " " << __TIME__ << endl; | cout << "Built " << __DATE__ << " " << __TIME__ << endl; |
cout <<"Started..." |
cout <<"Starting..." |
<< (pegasusIOTrace ? " Tracing to Display ": " ") |
|
<< (pegasusIOLog ? " Tracing to Log ": " ") | << (pegasusIOLog ? " Tracing to Log ": " ") |
<< (useSLP ? " SLP reg. " : " No SLP ") | << (useSLP ? " SLP reg. " : " No SLP ") |
<< (useSSL ? " Use SSL " : " No SSL ") | << (useSSL ? " Use SSL " : " No SSL ") |
|
|
exit(-1); | exit(-1); |
} | } |
| |
// Put server start message to the logger |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Start $0 $1 port $2 $3 $4 $5", |
|
PEGASUS_NAME, |
|
PEGASUS_VERSION, |
|
address, |
|
(pegasusIOTrace ? " Tracing": " "), |
|
(useSLP ? " SLP on " : " SLP off "), |
|
(useSSL ? " Use SSL " : " No SSL ")); |
|
|
|
// try loop to bind the address, and run the server | // try loop to bind the address, and run the server |
try | try |
{ | { |
|
|
| |
#if defined(PEGASUS_OS_HPUX) | #if defined(PEGASUS_OS_HPUX) |
// | // |
// create a file to indicate that the cimserver has started |
// create a file to indicate that the cimserver has started and |
// |
// save the process id of the cimserver process in the file |
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.", |
// remove the old file if it exists |
CIMSERVERSTART_FILE); |
System::removeFile(fname); |
} |
|
else |
// open the file |
|
FILE *pid_file = fopen(fname, "w"); |
|
if (pid_file) |
{ | { |
fs.close(); |
// save the pid in the file |
|
fprintf(pid_file, "%ld\n", (long)server_pid); |
|
fclose(pid_file); |
} | } |
#endif | #endif |
|
cout << "Started. " << endl; |
|
|
|
// Put server started message to the logger |
|
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"Started $0 version $1 on port $2.", |
|
PEGASUS_NAME, PEGASUS_VERSION, address); |
|
|
| |
// | // |
// Loop to call CIMServer's runForever() method until CIMServer | // Loop to call CIMServer's runForever() method until CIMServer |
|
|
// | // |
// normal termination | // normal termination |
// | // |
|
// Put server shutdown message to the logger |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, | Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
"Normal Termination"); |
"$0 stopped.", PEGASUS_NAME); |
| |
#if defined(PEGASUS_OS_HPUX) | #if defined(PEGASUS_OS_HPUX) |
// | // |
// close the file at startup time to indicate that the cimserver |
// close the file created at startup time to indicate that the |
// has terminated normally. |
// cimserver has terminated normally. |
// | // |
FileSystem::removeFile(CIMSERVERSTART_FILE); | FileSystem::removeFile(CIMSERVERSTART_FILE); |
#endif | #endif |
|
|
catch(Exception& e) | catch(Exception& e) |
{ | { |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, | Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
"Abnormal Termination $0", e.getMessage()); |
"$0 .Abnormal Termination.", e.getMessage()); |
| |
PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); |
|
return 1; |
} | } |
| |
return 0; | return 0; |