From 9bce56beb398d1e300bc1393c184fbe3a39d6de5 Mon Sep 17 00:00:00 2001 From: David Hill Date: Tue, 23 Oct 2018 14:40:17 -0500 Subject: [PATCH] MCOL-520 --- oam/oamcpp/liboamcpp.cpp | 22 +++++++++++++--------- oamapps/postConfigure/postConfigure.cpp | 25 +++++++++++++++---------- procmgr/processmanager.cpp | 2 +- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/oam/oamcpp/liboamcpp.cpp b/oam/oamcpp/liboamcpp.cpp index cf8a15cde..ba40f9279 100644 --- a/oam/oamcpp/liboamcpp.cpp +++ b/oam/oamcpp/liboamcpp.cpp @@ -8798,14 +8798,18 @@ int Oam::glusterctl(GLUSTER_COMMANDS command, std::string argument1, std::string group = getgid(); string glustercmd = "gluster "; - - errmsg = ""; + + string SUDO = ""; + if ( user != "root" ) + SUDO = "sudo "; + + string errmsg = ""; switch ( command ) { case (oam::GLUSTER_STATUS): { - string command = glustercmd + "volume status"; + string command = SUDO + glustercmd + "volume status"; char buffer[128]; string result = ""; @@ -9010,7 +9014,7 @@ int Oam::glusterctl(GLUSTER_COMMANDS command, std::string argument1, std::string } sleep(5); - command = glustercmd + "peer status " + " >> " + tmpdir + "/glusterCommands.log 2>&1"; + command = SUDO + glustercmd + "peer status " + " >> " + tmpdir + "/glusterCommands.log 2>&1"; status = system(command.c_str()); if (WEXITSTATUS(status) != 0 ) @@ -9032,7 +9036,7 @@ int Oam::glusterctl(GLUSTER_COMMANDS command, std::string argument1, std::string { int newDbrootID = db + 1; - command = glustercmd + "volume create dbroot" + itoa(newDbrootID) + " transport tcp replica " + itoa(dataRedundancyCopies) + " "; + command = SUDO + glustercmd + "volume create dbroot" + itoa(newDbrootID) + " transport tcp replica " + itoa(dataRedundancyCopies) + " "; vector::iterator dbrootPmIter = dbrootPms[db].begin(); @@ -9074,7 +9078,7 @@ int Oam::glusterctl(GLUSTER_COMMANDS command, std::string argument1, std::string } } - command = glustercmd + "volume start dbroot" + itoa(newDbrootID) + " >> " + tmpdir + "/glusterCommands.log 2>&1"; + command = SUDO + glustercmd + "volume start dbroot" + itoa(newDbrootID) + " >> " + tmpdir + "/glusterCommands.log 2>&1"; status = system(command.c_str()); if (WEXITSTATUS(status) != 0 ) @@ -9121,7 +9125,7 @@ int Oam::glusterctl(GLUSTER_COMMANDS command, std::string argument1, std::string int status; writeLog("glusterctl: GLUSTER_DELETE: dbroot = " + dbrootID, LOG_TYPE_DEBUG ); - command = glustercmd + "--mode=script volume stop dbroot" + dbrootID + " >> " + tmpdir + "/glusterCommands.log 2>&1"; + command = SUDO + glustercmd + "--mode=script volume stop dbroot" + dbrootID + " >> " + tmpdir + "/glusterCommands.log 2>&1"; status = system(command.c_str()); @@ -9134,7 +9138,7 @@ int Oam::glusterctl(GLUSTER_COMMANDS command, std::string argument1, std::string // give time for transaction to finish after stopping sleep(10); - command = glustercmd + " --mode=script volume delete dbroot" + dbrootID + " >> " + tmpdir + "/glusterCommands.log 2>&1"; + command = SUDO + glustercmd + " --mode=script volume delete dbroot" + dbrootID + " >> " + tmpdir + "/glusterCommands.log 2>&1"; status = system(command.c_str()); @@ -9154,7 +9158,7 @@ int Oam::glusterctl(GLUSTER_COMMANDS command, std::string argument1, std::string string command = ""; int status; - command = glustercmd + "peer probe " + ipAddress + " >> " + tmpdir + "/glusterCommands.log 2>&1"; + command = SUDO + glustercmd + "peer probe " + ipAddress + " >> " + tmpdir + "/glusterCommands.log 2>&1"; cout << "gluster peer probe " + ipAddress << endl; status = system(command.c_str()); diff --git a/oamapps/postConfigure/postConfigure.cpp b/oamapps/postConfigure/postConfigure.cpp index a2f9a0df3..06e6bad36 100644 --- a/oamapps/postConfigure/postConfigure.cpp +++ b/oamapps/postConfigure/postConfigure.cpp @@ -198,13 +198,14 @@ string DataFileEnvFile; string installDir; string tmpDir; string HOME = "/root"; - +string SUDO = ""; extern string pwprompt; string mysqlpw = oam::UnassignedName; extern const char* pcommand; extern string prompt; + /* create thread argument struct for thr_func() */ typedef struct _thread_data_t { @@ -274,9 +275,13 @@ int main(int argc, char* argv[]) user = getuid(); usergroup = getgid(); - if (user != 0) + SUDO = "" + if (user != 0) { + rootUser = false; - + SUDO = "sudo "; + } + char* p = getenv("USER"); if (p && *p) @@ -5104,7 +5109,7 @@ bool storageSetup(bool amazonInstall) //check if gluster is installed int rtnCode = 1; - string cmd = "gluster --version > " + tmpDir + "/gluster.log 2>&1"; + string cmd = SUDO + "gluster --version > " + tmpDir + "/gluster.log 2>&1"; rtnCode = system(cmd.c_str()); if (rtnCode == 0) @@ -5515,7 +5520,7 @@ bool storageSetup(bool amazonInstall) // if gluster if ( storageType == "3" ) { - string command = "stat /var/run/glusterd.pid > /dev/null 2>&1"; + string command = SUDO + "stat /var/run/glusterd.pid > /dev/null 2>&1"; int status = system(command.c_str()); if (WEXITSTATUS(status) != 0 ) @@ -6704,7 +6709,7 @@ bool glusterSetup(string password) string glusterCommandsLog = tmpDir + "/glusterCommands.log"; - command = "gluster peer status " + glusterCommandsLog + "2>&1"; + command = SUDO + "gluster peer status " + glusterCommandsLog + "2>&1"; status = system(command.c_str()); @@ -6729,7 +6734,7 @@ bool glusterSetup(string password) { int dbrootID = db + 1; - command = "gluster volume create dbroot" + oam.itoa(dbrootID) + " transport tcp replica " + oam.itoa(dataRedundancyCopies) + " "; + command = SUDO + "gluster volume create dbroot" + oam.itoa(dbrootID) + " transport tcp replica " + oam.itoa(dataRedundancyCopies) + " "; vector::iterator dbrootPmIter = dbrootPms[db].begin(); @@ -6788,7 +6793,7 @@ bool glusterSetup(string password) { int user = getuid(); int group = getgid(); - command = "gluster volume set dbroot" + oam.itoa(dbrootID) + " storage.owner-uid " + oam.itoa(user) + " >> " + glusterCommandsLog + " 2>&1"; + command = SUDO + "gluster volume set dbroot" + oam.itoa(dbrootID) + " storage.owner-uid " + oam.itoa(user) + " >> " + glusterCommandsLog + " 2>&1"; status = system(command.c_str()); if (WEXITSTATUS(status) != 0 ) @@ -6797,7 +6802,7 @@ bool glusterSetup(string password) exit(1); } - command = "gluster volume set dbroot" + oam.itoa(dbrootID) + " storage.owner-gid " + oam.itoa(group) + " >> " + glusterCommandsLog + " 2>&1"; + command = SUDO + "gluster volume set dbroot" + oam.itoa(dbrootID) + " storage.owner-gid " + oam.itoa(group) + " >> " + glusterCommandsLog + " 2>&1"; status = system(command.c_str()); if (WEXITSTATUS(status) != 0 ) @@ -6806,7 +6811,7 @@ bool glusterSetup(string password) exit(1); } - command = "gluster volume start dbroot" + oam.itoa(dbrootID) + " >> " + glusterCommandsLog + " 2>&1"; + command = SUDO + "gluster volume start dbroot" + oam.itoa(dbrootID) + " >> " + glusterCommandsLog + " 2>&1"; status = system(command.c_str()); if (WEXITSTATUS(status) != 0 ) diff --git a/procmgr/processmanager.cpp b/procmgr/processmanager.cpp index b8385964f..11ed49fe3 100644 --- a/procmgr/processmanager.cpp +++ b/procmgr/processmanager.cpp @@ -1334,7 +1334,7 @@ void processMSG(messageqcpp::IOSocket* cfIos) //now stop local module processManager.stopModule(config.moduleName(), graceful, manualFlag ); - //run save.brm script + //run save brm script processManager.saveBRM(false); log.writeLog(__LINE__, "Stop System Completed Success", LOG_TYPE_INFO);