From 5fe158f353fad5b243eeeb5284acd30a75152691 Mon Sep 17 00:00:00 2001 From: immarvin Date: Tue, 10 Jun 2014 06:11:07 -0700 Subject: [PATCH] replace service stuff with newly added subrotines in xCAT::Utils --- perl-xCAT/xCAT/Utils.pm | 6 +- xCAT-server/lib/xcat/monitoring/nagiosmon.pm | 6 +- xCAT-server/lib/xcat/monitoring/rrdutil.pm | 6 +- xCAT-server/lib/xcat/plugins/AAsn.pm | 170 ++++++++++++------- xCAT-server/lib/xcat/plugins/anaconda.pm | 8 +- xCAT-server/lib/xcat/plugins/ddns.pm | 71 +++++--- xCAT-server/lib/xcat/plugins/dhcp.pm | 60 ++++--- xCAT-server/lib/xcat/plugins/nimol.pm | 9 +- xCAT-server/lib/xcat/plugins/sles.pm | 8 +- xCAT-server/sbin/xcatconfig | 4 +- 10 files changed, 221 insertions(+), 127 deletions(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 3a5b23db1..55bb47354 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -1881,7 +1881,9 @@ sub get_image_name Example: if (xCAT::Utils->startService("named") { ...} Comments: - none + this subroutine is deprecated, + will be used as an internal function to process AIX service, + for linux, use xCAT::Utils->startservice instead =cut @@ -3586,7 +3588,7 @@ sub servicemap{ # } my %svchash=( "dhcp" => { - 0=>["dhcpd","isc-dhcp-server"], + 0=>["dhcp3-server","dhcpd","isc-dhcp-server"], 1=>["dhcpd.service"], }, "nfs" => { diff --git a/xCAT-server/lib/xcat/monitoring/nagiosmon.pm b/xCAT-server/lib/xcat/monitoring/nagiosmon.pm index 24ded6ddd..4f0acb8cc 100644 --- a/xCAT-server/lib/xcat/monitoring/nagiosmon.pm +++ b/xCAT-server/lib/xcat/monitoring/nagiosmon.pm @@ -66,12 +66,14 @@ sub start { my $mychildren_cfg="/etc/nagios/objects/mychildren.cfg"; if ($isSN) { #start nagios daemon only when mychildren exists on the sn if (-f $mychildren_cfg) { - my $rc=`service nagios restart 2>&1`; + #my $rc=`service nagios restart 2>&1`; + my $rc=xCAT::Utils->restartservice("nagios"); reportError("$localhostname: $rc", $callback); } } else { #always start nagios daemon on mn - my $rc=`service nagios restart 2>&1`; + #my $rc=`service nagios restart 2>&1`; + my $rc=xCAT::Utils->restartservice("nagios"); reportError("$localhostname: $rc", $callback); } diff --git a/xCAT-server/lib/xcat/monitoring/rrdutil.pm b/xCAT-server/lib/xcat/monitoring/rrdutil.pm index 840615203..57c25ddd5 100755 --- a/xCAT-server/lib/xcat/monitoring/rrdutil.pm +++ b/xCAT-server/lib/xcat/monitoring/rrdutil.pm @@ -122,7 +122,8 @@ sub start_RRD_server print FILE "\tserver_args = - /var/rrd\n"; print FILE "}\n"; close FILE; - xCAT::Utils->runcmd("service xinetd restart", 0); + #xCAT::Utils->runcmd("service xinetd restart", 0); + xCAT::Utils->restartservice("xinetd"); } return 0; } @@ -188,7 +189,8 @@ sub stop_RRD_server } else { xCAT::Utils->runcmd("rm -f /etc/xinetd.d/rrdsrv", 0); } - xCAT::Utils->runcmd("service xinetd restart", 0); + #xCAT::Utils->runcmd("service xinetd restart", 0); + xCAT::Utils->restartservice("xinetd"); } return 0; } diff --git a/xCAT-server/lib/xcat/plugins/AAsn.pm b/xCAT-server/lib/xcat/plugins/AAsn.pm index f06ded0b0..540e0bdce 100755 --- a/xCAT-server/lib/xcat/plugins/AAsn.pm +++ b/xCAT-server/lib/xcat/plugins/AAsn.pm @@ -509,8 +509,13 @@ sub setup_CONS "conserver cannot be started because the file $ca_file2 cannot be found\n"; } else - { - my $rc = xCAT::Utils->startService("conserver"); + { + if (xCAT::Utils->isAIX()){ + $rc=xCAT::Utils->startService("conserver"); + }elsif(xCAT::Utils->isLinux()){ + #my $rc = xCAT::Utils->startService("conserver"); + $rc=xCAT::Utils->startservice("conserver"); + } if ($rc != 0) { return 1; @@ -537,9 +542,11 @@ sub setup_DHCP my $snonly = 0; # if on the MN check to see if dhcpd is running, and start it if not. if (xCAT::Utils->isMN()) { # on the MN - my @output = xCAT::Utils->runcmd("service dhcpd status", -1); - if ($::RUNCMD_RC != 0) { # not running - $rc = xCAT::Utils->startService("dhcpd"); + #my @output = xCAT::Utils->runcmd("service dhcpd status", -1); + #if ($::RUNCMD_RC != 0) { # not running + my $retcode= xCAT::Utils->checkservicestatus("dhcpd"); + if($retcode!=0){ + $rc = xCAT::Utils->startservice("dhcpd"); if ($rc != 0) { return 1; @@ -573,12 +580,18 @@ sub setup_DHCP ->($cmdref, \&xCAT::Client::handle_response); my $distro = xCAT::Utils->osver(); - my $serv = "dhcpd"; - if ( $distro =~ /ubuntu.*/i || $distro =~ /debian.*/i ){ - $serv = "isc-dhcp-server"; - } + #my $serv = "dhcpd"; + #if ( $distro =~ /ubuntu.*/i || $distro =~ /debian.*/i ){ + # $serv = "isc-dhcp-server"; + #} - my $rc = xCAT::Utils->startService($serv); + #my $rc = xCAT::Utils->startService($serv); + my $rc=0; + if(xCAT::Utils->isAIX()){ + $rc = xCAT::Utils->startService("dhcpd"); + } elsif(xCAT::Utils->isLinux()){ + $rc = xCAT::Utils->startservice("dhcp"); + } if ($rc != 0) { return 1; @@ -672,7 +685,13 @@ sub setup_FTP # start ftp - my $rc = xCAT::Utils->startService("vsftpd"); + #my $rc = xCAT::Utils->startService("vsftpd"); + my $rc = 0; + if(xCAT::Utils->isAIX()){ + $rc = xCAT::Utils->startService("vsftpd"); + }elsif(xCAT::Utils->isLinux()){ + $rc = xCAT::Utils->startservice("vsftpd"); + } if ($rc != 0) { return 1; @@ -723,12 +742,19 @@ sub setup_DNS # turn DNS on my $distro = xCAT::Utils->osver(); - my $serv = "named"; - if ( $distro =~ /ubuntu.*/i || $distro =~ /debian.*/i ){ - $serv = "bind9"; + #my $serv = "named"; + #if ( $distro =~ /ubuntu.*/i || $distro =~ /debian.*/i ){ + # $serv = "bind9"; + #} + + #my $rc = xCAT::Utils->startService($serv); + my $rc = 0; + if(xCAT::Utils->isAIX()){ + $rc = xCAT::Utils->startService("named"); + }elsif(xCAT::Utils->isLinux()){ + $rc=xCAT::Utils->startservice("named"); } - my $rc = xCAT::Utils->startService($serv); if ($rc != 0) { return 1; @@ -751,15 +777,17 @@ sub setup_DNS else { #chkconfig - my $cmd = "/sbin/chkconfig $serv on"; - my $outref = xCAT::Utils->runcmd("$cmd", 0); - if ($::RUNCMD_RC != 0) + #my $cmd = "/sbin/chkconfig $serv on"; + #my $outref = xCAT::Utils->runcmd("$cmd", 0); + #if ($::RUNCMD_RC != 0) + my $retcode=xCAT::Utils->enableservice("named"); + if($retcode!=0) { - xCAT::MsgUtils->message("SE", " Error: Could not enable $serv."); + xCAT::MsgUtils->message("SE", " Error: Could not enable dns server."); } else { - xCAT::MsgUtils->message("SI", " $serv has been enabled on boot."); + xCAT::MsgUtils->message("SI", " dns server has been enabled on boot."); } } @@ -778,7 +806,14 @@ sub setup_DNS sub setup_LDAP { - my $rc = xCAT::Utils->startService("ldap"); + #my $rc = xCAT::Utils->startService("ldap"); + my $rc = 0; + + if(xCAT::Utils->isAIX()){ + $rc = xCAT::Utils->startService("ldap"); + }elsif(xCAT::Utils->isLinux()){ + $rc=xCAT::Utils->startservice("ldap"); + } if ($rc != 0) { return 1; @@ -805,16 +840,17 @@ sub setup_NFS my $rc = 0; if (xCAT::Utils->isLinux()) { - my $os = xCAT::Utils->osver(); - if ($os =~ /sles.*/) - { - $rc = xCAT::Utils->startService("nfs"); - $rc = xCAT::Utils->startService("nfsserver"); - } - else - { - $rc = xCAT::Utils->startService("nfs"); - } + #my $os = xCAT::Utils->osver(); + #if ($os =~ /sles.*/) + #{ + # $rc = xCAT::Utils->startService("nfs"); + # $rc = xCAT::Utils->startService("nfsserver"); + #} + #else + #{ + # $rc = xCAT::Utils->startService("nfs"); + #} + $rc = xCAT::Utils->startservice("nfs"); } else { #AIX @@ -944,7 +980,14 @@ sub setup_NTPmn sub start_NTP { - my $rc = xCAT::Utils->startService("ntpd"); + my $rc =0; + if (xCAT::Utils->isAIX()){ + $rc=xCAT::Utils->startService("ntpd"); + }elsif(xCAT::Utils->isLinux()){ + #my $rc = xCAT::Utils->startService("conserver"); + $rc=xCAT::Utils->startservice("ntpd"); + } + if ($rc != 0) { return 1; @@ -1271,15 +1314,16 @@ sub setup_HTTP if (xCAT::Utils->isLinux()) { - my $os = xCAT::Utils->osver(); - if ($os =~ /sles.*/) - { - $rc = xCAT::Utils->startService("apache2"); - } - else - { - $rc = xCAT::Utils->startService("httpd"); - } + #my $os = xCAT::Utils->osver(); + #if ($os =~ /sles.*/) + #{ + # $rc = xCAT::Utils->startService("apache2"); + #} + #else + #{ + # $rc = xCAT::Utils->startService("httpd"); + #} + $rc=xCAT::Utils->startservice("http"); } return $rc; } @@ -1385,24 +1429,33 @@ sub enable_TFTPhpa } print FILE @newcfgfile; close (FILE); - my @output = xCAT::Utils->runcmd("service xinetd status", -1); - if ($::RUNCMD_RC == 0) { - if (grep(/running/, @output)) - { - print ' '; # indent service output to separate it from the xcatd service output - system "service xinetd stop"; - if ($? > 0) - { # error + #my @output = xCAT::Utils->runcmd("service xinetd status", -1); + #if ($::RUNCMD_RC == 0) {} + my $retcode=xCAT::Utils->checkservicestatus("xinetd"); + if($retcode==0){ + my $retcode=xCAT::Utils->restartservice("xinetd"); + if($retcode !=0 ) + { xCAT::MsgUtils->message("S", - "Error on command: service xinetd stop\n"); + "Error on restart xinetd\n"); + } - system "service xinetd start"; - if ($? > 0) - { # error - xCAT::MsgUtils->message("S", - "Error on command: service xinetd start\n"); - } - } + #if (grep(/running/, @output)) + #{ + # print ' '; # indent service output to separate it from the xcatd service output + # system "service xinetd stop"; + # if ($? > 0) + # { # error + # xCAT::MsgUtils->message("S", + # "Error on command: service xinetd stop\n"); + # } + # system "service xinetd start"; + # if ($? > 0) + # { # error + # xCAT::MsgUtils->message("S", + # "Error on command: service xinetd start\n"); + # } + #} } } } @@ -1449,7 +1502,8 @@ sub enable_TFTPhpa sleep 1; my @checkproc=`ps axf|grep -v grep|grep in.tftpd`; if (@checkproc){ - system("service tftpd-hpa stop"); + #system("service tftpd-hpa stop"); + xCAT::Utils->stopservice("tftpd-hpa"); } } my @tftpprocs=`ps axf|grep -v grep|grep in.tftpd`; diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index 028515366..e03144698 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -2000,9 +2000,11 @@ sub mksysclone } # check systemimager-server-rsyncd to make sure it's running. - my $out = xCAT::Utils->runcmd("service systemimager-server-rsyncd status", -1); - if ($::RUNCMD_RC != 0) { # not running - my $rc = xCAT::Utils->startService("systemimager-server-rsyncd"); + #my $out = xCAT::Utils->runcmd("service systemimager-server-rsyncd status", -1); + # if ($::RUNCMD_RC != 0) { # not running + my $retcode=xCAT::Utils->checkservicestatus("systemimager-server-rsyncd"); + if($retcode!=0){ + my $rc = xCAT::Utils->startservice("systemimager-server-rsyncd"); if ($rc != 0) { return 1; } diff --git a/xCAT-server/lib/xcat/plugins/ddns.pm b/xCAT-server/lib/xcat/plugins/ddns.pm index ddda1a6a8..58c5659f6 100755 --- a/xCAT-server/lib/xcat/plugins/ddns.pm +++ b/xCAT-server/lib/xcat/plugins/ddns.pm @@ -571,7 +571,8 @@ sub process_request { } else { - system("service $service stop"); #named may otherwise hold on to stale journal filehandles + #system("service $service stop"); #named may otherwise hold on to stale journal filehandles + xCAT::Utils->stopservice("named"); } my $conf = get_conf(); unlink $conf; @@ -614,24 +615,31 @@ sub process_request { } else { - my $cmd = "service $service stop"; - my @output=xCAT::Utils->runcmd($cmd, 0); - my $outp = join('', @output); - if ($::RUNCMD_RC != 0) - { - my $rsp = {}; - $rsp->{data}->[0] = "Command failed: $cmd. Error message: $outp.\n"; - xCAT::MsgUtils->message("E", $rsp, $callback); - return; - } + #my $cmd = "service $service stop"; + #my @output=xCAT::Utils->runcmd($cmd, 0); + #my $outp = join('', @output); + #if ($::RUNCMD_RC != 0) + #{ + # my $rsp = {}; + # $rsp->{data}->[0] = "Command failed: $cmd. Error message: $outp.\n"; + # xCAT::MsgUtils->message("E", $rsp, $callback); + # return; + #} - $cmd = "service $service start"; - @output=xCAT::Utils->runcmd($cmd, 0); - $outp = join('', @output); - if ($::RUNCMD_RC != 0) - { + #$cmd = "service $service start"; + #@output=xCAT::Utils->runcmd($cmd, 0); + #$outp = join('', @output); + #if ($::RUNCMD_RC != 0) + #{ + # my $rsp = {}; + # $rsp->{data}->[0] = "Command failed: $cmd. Error message: $outp.\n"; + # xCAT::MsgUtils->message("E", $rsp, $callback); + # return; + #} + my $retcode=xCAT::Utils->restartservice("named"); + if($retcode!=0){ my $rsp = {}; - $rsp->{data}->[0] = "Command failed: $cmd. Error message: $outp.\n"; + $rsp->{data}->[0] = "failed to start named.\n"; xCAT::MsgUtils->message("E", $rsp, $callback); return; } @@ -673,20 +681,29 @@ sub process_request { } else { - my $cmd = "service $service status|grep running"; - my @output=xCAT::Utils->runcmd($cmd, 0); - if ($::RUNCMD_RC != 0) + #my $cmd = "service $service status|grep running"; + #my @output=xCAT::Utils->runcmd($cmd, 0); + #if ($::RUNCMD_RC != 0) + #{ + # $cmd = "service $service start"; + # @output=xCAT::Utils->runcmd($cmd, 0); + # my $outp = join('', @output); + # if ($::RUNCMD_RC != 0) + # { + # my $rsp = {}; + # $rsp->{data}->[0] = "Command failed: $cmd. Error message: $outp.\n"; + # xCAT::MsgUtils->message("E", $rsp, $callback); + # return; + # } + #} + my $retcode=xCAT::Utils->startservice("named"); + if($retcode!=0) { - $cmd = "service $service start"; - @output=xCAT::Utils->runcmd($cmd, 0); - my $outp = join('', @output); - if ($::RUNCMD_RC != 0) - { my $rsp = {}; - $rsp->{data}->[0] = "Command failed: $cmd. Error message: $outp.\n"; + $rsp->{data}->[0] = "failed to start named.\n"; xCAT::MsgUtils->message("E", $rsp, $callback); return; - } + } } } diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index 0d59f9c87..e86bb20d3 100755 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -884,15 +884,19 @@ sub check_options # if not help and not -n, dhcpd needs to be running if (!($opt->{h})&& (!($opt->{n}))) { if (xCAT::Utils->isLinux()) { - my $DHCPSERVER="dhcpd"; - if( -e "/etc/init.d/isc-dhcp-server" ){ - $DHCPSERVER="isc-dhcp-server"; - } + #my $DHCPSERVER="dhcpd"; + #if( -e "/etc/init.d/isc-dhcp-server" ){ + # $DHCPSERVER="isc-dhcp-server"; + #} - my @output = xCAT::Utils->runcmd("service $DHCPSERVER status", -1); - if ($::RUNCMD_RC != 0) { # not running + #my @output = xCAT::Utils->runcmd("service $DHCPSERVER status", -1); + #if ($::RUNCMD_RC != 0) { # not running + my $ret=0; + $ret=xCAT::Utils->checkservicestatus("dhcp"); + if($ret!=0) + { my $rsp = {}; - $rsp->{data}->[0] = "$DHCPSERVER is not running. Run service $DHCPSERVER start and rerun your command."; + $rsp->{data}->[0] = "dhcp server is not running. please start the dhcp server."; xCAT::MsgUtils->message("E", $rsp, $callback, 1); return 1; } @@ -1840,25 +1844,29 @@ sub process_request { restart_dhcpd_aix(); } - elsif ( $distro =~ /ubuntu.*/ || $distro =~ /debian.*/i) - { - if (-e '/etc/dhcp/dhcpd.conf') { - system("chmod a+r /etc/dhcp/dhcpd.conf"); - system("/etc/init.d/isc-dhcp-server restart"); - } - else { - #ubuntu config - system("chmod a+r /etc/dhcp3/dhcpd.conf"); - system("/etc/init.d/dhcp3-server restart"); - } - } - else - { - system("/etc/init.d/dhcpd restart"); - # should not chkconfig dhcpd on every makedhcp invoation - # it is not appropriate and will cause problem for HAMN - # do it in xcatconfig instead - #system("chkconfig dhcpd on"); + else { + if ( $distro =~ /ubuntu.*/ || $distro =~ /debian.*/i) + { + if (-e '/etc/dhcp/dhcpd.conf') { + system("chmod a+r /etc/dhcp/dhcpd.conf"); + #system("/etc/init.d/isc-dhcp-server restart"); + } + else { + #ubuntu config + system("chmod a+r /etc/dhcp3/dhcpd.conf"); + #system("/etc/init.d/dhcp3-server restart"); + } + } + #else + #{ + # system("/etc/init.d/dhcpd restart"); + # # should not chkconfig dhcpd on every makedhcp invoation + # # it is not appropriate and will cause problem for HAMN + # # do it in xcatconfig instead + # #system("chkconfig dhcpd on"); + #} + xCAT::Utils->restartservice("dhcp"); + print "xx"; } } flock($dhcplockfd,LOCK_UN); diff --git a/xCAT-server/lib/xcat/plugins/nimol.pm b/xCAT-server/lib/xcat/plugins/nimol.pm index afc2a9336..46f206364 100644 --- a/xCAT-server/lib/xcat/plugins/nimol.pm +++ b/xCAT-server/lib/xcat/plugins/nimol.pm @@ -25,6 +25,7 @@ Getopt::Long::Configure("pass_through"); use xCAT::Table; use xCAT::MsgUtils; use xCAT::DBobjUtils; +use xCAT::Utils; sub handled_commands { return { @@ -376,7 +377,9 @@ sub update_export { for my $l (@new_export) { print $new_export_fd $l; } flock($new_export_fd,LOCK_UN); close($new_export_fd); - system("service nfs restart"); + #system("service nfs restart"); + my $retcode=xCAT::Utils->restartservice("nfs"); + return $retcode; } sub update_syslog { @@ -391,7 +394,9 @@ sub update_syslog { open($new_syslog_fd, ">>", "/etc/exports"); print $new_syslog_fd "local2.* /var/log/nimol.log\n"; close($new_syslog_fd); - system("service rsyslog restart"); + #system("service rsyslog restart"); + my $retcode=xCAT::Utils->restartservice("rsyslog"); + return $retcode; } else { print "Don't need to update syslog configure file.\n"; } diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index 61ac8b8ac..e44a8e719 100755 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -1520,9 +1520,11 @@ sub mksysclone } # check systemimager-server-rsyncd to make sure it's running. - my $out = xCAT::Utils->runcmd("service systemimager-server-rsyncd status", -1); - if ($::RUNCMD_RC != 0) { # not running - my $rc = xCAT::Utils->startService("systemimager-server-rsyncd"); + #my $out = xCAT::Utils->runcmd("service systemimager-server-rsyncd status", -1); + #if ($::RUNCMD_RC != 0) { # not running + my $retcode=xCAT::Utils->checkservicestatus("systemimager-server-rsyncd"); + if($retcode !=0){ + my $rc = xCAT::Utils->startservice("systemimager-server-rsyncd"); if ($rc != 0) { return 1; } diff --git a/xCAT-server/sbin/xcatconfig b/xCAT-server/sbin/xcatconfig index 2abb7f7fe..096e70cee 100755 --- a/xCAT-server/sbin/xcatconfig +++ b/xCAT-server/sbin/xcatconfig @@ -453,8 +453,8 @@ if ($::INITIALINSTALL || $::FORCE) &setuphttp; # chkconfig dhcpd on - system("chkconfig dhcpd on"); - + #system("chkconfig dhcpd on"); + xCAT::Utils->enableservice("dhcp"); # Turn off selinux on RedHat if (-f "/etc/redhat-release")