From 7df731a3a6e204aae150cc1d0207968264757b7d Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Tue, 4 Feb 2020 14:16:49 +0000 Subject: [PATCH] Make mysqld work without systemd ColumnStore should now start/stop mysqld where the systemd service is not available. --- .../columnstore-pre-uninstall.in | 9 ++- oam/install_scripts/columnstore.in | 8 ++- oam/install_scripts/post-mysql-install | 40 +++++++++++-- oam/oamcpp/liboamcpp.cpp | 56 ++++++++++++++++--- procmon/processmonitor.cpp | 13 ++++- 5 files changed, 109 insertions(+), 17 deletions(-) diff --git a/oam/install_scripts/columnstore-pre-uninstall.in b/oam/install_scripts/columnstore-pre-uninstall.in index 6c549a677..41896c937 100755 --- a/oam/install_scripts/columnstore-pre-uninstall.in +++ b/oam/install_scripts/columnstore-pre-uninstall.in @@ -25,7 +25,14 @@ done #stop services columnstore stop > /dev/null 2>&1 -systemctl stop mariadb.service > /dev/null 2>&1 + +# Test we are using systemd +systemctl cat mariadb.service > /dev/null 2>&1 +if [ $? -eq 0 ]; then + systemctl stop mariadb.service > /dev/null 2>&1 +else + pkill mysqld +fi cloud=`mcsGetConfig Installation Cloud` if [ $cloud = "amazon-ec2" ] || [ $cloud = "amazon-vpc" ]; then diff --git a/oam/install_scripts/columnstore.in b/oam/install_scripts/columnstore.in index 4e4383f93..fc0d952bc 100644 --- a/oam/install_scripts/columnstore.in +++ b/oam/install_scripts/columnstore.in @@ -90,7 +90,13 @@ stop() { RETVAL=$? rm -f $lockdir/columnstore fuser -k 8604/tcp > /dev/null 2>&1 - systemctl stop mariadb.service > /dev/null 2>&1 + # Test we are using systemd + systemctl cat mariadb.service > /dev/null 2>&1 + if [ $? -eq 0 ]; then + systemctl stop mariadb.service > /dev/null 2>&1 + else + pkill mysqld + fi pkill ProcMon pkill ProcMgr return $RETVAL diff --git a/oam/install_scripts/post-mysql-install b/oam/install_scripts/post-mysql-install index 2566e39b3..81808c5da 100755 --- a/oam/install_scripts/post-mysql-install +++ b/oam/install_scripts/post-mysql-install @@ -11,7 +11,13 @@ checkForError() { if [ `cat ${tmpdir}/error.check | wc -c` -ne 0 ]; then echo "MySQL Password file missing or incorrect, check .my.cnf file" rm -f ${tmpdir}/error.check - systemctl stop mysqld.service + # Test we are using systemd + systemctl cat mariadb.service > /dev/null 2>&1 + if [ $? -eq 0 ]; then + systemctl stop mariadb.service > /dev/null 2>&1 + else + pkill mysqld + fi sleep 2 exit 2; fi @@ -54,10 +60,22 @@ for arg in "$@"; do done # Restart in the same way that mysqld will be started normally. -systemctl stop mariadb.service >/dev/null 2>&1 +# Test we are using systemd +systemctl cat mariadb.service > /dev/null 2>&1 +if [ $? -eq 0 ]; then + systemctl stop mariadb.service > /dev/null 2>&1 +else + pkill mysqld +fi sleep 2 export MYSQL_OPTS="--skip-grant-tables" -systemctl start mariadb.service +# Test we are using systemd +systemctl cat mariadb.service > /dev/null 2>&1 +if [ $? -eq 0 ]; then + systemctl start mariadb.service +else + /usr/bin/mysqld_safe --skip-grant-tables & +fi unset MYSQL_OPTS sleep 5 @@ -67,12 +85,24 @@ install_mcs_mysql.sh --tmpdir=$tmpdir checkForError if [ $? -ne 0 ]; then echo "ERROR: Invalid password in .my.cnf, or Columnstore plugin install missing" - systemctl stop mariadb.service + # Test we are using systemd + systemctl cat mariadb.service > /dev/null 2>&1 + if [ $? -eq 0 ]; then + systemctl stop mariadb.service > /dev/null 2>&1 + else + pkill mysqld + fi sleep 2 exit 2; fi -systemctl stop mariadb.service +# Test we are using systemd +systemctl cat mariadb.service > /dev/null 2>&1 +if [ $? -eq 0 ]; then + systemctl stop mariadb.service > /dev/null 2>&1 +else + pkill mysqld +fi exit 0 diff --git a/oam/oamcpp/liboamcpp.cpp b/oam/oamcpp/liboamcpp.cpp index 48205af38..4cfbc3d70 100644 --- a/oam/oamcpp/liboamcpp.cpp +++ b/oam/oamcpp/liboamcpp.cpp @@ -7796,16 +7796,26 @@ void Oam::actionMysqlCalpont(MYSQLCALPONT_ACTION action) string pidtmp = tmpdir + "/mysql.pid"; + int no_systemd = system("systemctl cat mariadb.server > /dev/null 2>&1"); + switch (action) { case MYSQL_START: { + if (no_systemd) + { + system("/usr/bin/mysqld_safe &"); + } command = "start"; break; } case MYSQL_STOP: { + if (no_systemd) + { + system("pkill mysqld"); + } command = "stop"; //set process status @@ -7821,18 +7831,31 @@ void Oam::actionMysqlCalpont(MYSQLCALPONT_ACTION action) case MYSQL_RESTART: { + if (no_systemd) + { + system("pkill mysqld"); + system("/usr/bin/mysqld_safe &"); + } command = "restart"; break; } case MYSQL_RELOAD: { + if (no_systemd) + { + system("pkill -HUP mysqld"); + } command = "reload"; break; } case MYSQL_FORCE_RELOAD: { + if (no_systemd) + { + system("pkill -HUP mysqld"); + } command = "force-reload"; break; } @@ -7851,19 +7874,36 @@ void Oam::actionMysqlCalpont(MYSQLCALPONT_ACTION action) } //RUN COMMAND - string cmd = mysqlscript + " " + command + " mariadb.service > " + tmpdir + "/actionMysqlCalpont.log 2>&1"; - system(cmd.c_str()); + if (!no_systemd) + { + string cmd = mysqlscript + " " + command + " mariadb.service > " + tmpdir + "/actionMysqlCalpont.log 2>&1"; + system(cmd.c_str()); + } if (action == MYSQL_START || action == MYSQL_RESTART) { - //get pid - char buf[512]; - FILE *cmd_pipe = popen("pidof -s mysqld", "r"); + pid_t pid = 0; + // Loop check because we mysqld may not start immediately + for (int i=0; i < 10; i++) + { + //get pid + char buf[512]; + FILE *cmd_pipe = popen("pidof -s mysqld", "r"); - fgets(buf, 512, cmd_pipe); - pid_t pid = strtoul(buf, NULL, 10); + fgets(buf, 512, cmd_pipe); + pid = strtoul(buf, NULL, 10); - pclose( cmd_pipe ); + pclose( cmd_pipe ); + + if (pid) + { + break; + } + else + { + sleep(2); + } + } if (!pid) { diff --git a/procmon/processmonitor.cpp b/procmon/processmonitor.cpp index 53930a7a8..e2da321ee 100644 --- a/procmon/processmonitor.cpp +++ b/procmon/processmonitor.cpp @@ -1514,8 +1514,17 @@ void ProcessMonitor::processMessage(messageqcpp::ByteStream msg, messageqcpp::IO system(cmd.c_str()); cmd = "post-mysql-install >> " + tmpLogDir + "/rpminstall"; system(cmd.c_str()); - cmd = "systemctl start mariadb.service > " + tmpLogDir + "/mysqldstart"; - system(cmd.c_str()); + int ret = system("systemctl cat mariadb.service > /dev/null 2>&1"); + if (!ret) + { + cmd = "systemctl start mariadb.service > " + tmpLogDir + "/mysqldstart"; + system(cmd.c_str()); + } + else + { + cmd = "/usr/bin/mysqld_safe & > " + tmpLogDir + "/mysqldstart"; + system(cmd.c_str()); + } string tmpFile = tmpLogDir + "/mysqldstart"; ifstream file (tmpFile.c_str());