version 1.197, 2007/04/12 16:51:53
|
version 1.200, 2007/06/05 10:22:40
|
|
|
// Alternatively, you can use the windows service manager. Pegasus shows up | // Alternatively, you can use the windows service manager. Pegasus shows up |
// in the service database as "Pegasus CIM Object Manager" | // in the service database as "Pegasus CIM Object Manager" |
// | // |
// Mike Day, mdday@us.ibm.com |
|
// |
|
////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////// |
| |
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/Constants.h> | #include <Pegasus/Common/Constants.h> |
#include <Pegasus/Common/PegasusAssert.h> | #include <Pegasus/Common/PegasusAssert.h> |
#include <cstdlib> |
|
#include <Pegasus/Common/FileSystem.h> | #include <Pegasus/Common/FileSystem.h> |
#include <Pegasus/Common/Monitor.h> | #include <Pegasus/Common/Monitor.h> |
#include <Pegasus/Common/PegasusVersion.h> | #include <Pegasus/Common/PegasusVersion.h> |
|
|
#include <Pegasus/Common/LanguageParser.h> | #include <Pegasus/Common/LanguageParser.h> |
#include <Pegasus/Config/ConfigManager.h> | #include <Pegasus/Config/ConfigManager.h> |
#include <Pegasus/Client/CIMClient.h> | #include <Pegasus/Client/CIMClient.h> |
#include <Pegasus/Server/ShutdownService.h> |
|
#include <Pegasus/Server/CIMServer.h> | #include <Pegasus/Server/CIMServer.h> |
#include <Service/ServerProcess.h> | #include <Service/ServerProcess.h> |
|
#include <Service/ServerShutdownClient.h> |
#if defined(PEGASUS_OS_OS400) |
#include <Service/ServerRunStatus.h> |
# include "vfyptrs.cinc" |
|
# include "OS400ConvertChar.h" |
|
#endif |
|
| |
#if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) | #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) |
#include <Service/ARM_zOS.h> | #include <Service/ARM_zOS.h> |
|
|
#endif | #endif |
| |
#if defined(PEGASUS_OS_TYPE_UNIX) | #if defined(PEGASUS_OS_TYPE_UNIX) |
# if defined(PEGASUS_OS_OS400) |
|
# include <unistd.cleinc> |
|
# else |
|
# include <unistd.h> | # include <unistd.h> |
# endif |
|
# include <sys/types.h> | # include <sys/types.h> |
# include <sys/stat.h> | # include <sys/stat.h> |
# include <fcntl.h> | # include <fcntl.h> |
#endif | #endif |
| |
|
#ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION |
|
# define PEGASUS_PROCESS_NAME "cimservermain" |
|
#else |
|
# define PEGASUS_PROCESS_NAME "cimserver" |
|
#endif |
|
|
|
#include <Pegasus/Common/Executor.h> |
|
|
PEGASUS_USING_PEGASUS; | PEGASUS_USING_PEGASUS; |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
#define PEGASUS_PROCESS_NAME "cimserver"; |
|
|
|
//Windows service variables are not defined elsewhere in the product | //Windows service variables are not defined elsewhere in the product |
//enable ability to override these | //enable ability to override these |
#ifndef PEGASUS_SERVICE_NAME | #ifndef PEGASUS_SERVICE_NAME |
|
|
void cimserver_stop(void); | void cimserver_stop(void); |
}; | }; |
| |
|
ServerRunStatus _serverRunStatus( |
|
PEGASUS_PROCESS_NAME, PEGASUS_CIMSERVER_START_FILE); |
AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess()); | AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess()); |
static CIMServer* _cimServer = 0; | static CIMServer* _cimServer = 0; |
static Monitor* _monitor = 0; | static Monitor* _monitor = 0; |
|
|
| |
/** GetOptions function - This function defines the Options Table | /** GetOptions function - This function defines the Options Table |
and sets up the options from that table using the config manager. | and sets up the options from that table using the config manager. |
|
|
|
Some possible exceptions: NoSuchFile, FileNotReadable, CannotRenameFile, |
|
ConfigFileSyntaxError, UnrecognizedConfigProperty, InvalidPropertyValue, |
|
CannotOpenFile. |
*/ | */ |
void GetOptions( | void GetOptions( |
ConfigManager* cm, | ConfigManager* cm, |
int& argc, | int& argc, |
char** argv, | char** argv, |
const Boolean& shutdownOption) |
Boolean shutdownOption) |
{ |
|
try |
|
{ | { |
if (shutdownOption) | if (shutdownOption) |
{ | { |
|
|
// Enable updates again | // Enable updates again |
cm->useConfigFiles = true; | cm->useConfigFiles = true; |
} | } |
catch (NoSuchFile&) |
|
{ |
|
throw; |
|
} |
|
catch (FileNotReadable&) |
|
{ |
|
throw; |
|
} |
|
catch (CannotRenameFile&) |
|
{ |
|
throw; |
|
} |
|
catch (ConfigFileSyntaxError&) |
|
{ |
|
throw; |
|
} |
|
catch(UnrecognizedConfigProperty&) |
|
{ |
|
throw; |
|
} |
|
catch(InvalidPropertyValue&) |
|
{ |
|
throw; |
|
} |
|
catch (CannotOpenFile&) |
|
{ |
|
throw; |
|
} |
|
} |
|
| |
/* PrintHelp - This is temporary until we expand the options manager to allow | /* PrintHelp - This is temporary until we expand the options manager to allow |
options help to be defined with the OptionRow entries and presented from | options help to be defined with the OptionRow entries and presented from |
|
|
return((ThreadReturnType)0); | return((ThreadReturnType)0); |
} | } |
| |
// |
#ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION |
// Waits until either the CIM Server has terminated, or the shutdown timeout |
|
// has expired. If the shutdown timeout has expired, and the CIM Server is |
|
// still running, kills the cimserver process. |
|
// |
|
void _waitForTerminationOrTimeout (Uint32 maxWaitTime) |
|
{ |
|
// |
|
// If the CIM Server is still running, and the shutdown timeout has not |
|
// expired, loop and wait one second until either the CIM Server has |
|
// terminated, or the shutdown timeout has expired |
|
// |
|
Boolean running = _cimServerProcess->isCIMServerRunning (); |
|
while (running && (maxWaitTime > 0)) |
|
{ |
|
System::sleep (1); |
|
running = _cimServerProcess->isCIMServerRunning (); |
|
maxWaitTime--; |
|
} |
|
| |
// |
static int _extractExecutorSockOpt(int& argc, char**& argv) |
// If the shutdown timeout has expired, and the CIM Server is still |
|
// running, kill the cimserver process |
|
// |
|
if (running) |
|
{ | { |
int kill_rc = _cimServerProcess->cimserver_kill (0); |
// Extract the "--executor-socket <sock>" option if any. This indicates |
|
// that the e[x]ecutor is running. The option argument is the socket used |
|
// to communicate with the executor. Remove the option from the |
|
// argv list and decrease argc by two. |
| |
#ifdef PEGASUS_OS_OS400 |
int sock = -1; |
if (kill_rc == -1) |
const char OPT[] = "--executor-socket"; |
|
|
|
for (int i = 1; i < argc; i++) |
{ | { |
_cimServerProcess->cimserver_exitRC (2); |
if (strcmp(argv[i], OPT) == 0) |
} |
{ |
_cimServerProcess->cimserver_exitRC (1); |
// Check for missing option argument. |
#endif |
|
| |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \ |
if (i + 1 == argc) |
|| defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_SOLARIS) \ |
|
|| defined (PEGASUS_OS_VMS) |
|
if (kill_rc != -1) |
|
{ | { |
//l10n - TODO |
MessageLoaderParms parms( |
Logger::put_l (Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
"src.Server.cimserver.MISSING_OPTION_ARGUMENT", |
"src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED", |
"Missing argument for $0 option.", |
"Shutdown timeout expired. Forced shutdown initiated."); |
OPT); |
MessageLoaderParms parms |
cerr << argv[0] << ": " << MessageLoader::getMessage(parms) << |
("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED", |
endl; |
"Shutdown timeout expired. Forced shutdown initiated."); |
exit(1); |
cout << MessageLoader::getMessage(parms) << endl; |
|
exit (0); |
|
} |
|
#endif |
|
} |
|
} | } |
| |
void shutdownCIMOM(Uint32 timeoutValue) |
// Convert argument to positive integer. |
{ |
|
// |
|
// Create CIMClient object |
|
// |
|
CIMClient client; |
|
| |
// |
char* end; |
// Get local host name |
unsigned long x = strtoul(argv[i+1], &end, 10); |
// |
|
String hostStr = System::getHostName(); |
|
| |
// |
// Check whether option argument will fit in a signed integer. |
// open connection to CIMOM |
|
// |
|
try |
|
{ |
|
client.connectLocal(); |
|
| |
// |
if (*end != '\0' || x > 2147483647) |
// set client timeout to 2 seconds |
|
// |
|
client.setTimeout(2000); |
|
} |
|
catch(Exception&) |
|
{ | { |
#ifdef PEGASUS_OS_OS400 |
MessageLoaderParms parms( |
//l10n |
"src.Server.cimserver.BAD_OPTION_ARGUMENT", |
//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
"Bad $0 option argument: $1.", |
//"Unable to connect to CIM Server. CIM Server may not be running." ); |
OPT, |
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
argv[i+1]); |
"src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING", |
cerr << argv[0] << ": " << MessageLoader::getMessage(parms) << |
"Unable to connect to CIM Server. CIM Server may not be running." ); |
endl; |
// The server job may still be active but not responding. |
|
// Kill the job if it exists. |
|
if(_cimServerProcess->cimserver_kill(0) == -1) |
|
_cimServerProcess->cimserver_exitRC(2); |
|
_cimServerProcess->cimserver_exitRC(1); |
|
#else |
|
//l10n |
|
//PEGASUS_STD(cerr) << "Unable to connect to CIM Server." << PEGASUS_STD(endl); |
|
//PEGASUS_STD(cerr) << "CIM Server may not be running." << PEGASUS_STD(endl); |
|
MessageLoaderParms parms("src.Server.cimserver.UNABLE_CONNECT_SERVER_MAY_NOT_BE_RUNNING", |
|
"Unable to connect to CIM Server.\nCIM Server may not be running.\n"); |
|
PEGASUS_STD(cerr) << MessageLoader::getMessage(parms); |
|
exit(1); | exit(1); |
#endif |
|
} | } |
| |
try |
sock = int(x); |
{ |
|
// |
|
// construct CIMObjectPath |
|
// |
|
String referenceStr = "//"; |
|
referenceStr.append(hostStr); |
|
referenceStr.append("/"); |
|
referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN.getString()); |
|
referenceStr.append(":"); |
|
referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN.getString()); |
|
CIMObjectPath reference(referenceStr); |
|
| |
// |
// Remove "-x <sock>" from argv-argc. |
// issue the invokeMethod request on the shutdown method |
|
// |
|
Array<CIMParamValue> inParams; |
|
Array<CIMParamValue> outParams; |
|
|
|
// set force option to true for now |
|
inParams.append(CIMParamValue("force", |
|
CIMValue(Boolean(true)))); |
|
|
|
inParams.append(CIMParamValue("timeout", |
|
CIMValue(Uint32(timeoutValue)))); |
|
|
|
CIMValue retValue = client.invokeMethod( |
|
PEGASUS_NAMESPACENAME_SHUTDOWN, |
|
reference, |
|
"shutdown", |
|
inParams, |
|
outParams); |
|
} |
|
catch(CIMException& e) |
|
{ |
|
#ifdef PEGASUS_OS_OS400 |
|
| |
if (e.getCode() == CIM_ERR_INVALID_NAMESPACE) |
memmove(argv + i, argv + i + 2, sizeof(char*) * (argc - i - 1)); |
{ |
argc -= 2; |
//l10n |
break; |
//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
//"Failed to shutdown server: $0", "The repository may be empty."); |
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
"src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY", |
|
"Error in server shutdown: The repository may be empty."); |
|
} |
|
else |
|
{ |
|
//l10n |
|
//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
//"Failed to shutdown server: $0", e.getMessage()); |
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
"src.Server.cimserver.SHUTDOWN_FAILED", |
|
"Error in server shutdown: $0", e.getMessage()); |
|
} |
|
// Kill the server job. |
|
if(_cimServerProcess->cimserver_kill(0) == -1) |
|
_cimServerProcess->cimserver_exitRC(2); |
|
#else |
|
//l10n - TODO |
|
MessageLoaderParms parms("src.Server.cimserver.SHUTDOWN_FAILED", |
|
"Error in server shutdown: "); |
|
PEGASUS_STD(cerr) << MessageLoader::getMessage(parms); |
|
if (e.getCode() == CIM_ERR_INVALID_NAMESPACE) |
|
{ |
|
// |
|
// Repository may be empty. |
|
// |
|
//l10n - TODO |
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
"src.Server.cimserver.SHUTDOWN_FAILED_REPOSITORY_EMPTY", |
|
"Error in server shutdown: The repository may be empty."); |
|
MessageLoaderParms parms("src.Server.cimserver.REPOSITORY_EMPTY", |
|
"The repository may be empty."); |
|
PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl); |
|
} | } |
else |
|
{ |
|
//l10n - TODO |
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
"src.Server.cimserver.SHUTDOWN_FAILED", |
|
"Error in server shutdown: $0", e.getMessage()); |
|
PEGASUS_STD(cerr) << e.getMessage() << PEGASUS_STD(endl); |
|
} | } |
| |
// Kill the cimserver process |
if (sock == -1) |
if (_cimServerProcess->cimserver_kill(0) == 0) |
|
{ | { |
//l10n - TODO |
MessageLoaderParms parms( |
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
"src.Server.cimserver.MISSING_OPTION", |
"src.Server.cimserver.SERVER_FORCED_SHUTDOWN", |
"Missing $0 option.", |
"Forced shutdown initiated."); |
OPT); |
MessageLoaderParms parms("src.Server.cimserver.SERVER_FORCED_SHUTDOWN", |
cerr << argv[0] << ": " << MessageLoader::getMessage(parms) << endl; |
"Forced shutdown initiated."); |
|
PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl); |
|
} |
|
exit(1); | exit(1); |
#endif |
|
} |
|
catch(Exception&) |
|
{ |
|
// |
|
// This may mean that the CIM Server has terminated, causing this |
|
// client to get a "Empty HTTP response message" exception. It may |
|
// also mean that the CIM Server is taking longer than 2 seconds |
|
// (client timeout value) to terminate, causing this client to |
|
// timeout with a "connection timeout" exception. |
|
// |
|
// Wait until either the CIM Server has terminated, or the shutdown |
|
// timeout has expired. If the timeout has expired and the CIM Server |
|
// is still running, kill the cimserver process. |
|
// |
|
_waitForTerminationOrTimeout (timeoutValue - 2); |
|
} | } |
| |
// |
return sock; |
// InvokeMethod succeeded. |
|
// Wait until either the CIM Server has terminated, or the shutdown |
|
// timeout has expired. If the timeout has expired and the CIM Server |
|
// is still running, kill the cimserver process. |
|
// |
|
_waitForTerminationOrTimeout (timeoutValue); |
|
return; |
|
} | } |
| |
|
#endif /* PEGASUS_ENABLE_PRIVILEGE_SEPARATION */ |
| |
///////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////// |
// MAIN | // MAIN |
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// |
|
|
int main(int argc, char** argv) | int main(int argc, char** argv) |
{ | { |
String pegasusHome; | String pegasusHome; |
|
|
setlocale(LC_ALL, ""); | setlocale(LC_ALL, ""); |
#endif | #endif |
| |
#ifdef PEGASUS_OS_OS400 |
|
|
|
VFYPTRS_INCDCL; // VFYPTRS local variables |
|
|
|
// verify pointers |
|
#pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\ |
|
0,_C2_MH_ESCAPE) |
|
for( int arg_index = 1; arg_index < argc; arg_index++ ){ |
|
VFYPTRS(VERIFY_SPP_NULL(argv[arg_index])); |
|
} |
|
#pragma disable_handler |
|
|
|
// Convert the args to ASCII |
|
for(Uint32 i = 0;i< argc;++i) |
|
{ |
|
EtoA(argv[i]); |
|
} |
|
|
|
// Initialize Pegasus home to the shipped OS/400 directory. |
|
pegasusHome = OS400_DEFAULT_PEGASUS_HOME; |
|
#endif |
|
|
|
|
|
#ifndef PEGASUS_OS_TYPE_WINDOWS | #ifndef PEGASUS_OS_TYPE_WINDOWS |
// | // |
// Get environment variables: | // Get environment variables: |
// | // |
#ifdef PEGASUS_OS_OS400 |
|
#pragma convert(37) |
|
const char* tmp = getenv("PEGASUS_HOME"); |
|
#pragma convert(0) |
|
char home[256] = {0}; |
|
if (tmp && strlen(tmp) < 256) |
|
{ |
|
strcpy(home, tmp); |
|
EtoA(home); |
|
pegasusHome = home; |
|
} |
|
#else |
|
#if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS) | #if defined(PEGASUS_OS_AIX) && defined(PEGASUS_USE_RELEASE_DIRS) |
pegasusHome = AIX_RELEASE_PEGASUS_HOME; | pegasusHome = AIX_RELEASE_PEGASUS_HOME; |
#elif !defined(PEGASUS_USE_RELEASE_DIRS) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) | #elif !defined(PEGASUS_USE_RELEASE_DIRS) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) |
|
|
pegasusHome = tmp; | pegasusHome = tmp; |
} | } |
#endif | #endif |
#endif |
|
| |
FileSystem::translateSlashes(pegasusHome); | FileSystem::translateSlashes(pegasusHome); |
#else | #else |
|
|
pegasusHome = _cimServerProcess->getHome(); | pegasusHome = _cimServerProcess->getHome(); |
#endif | #endif |
| |
|
#ifdef PEGASUS_ENABLE_PRIVILEGE_SEPARATION |
|
|
|
// If invoked with "--executor-socket <socket>" option, then use executor. |
|
|
|
Executor::setSock(_extractExecutorSockOpt(argc, argv)); |
|
|
|
// Ping executor to verify the specified socket is valid. |
|
|
|
if (Executor::ping() != 0) |
|
{ |
|
MessageLoaderParms parms("src.Server.cimserver.EXECUTOR_PING_FAILED", |
|
"Failed to ping the executor on the specified socket."); |
|
cerr << argv[0] << ": " << MessageLoader::getMessage(parms) << endl; |
|
exit(1); |
|
} |
|
|
|
#endif /* !defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) */ |
|
|
// Get help, version, and shutdown options | // Get help, version, and shutdown options |
| |
for (int i = 1; i < argc; ) | for (int i = 1; i < argc; ) |
|
|
configManager = ConfigManager::getInstance(); | configManager = ConfigManager::getInstance(); |
configManager->useConfigFiles = true; | configManager->useConfigFiles = true; |
| |
#ifdef PEGASUS_OS_OS400 |
|
// In a special startup case for IBM OS400, when the server is |
|
// automatically started when the machine starts up the config |
|
// file cannot be read because of access restrictions for the |
|
// user starting the server. In this case, we need to skip |
|
// reading the config options and therefore any use of the config |
|
// manager also. To make this determinations we will check to see |
|
// if the daemon flag is set to true. If so, then there will be a |
|
// series of checks to bracket all the calls to the configManager |
|
// which would otherwise fail. All this will only be done for |
|
// IBM OS400. |
|
|
|
Boolean os400StartupOption = false; |
|
// loop through args to check for daemon=true |
|
for (int i=1; i < argc; i++) |
|
if (strcmp(argv[i], "daemon=true") == 0) |
|
{ |
|
os400StartupOption = true; |
|
daemonOption = true; |
|
} |
|
|
|
if (!os400StartupOption) |
|
{ |
|
// If this is the server job, then set the job |
|
// to save the job log. |
|
system ("QSYS/CHGJOB JOB(*) LOG(4 00 *SECLVL)"); |
|
} |
|
#endif |
|
|
|
// | // |
// Get options (from command line and from configuration file); this | // Get options (from command line and from configuration file); this |
// removes corresponding options and their arguments from the command | // removes corresponding options and their arguments from the command |
|
|
// | // |
try | try |
{ | { |
#ifdef PEGASUS_OS_OS400 |
|
if (os400StartupOption == false) |
|
#endif |
|
// If current process is "cimserver -s" (shutdown option = true) the contents | // If current process is "cimserver -s" (shutdown option = true) the contents |
// of current config should not be overwriten by planned config | // of current config should not be overwriten by planned config |
GetOptions(configManager, argc, argv, shutdownOption); | GetOptions(configManager, argc, argv, shutdownOption); |
|
|
"src.Server.cimserver.SERVER_NOT_STARTED", | "src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); | "cimserver not started: $0", e.getMessage()); |
| |
#if !defined(PEGASUS_OS_OS400) |
|
MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", | MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); | "cimserver not started: $0", e.getMessage()); |
| |
PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms) | PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms) |
<< PEGASUS_STD(endl); | << PEGASUS_STD(endl); |
#endif |
|
| |
return(1); | return(1); |
} | } |
|
|
MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath( | MessageLoader::setPegasusMsgHome(ConfigManager::getHomedPath( |
ConfigManager::getInstance()->getCurrentValue("messageDir"))); | ConfigManager::getInstance()->getCurrentValue("messageDir"))); |
| |
#ifdef PEGASUS_OS_OS400 |
|
// Still need to declare and set the connection variables. |
|
// Will initialize to false since they are fixed at false for OS400. |
|
|
|
// NOTE: OS400 is a LOCAL_DOMAIN_SOCKET, so a few lines down |
|
// the test will not be compiled in. If OS400 ever turns off that |
|
// define, then we will need to change this code path to insure that |
|
// one of the variables is true. |
|
Boolean enableHttpConnection = false; |
|
Boolean enableHttpsConnection = false; |
|
|
|
if (os400StartupOption == false) |
|
{ |
|
enableHttpConnection = ConfigManager::parseBooleanValue( |
|
configManager->getCurrentValue("enableHttpConnection")); |
|
enableHttpsConnection = ConfigManager::parseBooleanValue( |
|
configManager->getCurrentValue("enableHttpsConnection")); |
|
} |
|
#else |
|
Boolean enableHttpConnection = ConfigManager::parseBooleanValue( | Boolean enableHttpConnection = ConfigManager::parseBooleanValue( |
configManager->getCurrentValue("enableHttpConnection")); | configManager->getCurrentValue("enableHttpConnection")); |
Boolean enableHttpsConnection = ConfigManager::parseBooleanValue( | Boolean enableHttpsConnection = ConfigManager::parseBooleanValue( |
configManager->getCurrentValue("enableHttpsConnection")); | configManager->getCurrentValue("enableHttpsConnection")); |
#endif |
|
| |
// Make sure at least one connection is enabled | // Make sure at least one connection is enabled |
#ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET | #ifdef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET |
|
|
daemonOption = ConfigManager::parseBooleanValue( | daemonOption = ConfigManager::parseBooleanValue( |
configManager->getCurrentValue("daemon")); | configManager->getCurrentValue("daemon")); |
| |
#ifdef PEGASUS_OS_OS400 |
|
if (os400StartupOption == false) |
|
{ |
|
#endif |
|
#if !defined(PEGASUS_USE_SYSLOGS) | #if !defined(PEGASUS_USE_SYSLOGS) |
logsDirectory = | logsDirectory = |
ConfigManager::getHomedPath(configManager->getCurrentValue("logdir")); | ConfigManager::getHomedPath(configManager->getCurrentValue("logdir")); |
#endif | #endif |
#ifdef PEGASUS_OS_OS400 |
|
} // end if (os400StartupOption == false) |
|
#endif |
|
| |
// Set up the Logger. This does not open the logs | // Set up the Logger. This does not open the logs |
// 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. |
| |
#if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \ | #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_PLATFORM_LINUX_IA64_GNU) && \ |
!defined(PEGASUS_OS_OS400) && !defined(PEGASUS_USE_SYSLOGS) |
!defined(PEGASUS_USE_SYSLOGS) |
Logger::setHomeDirectory(logsDirectory); | Logger::setHomeDirectory(logsDirectory); |
#endif | #endif |
| |
|
|
unregisterPegasusFromSLP(); | unregisterPegasusFromSLP(); |
#endif | #endif |
| |
shutdownCIMOM(timeoutValue); |
ServerShutdownClient serverShutdownClient(&_serverRunStatus); |
|
serverShutdownClient.shutdown(timeoutValue); |
| |
#ifdef PEGASUS_OS_OS400 |
MessageLoaderParms parms( |
//l10n |
|
//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION, |
|
//"CIM Server stopped."); |
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::INFORMATION, |
|
"src.Server.cimserver.SERVER_STOPPED", | "src.Server.cimserver.SERVER_STOPPED", |
"CIM Server stopped."); | "CIM Server stopped."); |
cimserver_exitRC(0); |
|
#else |
|
//l10n |
|
//cout << "CIM Server stopped." << endl; |
|
MessageLoaderParms parms("src.Server.cimserver.SERVER_STOPPED", |
|
"CIM Server stopped."); |
|
| |
cout << MessageLoader::getMessage(parms) << endl; | cout << MessageLoader::getMessage(parms) << endl; |
return(0); | return(0); |
#endif |
|
} | } |
| |
#if defined(PEGASUS_DEBUG) |
#if defined(PEGASUS_DEBUG) && !defined(PEGASUS_USE_SYSLOGS) |
// Leave this in until people get familiar with the logs. | // Leave this in until people get familiar with the logs. |
//l10n |
|
//cout << "Logs Directory = " << logsDirectory << endl; |
|
#if !defined(PEGASUS_USE_SYSLOGS) |
|
MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY", | MessageLoaderParms parms("src.Server.cimserver.LOGS_DIRECTORY", |
"Logs Directory = "); | "Logs Directory = "); |
cout << MessageLoader::getMessage(parms) << logsDirectory << endl; | cout << MessageLoader::getMessage(parms) << logsDirectory << endl; |
#endif | #endif |
#endif |
|
} | } |
catch (UnrecognizedConfigProperty& e) | catch (UnrecognizedConfigProperty& e) |
{ | { |
|
|
System::CIMSERVER, | System::CIMSERVER, |
Logger::SEVERE, | Logger::SEVERE, |
e.getMessage()); | e.getMessage()); |
#ifndef PEGASUS_OS_OS400 |
|
cout << e.getMessage() << endl; | cout << e.getMessage() << endl; |
#endif |
|
} | } |
catch (Exception& ex) | catch (Exception& ex) |
{ | { |
|
|
System::CIMSERVER, | System::CIMSERVER, |
Logger::SEVERE, | Logger::SEVERE, |
ex.getMessage()); | ex.getMessage()); |
#ifndef PEGASUS_OS_OS400 |
|
cout << ex.getMessage() << endl; | cout << ex.getMessage() << endl; |
#endif |
|
exit(1); | exit(1); |
} | } |
| |
|
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, | Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
"src.Server.cimserver.SERVER_NOT_STARTED", | "src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); | "cimserver not started: $0", e.getMessage()); |
#if !defined(PEGASUS_OS_OS400) |
|
MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", | MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); | "cimserver not started: $0", e.getMessage()); |
PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms) | PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms) |
<< PEGASUS_STD(endl); | << PEGASUS_STD(endl); |
#endif |
|
exit(1); | exit(1); |
} | } |
} | } |
|
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, | Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
"src.Server.cimserver.SERVER_NOT_STARTED", | "src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); | "cimserver not started: $0", e.getMessage()); |
#if !defined(PEGASUS_OS_OS400) |
|
MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", | MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); | "cimserver not started: $0", e.getMessage()); |
PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms) | PEGASUS_STD(cerr) << argv[0] << ": " << MessageLoader::getMessage(parms) |
<< PEGASUS_STD(endl); | << PEGASUS_STD(endl); |
#endif |
|
exit(1); | exit(1); |
} | } |
} | } |
|
|
//l10n | //l10n |
| |
// Get the parent's PID before forking | // Get the parent's PID before forking |
_cimServerProcess->set_parent_pid(System::getPID()); |
_serverRunStatus.setParentPid(System::getPID()); |
| |
// do we need to run as a daemon ? |
// Do not fork when using privilege separation (executor will daemonize itself |
|
// later). |
if (daemonOption) | if (daemonOption) |
{ | { |
if(-1 == _cimServerProcess->cimserver_fork()) | if(-1 == _cimServerProcess->cimserver_fork()) |
#ifndef PEGASUS_OS_OS400 |
|
{ |
|
return(-1); |
|
} |
|
#else |
|
{ |
|
return(-1); | return(-1); |
} |
|
else | else |
{ |
|
return(0); | return(0); |
} | } |
#endif |
|
|
|
} |
|
| |
// l10n | // l10n |
// Now we are after the fork... | // Now we are after the fork... |
|
|
e.getMessage()); | e.getMessage()); |
} | } |
| |
|
|
|
|
#ifdef PEGASUS_OS_OS400 |
|
// Special server initialization code for OS/400. |
|
if (cimserver_initialize() != 0) |
|
{ |
|
// do some logging here! |
|
//l10n |
|
//Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
//"CIM Server failed to initialize"); |
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
"src.Server.cimserver.SERVER_FAILED_TO_INITIALIZE", |
|
"CIM Server failed to initialize"); |
|
return(-1); |
|
} |
|
#endif |
|
|
|
#ifndef PEGASUS_OS_TYPE_WINDOWS | #ifndef PEGASUS_OS_TYPE_WINDOWS |
umask(S_IRWXG|S_IRWXO); | umask(S_IRWXG|S_IRWXO); |
#endif | #endif |
|
|
// if CIMServer is already running, print message and | // if CIMServer is already running, print message and |
// notify parent process (if there is a parent process) to terminate | // notify parent process (if there is a parent process) to terminate |
// | // |
if(_cimServerProcess->isCIMServerRunning()) |
if (_serverRunStatus.isServerRunning()) |
{ | { |
//l10n |
MessageLoaderParms parms( |
//cout << "Unable to start CIMServer." << endl; |
"src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING", |
//cout << "CIMServer is already running." << endl; |
|
MessageLoaderParms parms("src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING", |
|
"Unable to start CIMServer. CIMServer is already running."); | "Unable to start CIMServer. CIMServer is already running."); |
PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl); |
PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << |
|
PEGASUS_STD(endl); |
Logger::put(Logger::ERROR_LOG,System::CIMSERVER,Logger::INFORMATION, | Logger::put(Logger::ERROR_LOG,System::CIMSERVER,Logger::INFORMATION, |
MessageLoader::getMessage(parms)); | MessageLoader::getMessage(parms)); |
| |
|
|
// notify parent process (if there is a parent process) to terminate | // notify parent process (if there is a parent process) to terminate |
// | // |
if (daemonOption) | if (daemonOption) |
|
{ |
_cimServerProcess->notify_parent(1); | _cimServerProcess->notify_parent(1); |
|
} |
| |
return(1); |
return 1; |
} | } |
| |
#endif | #endif |
|
|
// try loop to bind the address, and run the server | // try loop to bind the address, and run the server |
try | try |
{ | { |
|
|
_monitor = new Monitor(); | _monitor = new Monitor(); |
//PEP#222 |
|
//CIMServer server(&monitor); |
|
//CimserverHolder cimserverHolder( &server ); |
|
_cimServer = new CIMServer(_monitor); | _cimServer = new CIMServer(_monitor); |
| |
|
|
if (enableHttpConnection) | if (enableHttpConnection) |
{ | { |
_cimServer->addAcceptor(false, portNumberHttp, false); | _cimServer->addAcceptor(false, portNumberHttp, false); |
//l10n |
|
//Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, |
|
//"Listening on HTTP port $0.", portNumberHttp); |
|
| |
Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, |
Logger::put_l( |
|
Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, |
"src.Server.cimserver.LISTENING_ON_HTTP_PORT", | "src.Server.cimserver.LISTENING_ON_HTTP_PORT", |
"Listening on HTTP port $0.", portNumberHttp); | "Listening on HTTP port $0.", portNumberHttp); |
} | } |
|
|
if (enableHttpsConnection) | if (enableHttpsConnection) |
{ | { |
_cimServer->addAcceptor(false, portNumberHttps, true); | _cimServer->addAcceptor(false, portNumberHttps, true); |
//l10n |
|
//Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, |
Logger::put_l( |
//"Listening on HTTPS port $0.", portNumberHttps); |
Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, |
Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, |
|
"src.Server.cimserver.LISTENING_ON_HTTPS_PORT", | "src.Server.cimserver.LISTENING_ON_HTTPS_PORT", |
"Listening on HTTPS port $0.", portNumberHttps); | "Listening on HTTPS port $0.", portNumberHttps); |
} | } |
| |
#ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET | #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET |
_cimServer->addAcceptor(true, 0, false); | _cimServer->addAcceptor(true, 0, false); |
//l10n |
|
//Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, |
Logger::put_l( |
//"Listening on local connection socket."); |
Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, |
Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, |
|
"src.Server.cimserver.LISTENING_ON_LOCAL", | "src.Server.cimserver.LISTENING_ON_LOCAL", |
"Listening on local connection socket."); | "Listening on local connection socket."); |
#endif | #endif |
|
|
#if defined(PEGASUS_DEBUG) | #if defined(PEGASUS_DEBUG) |
if (enableHttpConnection) | if (enableHttpConnection) |
{ | { |
//l10n |
MessageLoaderParms parms( |
//cout << "Listening on HTTP port " << portNumberHttp << endl; |
"src.Server.cimserver.LISTENING_ON_HTTP_PORT", |
MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTP_PORT", |
|
"Listening on HTTP port $0.", portNumberHttp); | "Listening on HTTP port $0.", portNumberHttp); |
cout << MessageLoader::getMessage(parms) << endl; | cout << MessageLoader::getMessage(parms) << endl; |
} | } |
if (enableHttpsConnection) | if (enableHttpsConnection) |
{ | { |
//l10n |
MessageLoaderParms parms( |
//cout << "Listening on HTTPS port " << portNumberHttps << endl; |
"src.Server.cimserver.LISTENING_ON_HTTPS_PORT", |
MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_HTTPS_PORT", |
|
"Listening on HTTPS port $0.", portNumberHttps); | "Listening on HTTPS port $0.", portNumberHttps); |
cout << MessageLoader::getMessage(parms) << endl; | cout << MessageLoader::getMessage(parms) << endl; |
} | } |
| |
# ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET | # ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET |
//l10n |
MessageLoaderParms parms( |
//cout << "Listening on local connection socket" << endl; |
"src.Server.cimserver.LISTENING_ON_LOCAL", |
MessageLoaderParms parms("src.Server.cimserver.LISTENING_ON_LOCAL", |
|
"Listening on local connection socket."); | "Listening on local connection socket."); |
cout << MessageLoader::getMessage(parms) << endl; | cout << MessageLoader::getMessage(parms) << endl; |
# endif | # endif |
#endif | #endif |
| |
_cimServer->bind(); | _cimServer->bind(); |
|
|
// notify parent process (if there is a parent process) to terminate | // notify parent process (if there is a parent process) to terminate |
// so user knows that there is cimserver ready to serve CIM requests. | // so user knows that there is cimserver ready to serve CIM requests. |
if (daemonOption) | if (daemonOption) |
|
{ |
|
#if defined(PEGASUS_ENABLE_PRIVILEGE_SEPARATION) |
|
Executor::daemonizeExecutor(); |
|
#else |
_cimServerProcess->notify_parent(0); | _cimServerProcess->notify_parent(0); |
|
#endif |
|
} |
| |
time_t last = 0; |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || \ |
|
defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) || \ |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \ |
defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS) |
|| defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_SOLARIS) \ |
|
|| defined(PEGASUS_OS_VMS) |
|
// | // |
// create a file to indicate that the cimserver has started and | // create a file to indicate that the cimserver has started and |
// save the process id of the cimserver process in the file | // save the process id of the cimserver process in the file |
// | // |
// remove the old file if it exists |
_serverRunStatus.setServerRunning(); |
System::removeFile(_cimServerProcess->getPIDFileName()); |
|
|
|
// open the file |
|
FILE *pid_file = fopen(_cimServerProcess->getPIDFileName(), "w"); |
|
|
|
if (pid_file) |
|
{ |
|
// save the pid in the file |
|
fprintf(pid_file, "%ld\n", _cimServerProcess->get_server_pid()); |
|
fclose(pid_file); |
|
} |
|
#endif | #endif |
| |
#if defined(PEGASUS_DEBUG) | #if defined(PEGASUS_DEBUG) |
|
|
Logger::INFORMATION, | Logger::INFORMATION, |
"src.Server.cimserver.STARTED_VERSION", | "src.Server.cimserver.STARTED_VERSION", |
"Started $0 version $1.", | "Started $0 version $1.", |
_cimServerProcess->getProductName(), _cimServerProcess->getCompleteVersion()); |
_cimServerProcess->getProductName(), |
|
_cimServerProcess->getCompleteVersion()); |
| |
#if defined(PEGASUS_OS_TYPE_UNIX) && !defined(PEGASUS_OS_ZOS) | #if defined(PEGASUS_OS_TYPE_UNIX) && !defined(PEGASUS_OS_ZOS) |
if (daemonOption && !debugOutputOption) | if (daemonOption && !debugOutputOption) |
|
|
| |
#endif | #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 |
|
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, | Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
"src.Server.cimserver.SERVER_NOT_STARTED", | "src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); | "cimserver not started: $0", e.getMessage()); |
|
|
#if !defined(PEGASUS_OS_OS400) |
|
MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", | MessageLoaderParms parms("src.Server.cimserver.SERVER_NOT_STARTED", |
"cimserver not started: $0", e.getMessage()); | "cimserver not started: $0", e.getMessage()); |
| |
cerr << MessageLoader::getMessage(parms) << endl; | cerr << MessageLoader::getMessage(parms) << endl; |
#endif |
|
| |
// | // |
// notify parent process (if there is a parent process) to terminate | // notify parent process (if there is a parent process) to terminate |
|
|
Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING, | Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING, |
"src.Server.cimserver.ERROR", | "src.Server.cimserver.ERROR", |
"Error: $0", e.getMessage()); | "Error: $0", e.getMessage()); |
#ifndef PEGASUS_OS_OS400 |
|
MessageLoaderParms parms("src.Server.cimserver.ERROR", | MessageLoaderParms parms("src.Server.cimserver.ERROR", |
"Error: $0", e.getMessage()); | "Error: $0", e.getMessage()); |
PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl); |
#endif |
|
// | // |
// notify parent process (if there is a parent process) to terminate | // notify parent process (if there is a parent process) to terminate |
// | // |
|
|
deleteCIMServer(); | deleteCIMServer(); |
return 0; | return 0; |
} | } |
|
|
|
|
|
|
|
|