fix defect #4238 [FVT]: xcat installation on sles gives out /sbin/SuSEfirewall2: line 507: /proc/net/ip_tables_names: No such file or directory
This commit is contained in:
		| @@ -3569,7 +3569,97 @@ sub gettimezone | ||||
|  | ||||
| } | ||||
|  | ||||
| 1; | ||||
| #-------------------------------------------------------------------------------- | ||||
|  | ||||
| =head3  specialservicemgr  | ||||
|     some special services cannot be processed in sysVinit, upstart and systemd framework, should be process here... | ||||
|     Arguments: | ||||
|       service name:  | ||||
|       action:        start/stop/restart/status/enable/disable | ||||
|       outputoption:   | ||||
|                      1:        return a hashref with the keys:"retcode","retmsg" | ||||
|                      otherwise: return retcode only | ||||
|     Returns: | ||||
|        | ||||
|                      a hashref if $outputoption is 1,the hash structure is: | ||||
|                                  {"retcode"=>(status code, 0 for running/active,1 for stopped/inactive,2 for failed) | ||||
|                                   "retmsg" =>(status string, running/active/stopped/inactive/failed) | ||||
|                                  } | ||||
|                      the status code otherwise | ||||
|  | ||||
|                      retcode:   127 if the service specified is not processed | ||||
|                                 the exit code of the service operation if the service specified is processed | ||||
|      | ||||
|     Globals: | ||||
|         none | ||||
|     Error: | ||||
|         none | ||||
|     Example: | ||||
|         my $ret=xCAT::Utils->specialservicemgr("firewall","start"); | ||||
|     Comments: | ||||
|         none | ||||
| =cut | ||||
|  | ||||
| #-------------------------------------------------------------------------------- | ||||
| sub specialservicemgr{ | ||||
|     my $svcname=shift; | ||||
|     my $action=shift; | ||||
|     my $outputoption=shift; | ||||
|     my %ret;  | ||||
|   | ||||
|     $ret{retcode}=127; | ||||
|     if($svcname eq "firewall")  | ||||
|     { | ||||
|  | ||||
|        my $cmd="type -P SuSEfirewall2 >/dev/null 2>&1"; | ||||
|        xCAT::Utils->runcmd($cmd,-1); | ||||
|        if($::RUNCMD_RC) | ||||
|        { | ||||
|           $ret{retcode}=127; | ||||
|           if(defined $outputoption and $outputoption == 1){ | ||||
|              return \%ret; | ||||
|           }else{ | ||||
|              return $ret{retcode}; | ||||
|           } | ||||
|        }else{ | ||||
|           if(($action eq "start") || ($action eq "stop"))  | ||||
|           { | ||||
|              $cmd="SuSEfirewall2 $action"; | ||||
|           }elsif($action eq "restart"){ | ||||
|              $cmd="SuSEfirewall2 stop;SuSEfirewall2 start"; | ||||
|           }elsif($action eq "disable"){ | ||||
|              $cmd="SuSEfirewall2 off"; | ||||
|           }elsif($action eq "enable"){ | ||||
|              $cmd="SuSEfirewall2 on"; | ||||
|           }elsif($action eq "status"){ | ||||
|              $cmd="service SuSEfirewall2_setup status"; | ||||
|           }else{ | ||||
|              | ||||
|              $ret{retcode}=127; | ||||
|              if(defined $outputoption and $outputoption == 1){ | ||||
|                 return \%ret; | ||||
|              }else{ | ||||
|                 return $ret{retcode}; | ||||
|              } | ||||
|           } | ||||
|        | ||||
|           $ret{retmsg}=xCAT::Utils->runcmd($cmd,-1); | ||||
|           $ret{retcode}= $::RUNCMD_RC; | ||||
|           if(defined $outputoption and $outputoption == 1){ | ||||
|              return \%ret; | ||||
|           }else{ | ||||
|              return $ret{retcode}; | ||||
|           } | ||||
|        } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     if(defined $outputoption and $outputoption == 1){ | ||||
|        return \%ret; | ||||
|     }else{ | ||||
|        return $ret{retcode}; | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
| #-------------------------------------------------------------------------------- | ||||
| @@ -3623,7 +3713,7 @@ sub servicemap{ | ||||
|      "nfs"   =>    ["nfsserver","nfs-server","nfs","nfs-kernel-server"], | ||||
|      "named" =>    ["named","bind9"], | ||||
|      "syslog" =>   ["syslog","syslogd","rsyslog"], | ||||
|      "firewall" => ["iptables","firewalld","SuSEfirewall2_setup","ufw"], | ||||
|      "firewall" => ["iptables","firewalld","ufw"], | ||||
|      "http" =>     ["apache2","httpd"], | ||||
|      "ntpserver" =>["ntpd","ntp"], | ||||
|      "mysql" =>    ["mysqld","mysql"], | ||||
| @@ -3690,6 +3780,13 @@ sub startservice{ | ||||
|      $svcname=shift; | ||||
|   } | ||||
|  | ||||
|   my $retval=0; | ||||
|   $retval=specialservicemgr($svcname,"start"); | ||||
|   if($retval != 127) | ||||
|   { | ||||
|      return $retval; | ||||
|   } | ||||
|  | ||||
|   my $cmd=""; | ||||
|   #for Systemd | ||||
|   my $svcunit=undef; | ||||
| @@ -3754,6 +3851,16 @@ sub stopservice{ | ||||
|      $svcname=shift; | ||||
|   } | ||||
|  | ||||
|  | ||||
|   my $retval=0; | ||||
|   $retval=specialservicemgr($svcname,"stop"); | ||||
|   if($retval != 127) | ||||
|   { | ||||
|      return $retval; | ||||
|   } | ||||
|  | ||||
|  | ||||
|  | ||||
|   my $cmd=""; | ||||
|   my $svcunit=undef; | ||||
|   my $svcd=undef; | ||||
| @@ -3816,6 +3923,14 @@ sub restartservice{ | ||||
|      $svcname=shift; | ||||
|   } | ||||
|  | ||||
|  | ||||
|   my $retval=0; | ||||
|   $retval=specialservicemgr($svcname,"restart"); | ||||
|   if($retval != 127) | ||||
|   { | ||||
|      return $retval; | ||||
|   } | ||||
|  | ||||
|   my $cmd=""; | ||||
|   my $svcunit=undef; | ||||
|   my $svcd=undef; | ||||
| @@ -3886,6 +4001,18 @@ sub checkservicestatus{ | ||||
|  | ||||
|   my $outputoption=shift; | ||||
|  | ||||
|   my $retval; | ||||
|   $retval=specialservicemgr($svcname,"status",1); | ||||
|   if($retval->{retcode} != 127) | ||||
|   { | ||||
|      if(defined $outputoption and $outputoption == 1 ){ | ||||
|         return $retval; | ||||
|      }elsif(exists $retval->{retcode}){ | ||||
|         return $retval->{retcode}; | ||||
|      } | ||||
|   } | ||||
|  | ||||
|  | ||||
|   my $cmd=""; | ||||
|   my $svcunit=undef; | ||||
|   my $svcd=undef; | ||||
| @@ -3979,6 +4106,16 @@ sub enableservice{ | ||||
|      $svcname=shift; | ||||
|  | ||||
|   } | ||||
|  | ||||
|   my $retval=0; | ||||
|   $retval=specialservicemgr($svcname,"enable"); | ||||
|   if($retval != 127) | ||||
|   { | ||||
|      return $retval; | ||||
|   } | ||||
|  | ||||
|  | ||||
|  | ||||
|   my $cmd=""; | ||||
|   my $svcunit=undef; | ||||
|   my $svcd=undef; | ||||
| @@ -4045,6 +4182,17 @@ sub disableservice{ | ||||
|      $svcname=shift; | ||||
|  | ||||
|   } | ||||
|  | ||||
|  | ||||
|  | ||||
|   my $retval=0; | ||||
|   $retval=specialservicemgr($svcname,"disable"); | ||||
|   if($retval != 127) | ||||
|   { | ||||
|      return $retval; | ||||
|   } | ||||
|  | ||||
|  | ||||
|   my $cmd=""; | ||||
|   my $svcunit=undef; | ||||
|   my $svcjob=undef; | ||||
|   | ||||
| @@ -286,7 +286,7 @@ function servicemap { | ||||
|  | ||||
|    INIT_syslog="syslog syslogd rsyslog"; | ||||
|   | ||||
|    INIT_firewall="iptables firewalld SuSEfirewall2_setup ufw"; | ||||
|    INIT_firewall="iptables firewalld ufw"; | ||||
|  | ||||
|    INIT_http="apache2 httpd"; | ||||
|  | ||||
| @@ -328,8 +328,58 @@ function servicemap { | ||||
|     | ||||
| } | ||||
|  | ||||
| #some special services cannot be processed in sysVinit, upstart and systemd framework, should be process here... | ||||
| #Notice: | ||||
| # return value:  | ||||
| # 127 :         if the service $svcname cannot be processed in this function | ||||
| # otherwise:    the return value of the service action | ||||
|  | ||||
| function specialservicemgr { | ||||
|    local svcname=$1 | ||||
|    local action=$2 | ||||
|  | ||||
|    if [ "$svcname" = "firewall"  ];then | ||||
|       type -P SuSEfirewall2 >/dev/null 2>&1 | ||||
|       if [ "$?" = "0" ] ;then | ||||
|          case "$action" in | ||||
|               "start"|"stop") | ||||
|               SuSEfirewall2 $action | ||||
|               ;; | ||||
|               "restart") | ||||
|               SuSEfirewall2 stop | ||||
|               SuSEfirewall2 start | ||||
|               ;; | ||||
|               "disable") | ||||
|               SuSEfirewall2 off | ||||
|               ;; | ||||
|               "enable") | ||||
|               SuSEfirewall2 on | ||||
|               ;; | ||||
|               "status") | ||||
|               service SuSEfirewall2_setup status | ||||
|               ;; | ||||
|               *) | ||||
|               return 127  | ||||
|               ;; | ||||
|          esac | ||||
|          return $? | ||||
|       fi | ||||
|    fi | ||||
|  | ||||
|    return 127 | ||||
| } | ||||
|  | ||||
| function startservice { | ||||
|    local svcname=$1 | ||||
|  | ||||
|    local retval | ||||
|    specialservicemgr "$svcname" start  | ||||
|    retval=$? | ||||
|    if [ "$retval" != "127"  ]; then | ||||
|       return $retval | ||||
|    fi | ||||
|  | ||||
|  | ||||
|    local cmd= | ||||
|    local svcunit=`servicemap $svcname 1` | ||||
|    local svcjob=`servicemap $svcname 2` | ||||
| @@ -354,6 +404,14 @@ function startservice { | ||||
|  | ||||
| function stopservice { | ||||
|    local svcname=$1 | ||||
|  | ||||
|    local retval | ||||
|    specialservicemgr "$svcname" stop  | ||||
|    retval=$? | ||||
|    if [ "$retval" != "127"  ]; then | ||||
|       return $retval | ||||
|    fi | ||||
|  | ||||
|    local cmd= | ||||
|    local svcunit=`servicemap $svcname 1` | ||||
|    local svcjob=`servicemap $svcname 2` | ||||
| @@ -384,6 +442,15 @@ function stopservice { | ||||
|  | ||||
| function restartservice { | ||||
|    local svcname=$1 | ||||
|  | ||||
|    local retval | ||||
|    specialservicemgr "$svcname" restart  | ||||
|    retval=$? | ||||
|    if [ "$retval" != "127"  ]; then | ||||
|       return $retval | ||||
|    fi | ||||
|  | ||||
|  | ||||
|    local cmd= | ||||
|    local svcunit=`servicemap $svcname 1` | ||||
|    local svcjob=`servicemap $svcname 2` | ||||
| @@ -413,6 +480,14 @@ function restartservice { | ||||
| function checkservicestatus { | ||||
|    local svcname=$1 | ||||
|  | ||||
|    local retval | ||||
|    specialservicemgr "$svcname" status  | ||||
|    retval=$? | ||||
|    if [ "$retval" != "127"  ]; then | ||||
|       return $retval | ||||
|    fi | ||||
|  | ||||
|  | ||||
|    local svcunit=`servicemap $svcname 1` | ||||
|    local svcjob=`servicemap $svcname 2` | ||||
|    local svcd=`servicemap $svcname 0` | ||||
| @@ -455,6 +530,15 @@ function checkservicestatus { | ||||
|  | ||||
| function enableservice { | ||||
|    local svcname=$1 | ||||
|  | ||||
|    local retval | ||||
|    specialservicemgr "$svcname" enable  | ||||
|    retval=$? | ||||
|    if [ "$retval" != "127"  ]; then | ||||
|       return $retval | ||||
|    fi | ||||
|  | ||||
|  | ||||
|    local cmd= | ||||
|    local svcunit=`servicemap $svcname 1` | ||||
|    local svcjob=`servicemap $svcname 2` | ||||
| @@ -486,6 +570,14 @@ function enableservice { | ||||
|  | ||||
| function disableservice { | ||||
|    local svcname=$1 | ||||
|  | ||||
|    local retval | ||||
|    specialservicemgr "$svcname" disable  | ||||
|    retval=$? | ||||
|    if [ "$retval" != "127"  ]; then | ||||
|       return $retval | ||||
|    fi | ||||
|  | ||||
|    local cmd= | ||||
|    local svcunit=`servicemap $svcname 1` | ||||
|    local svcjob=`servicemap $svcname 2` | ||||
|   | ||||
		Reference in New Issue
	
	Block a user