version 1.7, 2007/04/03 18:51:01
|
version 1.8, 2007/05/08 18:30:52
|
|
|
#include <Pegasus/Common/MessageLoader.h> | #include <Pegasus/Common/MessageLoader.h> |
#include <Pegasus/Common/Thread.h> | #include <Pegasus/Common/Thread.h> |
#include <Pegasus/Server/CIMServer.h> | #include <Pegasus/Server/CIMServer.h> |
|
#include <Service/ServerRunStatus.h> |
| |
#include "Service.cpp" | #include "Service.cpp" |
| |
PEGASUS_USING_PEGASUS; | PEGASUS_USING_PEGASUS; |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
static const char* _ALREADY_RUNNING_NAME = 0; |
|
|
|
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- |
// GLOBALS | // GLOBALS |
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- |
|
|
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- |
int ServerProcess::cimserver_fork(void) { return(0); } | int ServerProcess::cimserver_fork(void) { return(0); } |
void ServerProcess::notify_parent(int id) { return; } | void ServerProcess::notify_parent(int id) { return; } |
long ServerProcess::get_server_pid(void) { return 0; } |
|
void ServerProcess::set_parent_pid(int pid) {} |
|
int ServerProcess::get_proc(int pid) { return 0; } |
|
int ServerProcess::cimserver_kill(int id) { return(0); } |
|
void cimserver_exitRC(int rc) {} | void cimserver_exitRC(int rc) {} |
int ServerProcess::cimserver_initialize(void) { return 0; } | int ServerProcess::cimserver_initialize(void) { return 0; } |
int ServerProcess::cimserver_wait(void) { return 0; } | int ServerProcess::cimserver_wait(void) { return 0; } |
|
|
_server_proc->cimserver_stop(); | _server_proc->cimserver_stop(); |
| |
pegasus_service = Service(getProcessName()); | pegasus_service = Service(getProcessName()); |
_ALREADY_RUNNING_NAME = getProcessName(); |
|
} | } |
| |
void signal_shutdown() | void signal_shutdown() |
|
|
return 0; | return 0; |
} | } |
| |
//------------------------------------------------------------------------- |
|
// IS RUNNING? |
|
//------------------------------------------------------------------------- |
|
|
|
class AlreadyRunning |
|
{ |
|
public: |
|
AlreadyRunning(): alreadyRunning( true ), event( NULL ) |
|
{ |
|
} |
|
~AlreadyRunning() |
|
{ |
|
if( event != NULL ) |
|
CloseHandle( event ); |
|
} |
|
|
|
void Init() |
|
{ |
|
if( event == NULL ) |
|
{ |
|
event = CreateEvent( NULL, TRUE, TRUE, _ALREADY_RUNNING_NAME ); |
|
if( event != NULL && GetLastError() != ERROR_ALREADY_EXISTS ) |
|
alreadyRunning = false; |
|
} |
|
} |
|
|
|
bool IsAlreadyRunning() |
|
{ |
|
return alreadyRunning; |
|
} |
|
|
|
bool alreadyRunning; |
|
HANDLE event; |
|
}; |
|
|
|
AlreadyRunning _alreadyRunning; |
|
|
|
|
|
Boolean ServerProcess::isCIMServerRunning(void) |
|
{ |
|
//Service::State state; |
|
//pegasus_service.GetState(&state); |
|
//return (state == Service::SERVICE_STATE_RUNNING) ? true : false; |
|
|
|
// We do it this way so this will work when run as a |
|
// console process and a Windows service. |
|
AlreadyRunning ar; |
|
ar.Init(); |
|
return ar.IsAlreadyRunning(); |
|
} |
|
| |
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- |
// INSTALL | // INSTALL |
|
|
// Signal ourself as running | // Signal ourself as running |
// | // |
| |
|
// NOTE: This object must persist for the life of the server process |
|
ServerRunStatus serverRunStatus(getProcessName(), getPIDFileName()); |
|
|
if( !shutdownOption ) | if( !shutdownOption ) |
_alreadyRunning.Init(); |
{ |
|
serverRunStatus.setServerRunning(0); |
|
} |
| |
// | // |
// Check if already running | // Check if already running |
|
|
// then the service will start up then die silently. | // then the service will start up then die silently. |
// | // |
| |
if( !shutdownOption && _alreadyRunning.IsAlreadyRunning() ) |
if (!shutdownOption && serverRunStatus.isServerRunning()) |
{ | { |
MessageLoaderParms parms( | MessageLoaderParms parms( |
"src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING", | "src.Server.cimserver.UNABLE_TO_START_SERVER_ALREADY_RUNNING", |