2011-07-14 Vanessa Gil <vanessa.gil@artica.es>
* win32/pandora_agent_conf.cc win32/pandora_windows_service.cc win32/main.cc: Created runtime enviroment variables for agents and fixed bug in drone agents. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4559 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
5b4fd01d4a
commit
8607818525
|
@ -1,3 +1,9 @@
|
||||||
|
2011-07-14 Vanessa Gil <vanessa.gil@artica.es>
|
||||||
|
|
||||||
|
* win32/pandora_agent_conf.cc
|
||||||
|
win32/pandora_windows_service.cc
|
||||||
|
win32/main.cc: Created runtime enviroment variables for agents and fixed bug in drone agents.
|
||||||
|
|
||||||
2011-07-11 Vanessa Gil <vanessa.gil@artica.es>
|
2011-07-11 Vanessa Gil <vanessa.gil@artica.es>
|
||||||
|
|
||||||
* win32/pandora_agent_conf.cc
|
* win32/pandora_agent_conf.cc
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "pandora.h"
|
#include "pandora.h"
|
||||||
#include "pandora_windows_service.h"
|
#include "pandora_windows_service.h"
|
||||||
|
@ -27,6 +28,9 @@
|
||||||
#include "debug_new.h"
|
#include "debug_new.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Pandora;
|
||||||
|
|
||||||
#define PATH_SIZE _MAX_PATH+1
|
#define PATH_SIZE _MAX_PATH+1
|
||||||
#define SERVICE_INSTALL_CMDLINE_PARAM "--install"
|
#define SERVICE_INSTALL_CMDLINE_PARAM "--install"
|
||||||
#define SERVICE_UNINSTALL_CMDLINE_PARAM "--uninstall"
|
#define SERVICE_UNINSTALL_CMDLINE_PARAM "--uninstall"
|
||||||
|
@ -42,6 +46,7 @@ main (int argc, char *argv[]) {
|
||||||
string aux;
|
string aux;
|
||||||
unsigned int pos;
|
unsigned int pos;
|
||||||
bool process = false;
|
bool process = false;
|
||||||
|
string home;
|
||||||
|
|
||||||
service = Pandora_Windows_Service::getInstance ();
|
service = Pandora_Windows_Service::getInstance ();
|
||||||
service->setValues (Pandora::name, Pandora::display_name,
|
service->setValues (Pandora::name, Pandora::display_name,
|
||||||
|
@ -55,6 +60,10 @@ main (int argc, char *argv[]) {
|
||||||
aux.erase (pos + 1);
|
aux.erase (pos + 1);
|
||||||
Pandora::setPandoraInstallDir (aux);
|
Pandora::setPandoraInstallDir (aux);
|
||||||
|
|
||||||
|
home = "PANDORA_HOME=";
|
||||||
|
home += Pandora::getPandoraInstallDir ();
|
||||||
|
putenv(home.c_str());
|
||||||
|
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (_stricmp(argv[i], SERVICE_INSTALL_CMDLINE_PARAM) == 0) {
|
if (_stricmp(argv[i], SERVICE_INSTALL_CMDLINE_PARAM) == 0) {
|
||||||
|
|
|
@ -148,7 +148,7 @@ Pandora::Pandora_Agent_Conf::setFile (string *all_conf){
|
||||||
|
|
||||||
filename = Pandora::getPandoraInstallDir ();
|
filename = Pandora::getPandoraInstallDir ();
|
||||||
filename += "pandora_agent.conf";
|
filename += "pandora_agent.conf";
|
||||||
|
|
||||||
ifstream file (filename.c_str ());
|
ifstream file (filename.c_str ());
|
||||||
|
|
||||||
if (this->key_values)
|
if (this->key_values)
|
||||||
|
|
|
@ -116,7 +116,7 @@ Pandora_Windows_Service::start () {
|
||||||
|
|
||||||
void
|
void
|
||||||
Pandora_Windows_Service::pandora_init_broker (string file_conf) {
|
Pandora_Windows_Service::pandora_init_broker (string file_conf) {
|
||||||
string interval, debug, transfer_interval, util_dir, path, env;
|
string interval, debug, transfer_interval, util_dir, path, env, name_agent;
|
||||||
string udp_server_enabled, udp_server_port, udp_server_addr, udp_server_auth_addr;
|
string udp_server_enabled, udp_server_port, udp_server_addr, udp_server_auth_addr;
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
|
@ -128,6 +128,9 @@ Pandora_Windows_Service::pandora_init_broker (string file_conf) {
|
||||||
path = getenv ("PATH");
|
path = getenv ("PATH");
|
||||||
env = "PATH=" + path + ";" + util_dir;
|
env = "PATH=" + path + ";" + util_dir;
|
||||||
putenv (env.c_str ());
|
putenv (env.c_str ());
|
||||||
|
|
||||||
|
name_agent = "PANDORA_AGENT=" + checkAgentName(file_conf);
|
||||||
|
putenv(name_agent.c_str());
|
||||||
|
|
||||||
this->conf = Pandora::Pandora_Agent_Conf::getInstance ();
|
this->conf = Pandora::Pandora_Agent_Conf::getInstance ();
|
||||||
this->conf->setFile (file_conf);
|
this->conf->setFile (file_conf);
|
||||||
|
@ -202,8 +205,9 @@ void
|
||||||
Pandora_Windows_Service::pandora_init () {
|
Pandora_Windows_Service::pandora_init () {
|
||||||
string conf_file, interval, debug, transfer_interval, util_dir, path, env;
|
string conf_file, interval, debug, transfer_interval, util_dir, path, env;
|
||||||
string udp_server_enabled, udp_server_port, udp_server_addr, udp_server_auth_addr;
|
string udp_server_enabled, udp_server_port, udp_server_addr, udp_server_auth_addr;
|
||||||
|
string name_agent, name;
|
||||||
int pos, num;
|
int pos, num;
|
||||||
|
|
||||||
setPandoraDebug (true);
|
setPandoraDebug (true);
|
||||||
|
|
||||||
// Add the util subdirectory to the PATH
|
// Add the util subdirectory to the PATH
|
||||||
|
@ -212,10 +216,10 @@ Pandora_Windows_Service::pandora_init () {
|
||||||
path = getenv ("PATH");
|
path = getenv ("PATH");
|
||||||
env = "PATH=" + path + ";" + util_dir;
|
env = "PATH=" + path + ";" + util_dir;
|
||||||
putenv (env.c_str ());
|
putenv (env.c_str ());
|
||||||
|
|
||||||
conf_file = Pandora::getPandoraInstallDir ();
|
conf_file = Pandora::getPandoraInstallDir ();
|
||||||
conf_file += "pandora_agent.conf";
|
conf_file += "pandora_agent.conf";
|
||||||
|
|
||||||
num = count_broker_agents();
|
num = count_broker_agents();
|
||||||
string all_conf[num];
|
string all_conf[num];
|
||||||
|
|
||||||
|
@ -223,6 +227,13 @@ Pandora_Windows_Service::pandora_init () {
|
||||||
this->conf->setFile (all_conf);
|
this->conf->setFile (all_conf);
|
||||||
this->modules = new Pandora_Module_List (conf_file);
|
this->modules = new Pandora_Module_List (conf_file);
|
||||||
|
|
||||||
|
name = checkAgentName(conf_file);
|
||||||
|
if (name.empty ()) {
|
||||||
|
name = Pandora_Windows_Info::getSystemName ();
|
||||||
|
}
|
||||||
|
name_agent = "PANDORA_AGENT=" + name;
|
||||||
|
putenv(name_agent.c_str());
|
||||||
|
|
||||||
/* Get the interval value (in seconds) and set it to the service */
|
/* Get the interval value (in seconds) and set it to the service */
|
||||||
interval = conf->getValue ("interval");
|
interval = conf->getValue ("interval");
|
||||||
transfer_interval = conf->getValue ("transfer_interval");
|
transfer_interval = conf->getValue ("transfer_interval");
|
||||||
|
@ -979,6 +990,28 @@ Pandora_Windows_Service::checkCollections () {
|
||||||
purgeDiskCollections ();
|
purgeDiskCollections ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
Pandora_Windows_Service::checkAgentName(string filename){
|
||||||
|
string name_agent = "";
|
||||||
|
string buffer;
|
||||||
|
unsigned int pos;
|
||||||
|
ifstream file (filename.c_str ());
|
||||||
|
|
||||||
|
while (!file.eof ()) {
|
||||||
|
getline (file, buffer);
|
||||||
|
/* Ignore blank or commented lines */
|
||||||
|
if (buffer[0] != '#' && buffer[0] != '\n' && buffer[0] != '\0') {
|
||||||
|
/*Check agent_name*/
|
||||||
|
pos = buffer.find("agent_name");
|
||||||
|
if (pos != string::npos){
|
||||||
|
name_agent = buffer.substr(pos+11);
|
||||||
|
return name_agent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
return name_agent;
|
||||||
|
}
|
||||||
void
|
void
|
||||||
Pandora_Windows_Service::checkConfig (string file) {
|
Pandora_Windows_Service::checkConfig (string file) {
|
||||||
int i, conf_size;
|
int i, conf_size;
|
||||||
|
@ -999,12 +1032,12 @@ Pandora_Windows_Service::checkConfig (string file) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get agent name */
|
/* Get agent name */
|
||||||
tmp = conf->getValue ("agent_name");
|
tmp = checkAgentName(file);
|
||||||
if (tmp.empty ()) {
|
if (tmp.empty ()) {
|
||||||
tmp = Pandora_Windows_Info::getSystemName ();
|
tmp = Pandora_Windows_Info::getSystemName ();
|
||||||
}
|
}
|
||||||
agent_name = tmp;
|
agent_name = tmp;
|
||||||
|
|
||||||
/* Error getting agent name */
|
/* Error getting agent name */
|
||||||
if (tmp.empty ()) {
|
if (tmp.empty ()) {
|
||||||
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error getting agent name");
|
pandoraDebug ("Pandora_Windows_Service::checkConfig: Error getting agent name");
|
||||||
|
@ -1252,7 +1285,7 @@ Pandora_Windows_Service::pandora_run_broker (string config) {
|
||||||
conf = this->getConf ();
|
conf = this->getConf ();
|
||||||
|
|
||||||
/* Sleep if a startup delay was specified */
|
/* Sleep if a startup delay was specified */
|
||||||
startup_delay = atoi (conf->getValue ("startup_delay").c_str ()) * 1000;
|
startup_delay = atoi (conf->getValue ("startup_delay").c_str ()) * 1000;
|
||||||
if (startup_delay > 0 && delayed == 0) {
|
if (startup_delay > 0 && delayed == 0) {
|
||||||
delayed = 1;
|
delayed = 1;
|
||||||
pandoraLog ("Delaying startup %d miliseconds", startup_delay);
|
pandoraLog ("Delaying startup %d miliseconds", startup_delay);
|
||||||
|
@ -1305,10 +1338,10 @@ void
|
||||||
Pandora_Windows_Service::pandora_run () {
|
Pandora_Windows_Service::pandora_run () {
|
||||||
Pandora_Agent_Conf *conf = NULL;
|
Pandora_Agent_Conf *conf = NULL;
|
||||||
string server_addr, conf_file;
|
string server_addr, conf_file;
|
||||||
int startup_delay = 0;
|
int startup_delay = 0;
|
||||||
static unsigned char delayed = 0;
|
static unsigned char delayed = 0;
|
||||||
int exe = 1;
|
int exe = 1;
|
||||||
int i, num;
|
int i, num;
|
||||||
|
|
||||||
pandoraDebug ("Run begin");
|
pandoraDebug ("Run begin");
|
||||||
|
|
||||||
|
@ -1326,6 +1359,7 @@ Pandora_Windows_Service::pandora_run () {
|
||||||
if (getPandoraDebug () == false) {
|
if (getPandoraDebug () == false) {
|
||||||
conf_file = Pandora::getPandoraInstallDir ();
|
conf_file = Pandora::getPandoraInstallDir ();
|
||||||
conf_file += "pandora_agent.conf";
|
conf_file += "pandora_agent.conf";
|
||||||
|
|
||||||
this->checkConfig (conf_file);
|
this->checkConfig (conf_file);
|
||||||
this->checkCollections ();
|
this->checkCollections ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ namespace Pandora {
|
||||||
int unzipCollection(string zip_path, string dest_dir);
|
int unzipCollection(string zip_path, string dest_dir);
|
||||||
void checkCollections ();
|
void checkCollections ();
|
||||||
void addCollectionsPath();
|
void addCollectionsPath();
|
||||||
|
string checkAgentName(string filename);
|
||||||
void checkConfig (string file);
|
void checkConfig (string file);
|
||||||
void purgeDiskCollections ();
|
void purgeDiskCollections ();
|
||||||
void pandora_init_broker (string file_conf);
|
void pandora_init_broker (string file_conf);
|
||||||
|
|
Loading…
Reference in New Issue