From 87afa435a38d982aef7fcc0a90a589ed5cab7fa7 Mon Sep 17 00:00:00 2001 From: immarvin Date: Sun, 8 Jun 2014 08:23:10 -0700 Subject: [PATCH] replace the service stuff with new added generic routines --- perl-xCAT/xCAT/Utils.pm | 4 + xCAT-server/sbin/xcatconfig | 232 ++++++++++++++++++++---------------- 2 files changed, 130 insertions(+), 106 deletions(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 69df29fca..abc69b137 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -3609,6 +3609,10 @@ sub servicemap{ 0=>["apache2","httpd"], 1=>["httpd.service"], }, + "ntpserver" => { + 0=>["ntpd","ntp"], + 1=>["ntpd.service"], + }, ); my $path=undef; diff --git a/xCAT-server/sbin/xcatconfig b/xCAT-server/sbin/xcatconfig index b55d916bb..2abb7f7fe 100755 --- a/xCAT-server/sbin/xcatconfig +++ b/xCAT-server/sbin/xcatconfig @@ -505,66 +505,74 @@ if ($::INITIALINSTALL || $::FORCE) xCAT::MsgUtils->message('E', "Failed to update /etc/ntp.conf"); } - my $ntpserv; - if (-f "/etc/redhat-release") - { - $ntpserv = "ntpd"; - } - else - { - $ntpserv = "ntp"; - } - $cmd = "service $ntpserv restart"; - $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) + #my $ntpserv; + #if (-f "/etc/redhat-release") + #{ + # $ntpserv = "ntpd"; + #} + #else + #{ + # $ntpserv = "ntp"; + #} + #$cmd = "service $ntpserv restart"; + #$outref = xCAT::Utils->runcmd("$cmd", 0); + #if ($::RUNCMD_RC != 0) + my $ret=xCAT::Utils->restartservice("ntpserver"); + if($ret !=0) { xCAT::MsgUtils->message('E', "Failed to start ntp service"); } - if (-f "/sbin/chkconfig") - { - $cmd = "chkconfig $ntpserv on"; - $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) + #if (-f "/sbin/chkconfig") + #{ + # $cmd = "chkconfig $ntpserv on"; + # $outref = xCAT::Utils->runcmd("$cmd", 0); + $ret=xCAT::Utils->enableservice("ntpserver"); + # if ($::RUNCMD_RC != 0) + if($ret!=0) { xCAT::MsgUtils->message('E', "Failed to enable ntp service on every boot"); } - } + #} } # Disable firewall - my $fwserv; - if(-f "/etc/SuSE-release") - { - $fwserv = "SuSEfirewall2_setup"; - } - elsif(-f "/etc/redhat-release") - { - $fwserv = "iptables"; - if( -f "/usr/sbin/firewalld" ) - { - $fwserv = "firewalld"; - } - } - else - { - #Ubuntu: FIXME - } + #my $fwserv; + #if(-f "/etc/SuSE-release") + #{ + # $fwserv = "SuSEfirewall2_setup"; + #} + #elsif(-f "/etc/redhat-release") + #{ + # $fwserv = "iptables"; + # if( -f "/usr/sbin/firewalld" ) + # { + # $fwserv = "firewalld"; + # } + #} + #else + #{ + # #Ubuntu: FIXME + #} - if($fwserv) - { - my $cmd = "service $fwserv stop"; - my $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) + #if($fwserv) + #{ + # my $cmd = "service $fwserv stop"; + # my $outref = xCAT::Utils->runcmd("$cmd", 0); + # if ($::RUNCMD_RC != 0) + my $ret=xCAT::Utils->stopservice("firewall"); + if($ret!=0) { xCAT::MsgUtils->message('E', "Failed to stop firewall"); } - $cmd = "chkconfig $fwserv off"; - $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) + # $cmd = "chkconfig $fwserv off"; + # $outref = xCAT::Utils->runcmd("$cmd", 0); + # if ($::RUNCMD_RC != 0) + $ret=xCAT::Utils->disableservice("firewall"); + if($ret!=0) { xCAT::MsgUtils->message('E', "Failed to disable firewall on boot"); } - } + #} # Enable ip forwarding. In most cases, # the MN itself will act as the default gateway for the compute nodes, @@ -1781,16 +1789,18 @@ sub setupLinuxexports { # restart nfs - my $cmd; - my $os = xCAT::Utils->osver(); - my $SERVICE = xCAT::Utils->fullpathbin("service"); - if ($os =~ /sles/) { - $cmd = "$SERVICE nfsserver restart"; - } else { - $cmd = "$SERVICE nfs restart"; - } - my $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) + # my $cmd; + # my $os = xCAT::Utils->osver(); + # my $SERVICE = xCAT::Utils->fullpathbin("service"); + # if ($os =~ /sles/) { + # $cmd = "$SERVICE nfsserver restart"; + # } else { + # $cmd = "$SERVICE nfs restart"; + # } + # my $outref = xCAT::Utils->runcmd("$cmd", 0); + # if ($::RUNCMD_RC != 0) + my $ret=xCAT::Utils->restartservice("nfs"); + if($ret!=0) { xCAT::MsgUtils->message('E', "Could not restart NFS."); } @@ -1799,14 +1809,18 @@ sub setupLinuxexports xCAT::MsgUtils->message('I', "NFS has been restarted."); } - my $CHKCONFIG=xCAT::Utils->fullpathbin("chkconfig"); - if ($os =~ /sles/) { - $cmd = "$CHKCONFIG nfsserver on"; - } else { - $cmd = "$CHKCONFIG nfs on"; - } - $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) + #my $CHKCONFIG=xCAT::Utils->fullpathbin("chkconfig"); + #if ($os =~ /sles/) { + # $cmd = "$CHKCONFIG nfsserver on"; + #} else { + # $cmd = "$CHKCONFIG nfs on"; + #} + #$outref = xCAT::Utils->runcmd("$cmd", 0); + #if ($::RUNCMD_RC != 0) + + + $ret=xCAT::Utils->enableservice("nfs"); + if($ret!=0) { xCAT::MsgUtils->message('E', "Could not enable NFS."); } @@ -1895,24 +1909,26 @@ sub makenetworks sub setuphttp { - my $cmd; - my $distro = xCAT::Utils->osver(); - # restart httpd - if (-e "/etc/init.d/apache2") - { #for sles/ubuntu - $cmd = "/etc/init.d/apache2 stop; /etc/init.d/apache2 start"; - } - elsif (-e "/etc/init.d/httpd") - { - $cmd = "/etc/init.d/httpd stop; /etc/init.d/httpd start"; - } - else - { - $cmd = "service httpd stop; service httpd start"; - } +# my $cmd; +# my $distro = xCAT::Utils->osver(); +# # restart httpd +# if (-e "/etc/init.d/apache2") +# { #for sles/ubuntu +# $cmd = "/etc/init.d/apache2 stop; /etc/init.d/apache2 start"; +# } +# elsif (-e "/etc/init.d/httpd") +# { +# $cmd = "/etc/init.d/httpd stop; /etc/init.d/httpd start"; +# } +# else +# { +# $cmd = "service httpd stop; service httpd start"; +# } - my $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) +# my $outref = xCAT::Utils->runcmd("$cmd", 0); +# if ($::RUNCMD_RC != 0) + my $ret=xCAT::Utils->restartservice("http"); + if($ret!=0) { xCAT::MsgUtils->message('E', "Could not restart httpd."); } @@ -1922,26 +1938,28 @@ sub setuphttp } # enable httpd - if (-e "/etc/init.d/apache2") - { - if ( $distro =~ /ubuntu.*/ || $distro =~ /debian.*/i) { - $cmd = "/usr/sbin/update-rc.d apache2 enable"; - } - else - { # for sles - $cmd = "/sbin/chkconfig apache2 on"; - } - } - else - { - my $CHKCONFIG = xCAT::Utils->fullpathbin("chkconfig"); - $cmd = "$CHKCONFIG httpd on"; - } + #if (-e "/etc/init.d/apache2") + #{ + # if ( $distro =~ /ubuntu.*/ || $distro =~ /debian.*/i) { + # $cmd = "/usr/sbin/update-rc.d apache2 enable"; + # } + # else + # { # for sles + # $cmd = "/sbin/chkconfig apache2 on"; + # } + #} + #else + #{ + # my $CHKCONFIG = xCAT::Utils->fullpathbin("chkconfig"); + # $cmd = "$CHKCONFIG httpd on"; + #} - $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) + #$outref = xCAT::Utils->runcmd("$cmd", 0); + #if ($::RUNCMD_RC != 0) + $ret=xCAT::Utils->enableservice("http"); + if($ret!=0) { xCAT::MsgUtils->message('E', "Could not enable httpd."); } @@ -2182,12 +2200,12 @@ sub startnamedonboot else { #chkconfig - my $serv = "named"; - my $cmd = "/sbin/chkconfig $serv on"; - if ( $distro =~ /ubuntu.*/ || $distro =~ /debian.*/i) { - $serv = "bind9"; - $cmd = "update-rc.d $serv enable"; - } + #my $serv = "named"; + #my $cmd = "/sbin/chkconfig $serv on"; + #if ( $distro =~ /ubuntu.*/ || $distro =~ /debian.*/i) { + # $serv = "bind9"; + # $cmd = "update-rc.d $serv enable"; + #} #"service named start" is very slowly,sometimes hang in rhels6.4 after installation #a work around is to generate /etc/rndc-key during xCAT installation @@ -2195,14 +2213,16 @@ sub startnamedonboot system("rndc-confgen -a -r /dev/urandom"); } - my $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) + #my $outref = xCAT::Utils->runcmd("$cmd", 0); + #if ($::RUNCMD_RC != 0) + my $ret=xCAT::Utils->enableservice("named"); + if($ret!=0) { - xCAT::MsgUtils->message("E", "Could not enable $serv."); + xCAT::MsgUtils->message("E", "Could not enable dns server."); } else { - xCAT::MsgUtils->message("I", "$serv has been enabled on boot."); + xCAT::MsgUtils->message("I", "dns server has been enabled on boot."); } } }