mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-12 09:17:41 +03:00
Merge branch 'feature-1683'
This commit is contained in:
commit
e68fe0202d
@ -58,7 +58,7 @@ public:
|
||||
* @param obj Callbackable obj to call if the query succeeds
|
||||
* @return 0 on success
|
||||
*/
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0);
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0, bool quiet=false);
|
||||
|
||||
/**
|
||||
* This function returns a legal SQL string that can be used in an SQL
|
||||
@ -143,7 +143,7 @@ public:
|
||||
|
||||
~MySqlDB(){};
|
||||
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0){return -1;};
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0, bool quiet=false){return -1;};
|
||||
|
||||
char * escape_str(const string& str){return 0;};
|
||||
|
||||
|
@ -341,7 +341,12 @@ public:
|
||||
/**
|
||||
* Starts all the modules and services for OpenNebula
|
||||
*/
|
||||
void start();
|
||||
void start(bool bootstrap_only=false);
|
||||
|
||||
/**
|
||||
* Initialize the database
|
||||
*/
|
||||
void bootstrap_db();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Configuration attributes (read from oned.conf)
|
||||
|
@ -37,10 +37,10 @@ public:
|
||||
* Performs a DB transaction
|
||||
* @param sql_cmd the SQL command
|
||||
* @param callbak function to execute on each data returned
|
||||
* @param arg to pass to the callback function
|
||||
* @param quiet True to log errors with DDEBUG level instead of ERROR
|
||||
* @return 0 on success
|
||||
*/
|
||||
virtual int exec(ostringstream& cmd, Callbackable* obj=0) = 0;
|
||||
virtual int exec(ostringstream& cmd, Callbackable* obj=0, bool quiet=false) = 0;
|
||||
|
||||
/**
|
||||
* This function returns a legal SQL string that can be used in an SQL
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
* @param arg to pass to the callback function
|
||||
* @return 0 on success
|
||||
*/
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0);
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0, bool quiet=false);
|
||||
|
||||
/**
|
||||
* This function returns a legal SQL string that can be used in an SQL
|
||||
@ -113,7 +113,7 @@ public:
|
||||
|
||||
~SqliteDB(){};
|
||||
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0){return -1;};
|
||||
int exec(ostringstream& cmd, Callbackable* obj=0, bool quiet=false){return -1;};
|
||||
|
||||
char * escape_str(const string& str){return 0;};
|
||||
|
||||
|
@ -79,7 +79,7 @@ if [ ! -d /var/lock/one ]; then
|
||||
fi
|
||||
|
||||
# Start the one daemon
|
||||
$ONED -f 2>&1 &
|
||||
$ONED -i 2>&1 &
|
||||
STARTED=$?
|
||||
CURPID=$!
|
||||
|
||||
@ -89,9 +89,10 @@ if [ $STARTED -ne 0 ]; then
|
||||
fi
|
||||
|
||||
# Give oned a chance to do it's thing...
|
||||
sleep 2
|
||||
sleep 5
|
||||
|
||||
# OK we're all done here
|
||||
# Just in case the process gets stuck, kill it
|
||||
kill -TERM $CURPID > /dev/null 2>&1
|
||||
|
||||
counter=0
|
||||
@ -105,4 +106,4 @@ while ps $CURPID > /dev/null 2>&1; do
|
||||
done
|
||||
|
||||
# If the lock file is left over remove it
|
||||
rm -f /var/lol/one/one
|
||||
rm -f /var/lock/one/one
|
||||
|
@ -128,7 +128,7 @@ int SystemDB::check_db_version()
|
||||
oss << "SELECT version FROM " << ver_table
|
||||
<< " WHERE oid=(SELECT MAX(oid) FROM " << ver_table << ")";
|
||||
|
||||
db->exec(oss, this);
|
||||
db->exec(oss, this, true);
|
||||
|
||||
oss.str("");
|
||||
unset_callback();
|
||||
@ -138,7 +138,7 @@ int SystemDB::check_db_version()
|
||||
// Table user_pool is present for all OpenNebula versions, and it
|
||||
// always contains at least the oneadmin user.
|
||||
oss << "SELECT MAX(oid) FROM user_pool";
|
||||
rc = db->exec(oss);
|
||||
rc = db->exec(oss, 0, true);
|
||||
|
||||
oss.str("");
|
||||
|
||||
@ -268,7 +268,15 @@ int SystemDB::select_sys_attribute(const string& attr_name, string& attr_xml)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void Nebula::start()
|
||||
void Nebula::bootstrap_db()
|
||||
{
|
||||
start(true);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void Nebula::start(bool bootstrap_only)
|
||||
{
|
||||
int rc;
|
||||
int fd;
|
||||
@ -376,7 +384,7 @@ void Nebula::start()
|
||||
xmlInitParser();
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Pools
|
||||
// Database
|
||||
// -----------------------------------------------------------
|
||||
try
|
||||
{
|
||||
@ -510,6 +518,19 @@ void Nebula::start()
|
||||
throw;
|
||||
}
|
||||
|
||||
if (bootstrap_only)
|
||||
{
|
||||
//XML Library
|
||||
xmlCleanupParser();
|
||||
|
||||
NebulaLog::log("ONE", Log::INFO, "Database bootstrap finalized, exiting.\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Pools
|
||||
// -----------------------------------------------------------
|
||||
try
|
||||
{
|
||||
int size;
|
||||
|
@ -32,9 +32,10 @@ static const char * usage =
|
||||
"SYNOPSIS\n"
|
||||
" Starts the OpenNebula daemon\n\n"
|
||||
"OPTIONS\n"
|
||||
"\t-h\tprints this help.\n"
|
||||
"\t-v\tprints OpenNebula version and license\n"
|
||||
"\t-f\tforeground, do not fork the oned daemon\n";
|
||||
"\t-h\tprints this help.\n"
|
||||
"\t-f\tforeground, do not fork the oned daemon\n"
|
||||
"\t-i\tinitialize the dabase and exit.\n";
|
||||
|
||||
static const char * susage =
|
||||
"usage: oned [-h] [-v] [-f]\n";
|
||||
@ -50,6 +51,24 @@ static void print_license()
|
||||
<< "(http://www.apache.org/licenses/LICENSE-2.0).\n";
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
static void oned_init()
|
||||
{
|
||||
try
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
nd.bootstrap_db();
|
||||
}
|
||||
catch (exception &e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -58,19 +77,19 @@ static void oned_main()
|
||||
try
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
nd.start();
|
||||
nd.start();
|
||||
}
|
||||
catch (exception &e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int opt;
|
||||
@ -80,8 +99,8 @@ int main(int argc, char **argv)
|
||||
pid_t pid,sid;
|
||||
string wd;
|
||||
int rc;
|
||||
|
||||
while((opt = getopt(argc,argv,"vhf")) != -1)
|
||||
|
||||
while((opt = getopt(argc,argv,"vhif")) != -1)
|
||||
switch(opt)
|
||||
{
|
||||
case 'v':
|
||||
@ -92,9 +111,13 @@ int main(int argc, char **argv)
|
||||
cout << usage;
|
||||
exit(0);
|
||||
break;
|
||||
case 'i':
|
||||
oned_init();
|
||||
exit(0);
|
||||
break;
|
||||
case 'f':
|
||||
foreground = true;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
cerr << susage;
|
||||
exit(-1);
|
||||
@ -102,24 +125,24 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
// ---------------------------------
|
||||
// Check if other oned is running
|
||||
// ---------------------------------
|
||||
|
||||
// Check if other oned is running
|
||||
// ---------------------------------
|
||||
|
||||
string lockfile;
|
||||
string var_location;
|
||||
|
||||
|
||||
nl = getenv("ONE_LOCATION");
|
||||
|
||||
if (nl == 0) // OpenNebula in root of FSH
|
||||
{
|
||||
var_location = "/var/lib/one/";
|
||||
var_location = "/var/lib/one/";
|
||||
lockfile = "/var/lock/one/one";
|
||||
}
|
||||
else
|
||||
{
|
||||
var_location = nl;
|
||||
var_location += "/var/";
|
||||
|
||||
|
||||
lockfile = var_location + ".lock";
|
||||
}
|
||||
|
||||
@ -127,70 +150,70 @@ int main(int argc, char **argv)
|
||||
|
||||
if( fd == -1)
|
||||
{
|
||||
cerr<< "Error: Cannot start oned, opening lock file " << lockfile
|
||||
cerr<< "Error: Cannot start oned, opening lock file " << lockfile
|
||||
<< endl;
|
||||
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
// ----------------------------
|
||||
// Fork & exit main process
|
||||
// ----------------------------
|
||||
|
||||
|
||||
// ----------------------------
|
||||
// Fork & exit main process
|
||||
// ----------------------------
|
||||
|
||||
if (foreground == true)
|
||||
{
|
||||
pid = 0; //Do not fork
|
||||
}
|
||||
else
|
||||
{
|
||||
pid = fork();
|
||||
pid = fork();
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch (pid){
|
||||
case -1: // Error
|
||||
cerr << "Error: Unable to fork.\n";
|
||||
cerr << "Error: Unable to fork.\n";
|
||||
exit(-1);
|
||||
|
||||
|
||||
|
||||
case 0: // Child process
|
||||
|
||||
|
||||
rc = chdir(var_location.c_str());
|
||||
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
goto error_chdir;
|
||||
}
|
||||
|
||||
|
||||
if (foreground == false)
|
||||
{
|
||||
{
|
||||
sid = setsid();
|
||||
|
||||
|
||||
if (sid == -1)
|
||||
{
|
||||
goto error_sid;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
oned_main();
|
||||
|
||||
unlink(lockfile.c_str());
|
||||
|
||||
unlink(lockfile.c_str());
|
||||
break;
|
||||
|
||||
default: // Parent process
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
error_chdir:
|
||||
cerr << "Error: cannot change to dir " << wd << "\n";
|
||||
unlink(lockfile.c_str());
|
||||
exit(-1);
|
||||
|
||||
error_sid:
|
||||
error_sid:
|
||||
cerr << "Error: creating new session\n";
|
||||
unlink(lockfile.c_str());
|
||||
exit(-1);
|
||||
|
@ -132,7 +132,7 @@ MySqlDB::~MySqlDB()
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int MySqlDB::exec(ostringstream& cmd, Callbackable* obj)
|
||||
int MySqlDB::exec(ostringstream& cmd, Callbackable* obj, bool quiet)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@ -142,6 +142,8 @@ int MySqlDB::exec(ostringstream& cmd, Callbackable* obj)
|
||||
str = cmd.str();
|
||||
c_str = str.c_str();
|
||||
|
||||
Log::MessageType error_level = quiet ? Log::DDEBUG : Log::ERROR;
|
||||
|
||||
MYSQL *db;
|
||||
|
||||
db = get_db_connection();
|
||||
@ -176,7 +178,7 @@ int MySqlDB::exec(ostringstream& cmd, Callbackable* obj)
|
||||
oss << ", error " << err_num << " : " << err_msg;
|
||||
}
|
||||
|
||||
NebulaLog::log("ONE",Log::ERROR,oss);
|
||||
NebulaLog::log("ONE",error_level,oss);
|
||||
|
||||
free_db_connection(db);
|
||||
|
||||
@ -204,7 +206,7 @@ int MySqlDB::exec(ostringstream& cmd, Callbackable* obj)
|
||||
oss << "SQL command was: " << c_str;
|
||||
oss << ", error " << err_num << " : " << err_msg;
|
||||
|
||||
NebulaLog::log("ONE",Log::ERROR,oss);
|
||||
NebulaLog::log("ONE",error_level,oss);
|
||||
|
||||
free_db_connection(db);
|
||||
|
||||
|
@ -66,7 +66,7 @@ SqliteDB::~SqliteDB()
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int SqliteDB::exec(ostringstream& cmd, Callbackable* obj)
|
||||
int SqliteDB::exec(ostringstream& cmd, Callbackable* obj, bool quiet)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@ -119,10 +119,12 @@ int SqliteDB::exec(ostringstream& cmd, Callbackable* obj)
|
||||
{
|
||||
if (err_msg != 0)
|
||||
{
|
||||
Log::MessageType error_level = quiet ? Log::DDEBUG : Log::ERROR;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
oss << "SQL command was: " << c_str << ", error: " << err_msg;
|
||||
NebulaLog::log("ONE",Log::ERROR,oss);
|
||||
NebulaLog::log("ONE",error_level,oss);
|
||||
|
||||
sqlite3_free(err_msg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user