From 5d479620a454800ae50ffd384d3b0b64b16040c7 Mon Sep 17 00:00:00 2001 From: immarvin Date: Mon, 9 Jun 2014 06:40:14 -0700 Subject: [PATCH 1/3] repleace the servcie stuff with newly added generic subroutines in xcat-client --- perl-xCAT/xCAT/Utils.pm | 4 +++ xCAT-client/bin/db2sqlsetup | 56 ++++++++++++++++++++++---------- xCAT-client/bin/mysqlsetup | 44 +++++++++++++++---------- xCAT-client/bin/pgsqlsetup | 65 ++++++++++++++++++++++++------------- 4 files changed, 111 insertions(+), 58 deletions(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index abc69b137..3a5b23db1 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -3613,6 +3613,10 @@ sub servicemap{ 0=>["ntpd","ntp"], 1=>["ntpd.service"], }, + "mysql" => { + 0=>["mysqld","mysql"], + 1=>["mysqld.service"], + }, ); my $path=undef; diff --git a/xCAT-client/bin/db2sqlsetup b/xCAT-client/bin/db2sqlsetup index fe765ffcd..ef8e5f219 100755 --- a/xCAT-client/bin/db2sqlsetup +++ b/xCAT-client/bin/db2sqlsetup @@ -590,13 +590,16 @@ sub startxcatd } else { $xcmd = "$::XCATROOT/sbin/restartxcatd"; } + system($xcmd); } else { - $xcmd = "service xcatd restart"; + #$xcmd = "service xcatd restart"; + my $ret=xCAT::Utils->restartservice("xcatd"); + return $ret; } - system($xcmd); + } #----------------------------------------------------------------------------- @@ -618,13 +621,16 @@ sub shutdownxcatd if ($::osname eq 'AIX') { $xcmd = "stopsrc -s xcatd"; + system($xcmd); } else { - $xcmd = "service xcatd stop"; + #$xcmd = "service xcatd stop"; + my $ret=xCAT::Utils->stopservice("xcatd"); + return $ret; } - system($xcmd); + } #----------------------------------------------------------------------------- @@ -2073,11 +2079,12 @@ sub adddb2paths #----------------------------------------------------------------------------- sub remove { - my $cmd; - my @output; - my $error = 0; - #see if DB2 is installed - if (!(-e ($::installdb2dir))) + my $cmd; + my @output; + my $error = 0; + my $retcode=0; + #see if DB2 is installed + if (!(-e ($::installdb2dir))) { my $message = "\nDB2 is not installed."; @@ -2120,18 +2127,23 @@ sub remove my $cmd = "ps -elf|grep xcatd"; my @output = xCAT::Utils->runcmd($cmd, 0); + if ($::RUNCMD_RC == 0) { if ($::osname eq 'AIX') { my $cmd = "startsrc -s xcatd"; + xCAT::Utils->runcmd($cmd, -1); + $retcode=$::RUNCMD_RC; } else { - my $cmd = "service xcatd start"; + #my $cmd = "service xcatd start"; + $retcode=xCAT::Utils->startservice("xcatd"); } - xCAT::Utils->runcmd($cmd, -1); - if ($::RUNCMD_RC !=0) + #xCAT::Utils->runcmd($cmd, -1); + #if ($::RUNCMD_RC !=0) + if($retcode!=0) { my $message = "can't start xcatd"; $error += 1; @@ -2155,13 +2167,17 @@ sub remove if ($::osname eq 'AIX') { my $cmd = "stopsrc -s xcatd"; + xCAT::Utils->runcmd($cmd, -1); + $retcode=$::RUNCMD_RC; } else { - my $cmd = "service xcatd stop"; + #my $cmd = "service xcatd stop"; + $retcode=xCAT::Utils->stopservice("xcatd"); } - xCAT::Utils->runcmd($cmd, -1); - if ($::RUNCMD_RC !=0) + #xCAT::Utils->runcmd($cmd, -1); + #if ($::RUNCMD_RC !=0) + if($retcode!=0) { my $message = "can't stop xcatd"; xCAT::MsgUtils->message("E", "$message"); @@ -2198,13 +2214,17 @@ sub remove if ($::osname eq 'AIX') { my $cmd = "startsrc -s xcatd"; + xCAT::Utils->runcmd($cmd, -1); + $retcode=$::RUNCMD_RC; } else { - my $cmd = "service xcatd start"; + #my $cmd = "service xcatd start"; + $retcode=xCAT::Utils->startservice("xcatd"); } - xCAT::Utils->runcmd($cmd, -1); - if ($::RUNCMD_RC !=0) + #xCAT::Utils->runcmd($cmd, -1); + #if ($::RUNCMD_RC !=0) + if($retcode!=0) { my $message = "can't start xcatd"; xCAT::MsgUtils->message("E", "$message"); diff --git a/xCAT-client/bin/mysqlsetup b/xCAT-client/bin/mysqlsetup index a0e020abe..5c78f2fd4 100755 --- a/xCAT-client/bin/mysqlsetup +++ b/xCAT-client/bin/mysqlsetup @@ -608,13 +608,16 @@ sub shutdownxcatd if ($::osname eq 'AIX') { $xcmd = "stopsrc -s xcatd"; + system($xcmd); } else { - $xcmd = "service xcatd stop"; + #$xcmd = "service xcatd stop"; + my $ret=xCAT::Utils->stopservice("xcatd"); + return $ret; } - system($xcmd); + } #----------------------------------------------------------------------------- @@ -861,6 +864,7 @@ sub initmysqldb sub mysqlstart { my $cmd; + my $ret=0; if ($::osname eq 'AIX') { my $hostname = `hostname`; @@ -872,28 +876,32 @@ sub mysqlstart $cmd = $cmd2; $cmd .= "$::installdir/bin/mysqld --user=mysql --basedir=$::installdir --datadir=/var/lib/mysql --user=mysql --log-error=/var/lib/mysql/$hostname.err --pid-file=/var/lib/mysql/$hostname.pid --socket=/tmp/mysql.sock --port=3306 &"; + $ret=xCAT::Utils->runcmd($cmd, 0); + + } else { if ($::MariaDB==1) { # running MariaDB - $cmd = "service mariadb start"; + #$cmd = "service mariadb start"; + $ret=xCAT::Utils->startservice("mariadb"); } else { # it is mysql - if ($::linuxos =~ /rh.*/) - { - $cmd = "service mysqld start"; - } - else - { # sles - $cmd = "service mysql start"; - } + #if ($::linuxos =~ /rh.*/) + #{ + # $cmd = "service mysqld start"; + #} + #else + #{ # sles + # $cmd = "service mysql start"; + #} + $ret=xCAT::Utils->startservice("mysql"); } } - xCAT::Utils->runcmd($cmd, 0); - if ($::RUNCMD_RC != 0) + if ($ret != 0) { - xCAT::MsgUtils->message("E", " $cmd failed."); + xCAT::MsgUtils->message("E", " failed to start mysql/mariadb."); exit(1); } @@ -1809,12 +1817,14 @@ sub restorexcatdb if ($::osname eq 'AIX') { $xcmd = "$::XCATROOT/sbin/restartxcatd"; - + system($xcmd); } else { - $xcmd = "service xcatd restart"; + #$xcmd = "service xcatd restart"; + my $ret=xCAT::Utils->restartservie("xcatd"); + return $ret; } - system($xcmd); + } diff --git a/xCAT-client/bin/pgsqlsetup b/xCAT-client/bin/pgsqlsetup index 9731c6973..94db9a888 100755 --- a/xCAT-client/bin/pgsqlsetup +++ b/xCAT-client/bin/pgsqlsetup @@ -444,13 +444,16 @@ sub shutdownxcatd if ($::osname eq 'AIX') { $xcmd = "stopsrc -s xcatd"; + system($xcmd); } else { - $xcmd = "service xcatd stop"; + # $xcmd = "service xcatd stop"; + my $ret=xCAT::Utils->stopservice("xcatd"); + return $ret; } - system($xcmd); + } #----------------------------------------------------------------------------- @@ -832,6 +835,7 @@ sub initpgdb sub pgstart { my $cmd; + my $ret=0; xCAT::MsgUtils->message("I", "Starting the PosgreSQL Server"); if ($::osname eq 'AIX') { @@ -843,27 +847,35 @@ sub pgstart else # linux { if (defined($::postgres9)) { # set to the PTF level of postgresql 9.X - $cmd = "service postgresql-9.$::postgres9 start"; + #$cmd = "service postgresql-9.$::postgres9 start"; + $cmd = "postgresql-9.$::postgres9"; } else { - $cmd = "service postgresql start"; + #$cmd = "service postgresql start"; + $cmd = "postgresql"; } - system($cmd); - if ($? > 0) { - xCAT::MsgUtils->message("E", " $cmd failed."); + #system($cmd) + #if ($? > 0) { + $ret=xCAT::Utils->startservice($cmd); + if ($ret != 0) { + xCAT::MsgUtils->message("E", " failed to start $cmd."); exit(1); } # check to see if running before continuing my $retries =0; my $pgstarted =0; - if (defined($::postgres9)) { # set to the PTF level of postgresql 9.X - $cmd = "service postgresql-9.$::postgres9 status"; - } else { - $cmd = "service postgresql status"; - } + #if (defined($::postgres9)) { # set to the PTF level of postgresql 9.X + # #$cmd = "service postgresql-9.$::postgres9 status"; + # $ret=xCAT::Utils->checkservicestatus("postgresql-9.$::postgres9"); + #} else { + # #$cmd = "service postgresql status"; + # $ret=xCAT::Utils->checkservicestatus("postgresql"); + #} while ($retries < 30) { $retries++; - my @status=xCAT::Utils->runcmd($cmd, -1); - if (grep(/[r|R]unning/, @status)) { + #my @status=xCAT::Utils->runcmd($cmd, -1); + #if (grep(/[r|R]unning/, @status)) { + $ret=xCAT::Utils->checkservicestatus($cmd); + if($ret == 0){ $pgstarted=1; last; } @@ -903,15 +915,19 @@ sub pgreboot else # linux { if (defined($::postgres9)) { # set to the postgresql ptf level - $cmd = "chkconfig postgresql-9.$::postgres9 on"; + # $cmd = "chkconfig postgresql-9.$::postgres9 on"; + $cmd = "postgresql-9.$::postgres9"; } else { - $cmd = "chkconfig postgresql on"; + #$cmd = "chkconfig postgresql on"; + $cmd = "postgresql"; } - if ($debianflag){ - $cmd = "update-rc.d postgresql defaults"; - } - xCAT::Utils->runcmd($cmd, 0); - if ($::RUNCMD_RC != 0) + #if ($debianflag){ + #$cmd = "update-rc.d postgresql defaults"; + #} + #xCAT::Utils->runcmd($cmd, 0); + #if ($::RUNCMD_RC != 0) + my $ret=xCAT::Utils->enableservice($cmd); + if($cmd !=0 ) { xCAT::MsgUtils->message("E", " $cmd failed. PostgreSQL will not restart on reboot."); @@ -1347,12 +1363,15 @@ sub restorexcatdb if ($::osname eq 'AIX') { $xcmd = "startsrc -s xcatd"; + system($xcmd); } else { - $xcmd = "service xcatd start"; + #$xcmd = "service xcatd start"; + my $ret=xCAT::Utils->startservice("xcatd"); + return $ret; } - system($xcmd); + } From fbce828647defd9976a2d957b4e3ec96179142b4 Mon Sep 17 00:00:00 2001 From: immarvin Date: Mon, 9 Jun 2014 06:52:07 -0700 Subject: [PATCH 2/3] correct the message --- xCAT-client/bin/pgsqlsetup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT-client/bin/pgsqlsetup b/xCAT-client/bin/pgsqlsetup index 94db9a888..5624f65f7 100755 --- a/xCAT-client/bin/pgsqlsetup +++ b/xCAT-client/bin/pgsqlsetup @@ -930,7 +930,7 @@ sub pgreboot if($cmd !=0 ) { xCAT::MsgUtils->message("E", - " $cmd failed. PostgreSQL will not restart on reboot."); + "enable service $cmd failed. PostgreSQL will not restart on reboot."); } } From 539feaca289e84f3d5cd616a11fddc8c3927f9c0 Mon Sep 17 00:00:00 2001 From: immarvin Date: Mon, 9 Jun 2014 08:58:56 -0700 Subject: [PATCH 3/3] add systemctl support for xCAT-sn --- xCATsn/xCATsn.spec | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/xCATsn/xCATsn.spec b/xCATsn/xCATsn.spec index 0fd02f9f0..ecc449369 100644 --- a/xCATsn/xCATsn.spec +++ b/xCATsn/xCATsn.spec @@ -179,14 +179,17 @@ fi %ifos linux if [ -e "/etc/redhat-release" ]; then apachedaemon='httpd' + apacheserviceunit='httpd.service' else # SuSE apachedaemon='apache2' fi # start xcatd on linux - chkconfig $apachedaemon on +[ -e "/etc/init.d/$apachedaemon" ] && chkconfig $apachedaemon on +[ -e "/usr/lib/systemd/system/$apacheserviceunit" ] && systemctl enable $apacheserviceunit if [ -f "/proc/cmdline" ]; then # prevent running it during install into chroot image - XCATROOT=$RPM_INSTALL_PREFIX0 /etc/init.d/xcatd restart - /etc/init.d/$apachedaemon reload + XCATROOT=$RPM_INSTALL_PREFIX0 /etc/init.d/xcatd restart + [ -e "/etc/init.d/$apachedaemon" ] && /etc/init.d/$apachedaemon reload + [ -e "/usr/lib/systemd/system/$apacheserviceunit" ] && systemctl reload $apacheserviceunit fi echo "xCATsn is now installed" %else