version 1.161, 2005/05/05 20:24:31
|
version 1.171, 2005/11/17 17:01:00
|
|
|
// Author: Mike Brasher (mbrasher@bmc.com) | // Author: Mike Brasher (mbrasher@bmc.com) |
// | // |
// Modified By: Mike Day (mdday@us.ibm.com) | // Modified By: Mike Day (mdday@us.ibm.com) |
// |
// Karl Schopmeyer (k.schopmeyer@opengroup.org) |
// Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org) |
// Nag Boranna (nagaraja_boranna@hp.com) |
// |
// Jenny Yu (jenny_yu@hp.com) |
// Modified By: Nag Boranna (nagaraja_boranna@hp.com) |
// Sushma Fernandes (sushma_fernandes@hp.com) |
// |
|
// Modified By: Jenny Yu (jenny_yu@hp.com) |
|
// |
|
// Modified By: Sushma Fernandes (sushma_fernandes@hp.com) |
|
// Carol Ann Krug Graves, Hewlett-Packard Company | // Carol Ann Krug Graves, Hewlett-Packard Company |
// (carolann_graves@hp.com) | // (carolann_graves@hp.com) |
// Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com) | // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com) |
// |
// Dave Rosckes (rosckes@us.ibm.com) |
// Modified By: Dave Rosckes (rosckes@us.ibm.com) |
// Humberto Rivero (hurivero@us.ibm.com) |
// |
// Steve Hills (steve.hills@ncr.com) |
// Modified By: Humberto Rivero (hurivero@us.ibm.com) |
|
// |
|
// Modified By: Steve Hills (steve.hills@ncr.com) |
|
// Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com) | // Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com) |
// |
// Amit K Arora, IBM (amitarora@in.ibm.com) - pep 167 |
// Modified By: Amit K Arora, IBM (amitarora@in.ibm.com) - pep 167 |
// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2555 |
// |
// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2032 |
// Modified By: Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2555 |
// Heather Sterling, IBM (hsterl@us.ibm.com) - PEP#222 |
// |
// Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#3452 |
// Modified By: Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#2032 |
// David Dillard, VERITAS Software Corp. |
// |
// (david.dillard@veritas.com) |
// Modified By: Heather Sterling, IBM (hsterl@us.ibm.com) - PEP#222 |
|
// |
|
// Modified By: Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) - Bug#3452 |
|
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
| |
////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////// |
// | // |
// Notes on deamon operation (Unix) and service operation (Win 32): |
// Notes on daemon operation (Unix) and service operation (Win 32): |
// | // |
// To run pegasus as a daemon on Unix platforms: | // To run pegasus as a daemon on Unix platforms: |
// | // |
|
|
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/Constants.h> | #include <Pegasus/Common/Constants.h> |
#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/Common/PegasusVersion.h> | #include <Pegasus/Common/PegasusVersion.h> |
|
|
| |
AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess()); | AutoPtr<CIMServerProcess> _cimServerProcess(new CIMServerProcess()); |
static CIMServer* _cimServer = 0; | static CIMServer* _cimServer = 0; |
|
static Monitor* _monitor = 0; |
|
static Thread* dummyInitialThread = 0; |
// | // |
// The command name. | // The command name. |
// | // |
|
|
{ | { |
delete _cimServer; | delete _cimServer; |
_cimServer = 0; | _cimServer = 0; |
|
|
|
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) \ |
|
|| defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \ |
|
|| defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS) |
|
// |
|
// Remove the PID file to indicate CIMServer termination |
|
// |
|
FileSystem::removeFile(_cimServerProcess->getPIDFileName()); |
|
#endif |
|
} |
|
if (_monitor) |
|
{ |
|
delete _monitor; |
|
} |
|
if (dummyInitialThread) |
|
{ |
|
Thread::clearLanguages(); |
|
delete dummyInitialThread; |
} | } |
} | } |
| |
|
|
return((PEGASUS_THREAD_RETURN)0); | return((PEGASUS_THREAD_RETURN)0); |
} | } |
| |
|
// |
|
// 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--; |
|
} |
|
|
|
// |
|
// 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); |
|
|
|
#ifdef PEGASUS_OS_OS400 |
|
if (kill_rc == -1) |
|
{ |
|
_cimServerProcess->cimserver_exitRC (2); |
|
} |
|
_cimServerProcess->cimserver_exitRC (1); |
|
#endif |
|
|
|
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \ |
|
|| defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_SOLARIS) \ |
|
|| defined (PEGASUS_OS_VMS) |
|
if (kill_rc != -1) |
|
{ |
|
//l10n - TODO |
|
Logger::put_l (Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
"src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED", |
|
"Shutdown timeout expired. Forced shutdown initiated."); |
|
MessageLoaderParms parms |
|
("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED", |
|
"Shutdown timeout expired. Forced shutdown initiated."); |
|
cout << MessageLoader::getMessage(parms) << endl; |
|
exit (0); |
|
} |
|
#endif |
|
} |
|
} |
|
|
void shutdownCIMOM(Uint32 timeoutValue) | void shutdownCIMOM(Uint32 timeoutValue) |
{ | { |
// | // |
|
|
"Forced shutdown initiated."); | "Forced shutdown initiated."); |
PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << MessageLoader::getMessage(parms) << PEGASUS_STD(endl); |
} | } |
PEGASUS_STD(cerr) << "Exit! " << endl; |
|
exit(1); | exit(1); |
#endif | #endif |
} | } |
|
|
// (client timeout value) to terminate, causing this client to | // (client timeout value) to terminate, causing this client to |
// timeout with a "connection timeout" exception. | // timeout with a "connection timeout" exception. |
// | // |
// Check to see if CIM Server is still running. If CIM Server |
// Wait until either the CIM Server has terminated, or the shutdown |
// is still running and the shutdown timeout has not expired, |
// timeout has expired. If the timeout has expired and the CIM Server |
// loop and wait one second until either the CIM Server is |
// is still running, kill the cimserver process. |
// terminated or timeout expires. If timeout expires and |
|
// the CIM Server is still running, kill the CIMServer process. |
|
// | // |
Uint32 maxWaitTime = timeoutValue - 2; |
_waitForTerminationOrTimeout (timeoutValue - 2); |
Boolean running = _cimServerProcess->isCIMServerRunning(); |
|
while ( running && maxWaitTime > 0 ) |
|
{ |
|
System::sleep(1); |
|
running = _cimServerProcess->isCIMServerRunning(); |
|
maxWaitTime = maxWaitTime - 1; |
|
} |
|
|
|
if (running) |
|
{ |
|
int kill_rc = _cimServerProcess->cimserver_kill(0); |
|
|
|
#ifdef PEGASUS_OS_OS400 |
|
if(kill_rc == -1) |
|
_cimServerProcess->cimserver_exitRC(2); |
|
_cimServerProcess->cimserver_exitRC(1); |
|
#endif |
|
|
|
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \ |
|
|| defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) \ |
|
|| defined (PEGASUS_OS_VMS) |
|
if (kill_rc != -1) |
|
{ |
|
//l10n - TODO |
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
"src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED", |
|
"Shutdown timeout expired. Forced shutdown initiated."); |
|
MessageLoaderParms parms("src.Server.cimserver.TIMEOUT_EXPIRED_SERVER_KILLED", |
|
"Shutdown timeout expired. Forced shutdown initiated."); |
|
cout << MessageLoader::getMessage(parms) << endl; |
|
exit(0); |
|
} |
|
#endif |
|
} |
|
} | } |
| |
|
// |
|
// 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; | return; |
} | } |
| |
|
|
#else | #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) |
#elif !defined(PEGASUS_USE_RELEASE_DIRS) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) |
const char* tmp = getenv("PEGASUS_HOME"); | const char* tmp = getenv("PEGASUS_HOME"); |
| |
if (tmp) | if (tmp) |
|
|
ConfigManager::setPegasusHome(pegasusHome); | ConfigManager::setPegasusHome(pegasusHome); |
| |
// | // |
// Do the plaform specific run |
// Do the platform specific run |
// | // |
| |
return _cimServerProcess->platform_run( argc, argv, shutdownOption ); | return _cimServerProcess->platform_run( argc, argv, shutdownOption ); |
|
|
// will fail to shutdown properly/cleanly. | // will fail to shutdown properly/cleanly. |
// | // |
// TODO: Current change minimal for platform "service" shutdown bug fixes. | // TODO: Current change minimal for platform "service" shutdown bug fixes. |
// Perhpas further extract out common stuff and put into main(), put |
// Perhaps further extract out common stuff and put into main(), put |
// daemon stuff into platform specific platform_run(), etc. | // daemon stuff into platform specific platform_run(), etc. |
// Note: make sure to not put error handling stuff that platform | // Note: make sure to not put error handling stuff that platform |
// specific runs may need to deal with bettter (instead of exit(), etc). |
// specific runs may need to deal with better (instead of exit(), etc). |
// | // |
| |
int CIMServerProcess::cimserver_run( int argc, char** argv, Boolean shutdownOption ) | int CIMServerProcess::cimserver_run( int argc, char** argv, Boolean shutdownOption ) |
|
|
os400StartupOption = true; | os400StartupOption = true; |
daemonOption = 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 | #endif |
| |
// | // |
|
|
// because this thread is not in a ThreadPool, but is used | // because this thread is not in a ThreadPool, but is used |
// to service CIM requests. | // to service CIM requests. |
// The run function for the dummy Thread should never be called, | // The run function for the dummy Thread should never be called, |
Thread *dummyInitialThread = new Thread(dummyThreadFunc, NULL, false); |
dummyInitialThread = new Thread(dummyThreadFunc, NULL, false); |
Thread::setCurrent(dummyInitialThread); | Thread::setCurrent(dummyInitialThread); |
AcceptLanguages default_al; | AcceptLanguages default_al; |
try{ | try{ |
|
|
} | } |
#endif | #endif |
| |
|
#ifndef PEGASUS_OS_TYPE_WINDOWS |
|
umask(S_IRWXG|S_IRWXO); |
|
#endif |
| |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \ | #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \ |
|| defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \ | || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \ |
|| defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || defined (PEGASUS_OS_VMS) |
|| defined(PEGASUS_OS_SOLARIS) || defined (PEGASUS_OS_VMS) |
umask(S_IWGRP|S_IWOTH); |
|
| |
// | // |
// check if CIMServer is already running | // check if CIMServer is already running |
|
|
try | try |
{ | { |
| |
Monitor monitor; |
_monitor = new Monitor(); |
//PEP#222 | //PEP#222 |
//CIMServer server(&monitor); | //CIMServer server(&monitor); |
//CimserverHolder cimserverHolder( &server ); | //CimserverHolder cimserverHolder( &server ); |
_cimServer = new CIMServer(&monitor); |
_cimServer = new CIMServer(_monitor); |
| |
| |
if (enableHttpConnection) | if (enableHttpConnection) |
|
|
#endif | #endif |
| |
// bind throws an exception if the bind fails | // bind throws an exception if the bind fails |
|
try { |
_cimServer->bind(); | _cimServer->bind(); |
|
} catch (const BindFailedException &e) |
|
{ |
|
#ifdef PEGASUS_DEBUG |
|
MessageLoaderParms parms("src.Server.cimserver.BIND_FAILED", |
|
"Could not bind: $0.", e.getMessage()); |
|
cout << MessageLoader::getMessage(parms) << endl; |
|
#endif |
|
Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE, |
|
"src.Server.cimserver.BIND.FAILED", |
|
"Could not bind: $0", e.getMessage()); |
| |
|
deleteCIMServer(); |
|
return 1; |
|
} |
// 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) |
|
|
time_t last = 0; | time_t last = 0; |
| |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \ | #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) \ |
|| defined(PEGASUS_OS_AIX) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) \ |
|| defined(PEGASUS_OS_AIX) || defined(PEGASUS_OS_SOLARIS) \ |
|| defined(PEGASUS_OS_VMS) | || 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 |
|
|
Logger::INFORMATION, "src.Server.cimserver.STOPPED", | Logger::INFORMATION, "src.Server.cimserver.STOPPED", |
"$0 stopped.", _cimServerProcess->getProductName()); | "$0 stopped.", _cimServerProcess->getProductName()); |
| |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) \ |
#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) \ |
|| defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \ | || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_OS_AIX) \ |
|| defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || defined(PEGASUS_OS_VMS) |
|| defined(PEGASUS_OS_SOLARIS) || defined(PEGASUS_OS_VMS) |
// | // |
// close the file created at startup time to indicate that the |
// Note: do not remove the PID file created at startup time, since |
// cimserver has terminated normally. |
// shutdown is not complete until the CIMServer destructor completes. |
// | // |
FileSystem::removeFile(_cimServerProcess->getPIDFileName()); |
|
#endif | #endif |
} | } |
catch(Exception& e) | catch(Exception& e) |