CLOUDSTACK-7568, CLOUDSTACK-7569: Use systemctl for managing services in RHEL7. chkconfig --del doesn't work in RHEL7.

This commit is contained in:
Kishan Kavala 2014-09-17 17:47:33 +05:30
parent 577a2f40b3
commit 983a3b80e2
2 changed files with 57 additions and 3 deletions

View File

@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from utilities import Distribution, serviceOpsRedhat,serviceOpsUbuntu
from utilities import Distribution, serviceOpsRedhat,serviceOpsUbuntu,serviceOpsRedhat7
from serviceConfig import *
class sysConfigFactory:
@staticmethod
@ -41,6 +41,8 @@ class sysConfigAgentFactory:
return sysConfigRedhat6(glbEnv)
elif distribution == "CentOS" or distribution == "RHEL5":
return sysConfigRedhat5(glbEnv)
elif distribution == "RHEL7":
return sysConfigRedhat7(glbEnv)
else:
print "Can't find the distribution version"
return sysConfig()
@ -140,6 +142,11 @@ class sysConfigAgentRedhatBase(sysConfigAgent):
self.svo = serviceOpsRedhat()
super(sysConfigAgentRedhatBase, self).__init__(env)
class sysConfigAgentRedhat7Base(sysConfigAgent):
def __init__(self, env):
self.svo = serviceOpsRedhat7()
super(sysConfigAgentRedhat7Base, self).__init__(env)
class sysConfigAgentUbuntu(sysConfigAgent):
def __init__(self, glbEnv):
super(sysConfigAgentUbuntu, self).__init__(glbEnv)
@ -175,6 +182,17 @@ class sysConfigRedhat5(sysConfigAgentRedhatBase):
firewallConfigAgent(self),
cloudAgentConfig(self)]
#it covers RHEL7
class sysConfigRedhat7(sysConfigAgentRedhat7Base):
def __init__(self, glbEnv):
super(sysConfigRedhat7, self).__init__(glbEnv)
self.services = [securityPolicyConfigRedhat(self),
networkConfigRedhat(self),
libvirtConfigRedhat(self),
firewallConfigAgent(self),
nfsConfig(self),
cloudAgentConfig(self)]
class sysConfigServer(sysConfig):
def check(self):
if os.geteuid() != 0:

View File

@ -113,7 +113,7 @@ class Distribution:
if version.find("Red Hat Enterprise Linux Server release 6") != -1 or version.find("Scientific Linux release 6") != -1 or version.find("CentOS Linux release 6") != -1 or version.find("CentOS release 6.") != -1:
self.distro = "RHEL6"
elif version.find("Red Hat Enterprise Linux Server release 7") != -1:
self.distro = "RHEL6"
self.distro = "RHEL7"
elif version.find("CentOS release") != -1:
self.distro = "CentOS"
else:
@ -212,3 +212,39 @@ class serviceOpsUbuntu(serviceOps):
def isKVMEnabled(self):
return bash("kvm-ok").isSuccess()
class serviceOpsRedhat7(serviceOps):
def isServiceRunning(self, servicename):
try:
o = bash("systemctl status " + servicename)
if "running" in o.getStdout() or "start" in o.getStdout() or "Running" in o.getStdout():
return True
else:
return False
except:
return False
def stopService(self, servicename,force=False):
if self.isServiceRunning(servicename) or force:
return bash("systemctl stop " + servicename).isSuccess()
return True
def disableService(self, servicename):
result = self.stopService(servicename)
bash("systemctl disable " + servicename)
return result
def startService(self, servicename,force=False):
if not self.isServiceRunning(servicename) or force:
return bash("systemctl start " + servicename).isSuccess()
return True
def enableService(self, servicename,forcestart=False):
bash("systemctl enable " + servicename)
return self.startService(servicename,force=forcestart)
def isKVMEnabled(self):
if os.path.exists("/dev/kvm"):
return True
else:
return False