Skip to content

Commit 983a3b8

Browse files
committed
CLOUDSTACK-7568, CLOUDSTACK-7569: Use systemctl for managing services in RHEL7. chkconfig --del doesn't work in RHEL7.
1 parent 577a2f4 commit 983a3b8

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

python/lib/cloudutils/syscfg.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
from utilities import Distribution, serviceOpsRedhat,serviceOpsUbuntu
17+
from utilities import Distribution, serviceOpsRedhat,serviceOpsUbuntu,serviceOpsRedhat7
1818
from serviceConfig import *
1919
class sysConfigFactory:
2020
@staticmethod
@@ -41,6 +41,8 @@ def getAgent(glbEnv):
4141
return sysConfigRedhat6(glbEnv)
4242
elif distribution == "CentOS" or distribution == "RHEL5":
4343
return sysConfigRedhat5(glbEnv)
44+
elif distribution == "RHEL7":
45+
return sysConfigRedhat7(glbEnv)
4446
else:
4547
print "Can't find the distribution version"
4648
return sysConfig()
@@ -139,7 +141,12 @@ class sysConfigAgentRedhatBase(sysConfigAgent):
139141
def __init__(self, env):
140142
self.svo = serviceOpsRedhat()
141143
super(sysConfigAgentRedhatBase, self).__init__(env)
142-
144+
145+
class sysConfigAgentRedhat7Base(sysConfigAgent):
146+
def __init__(self, env):
147+
self.svo = serviceOpsRedhat7()
148+
super(sysConfigAgentRedhat7Base, self).__init__(env)
149+
143150
class sysConfigAgentUbuntu(sysConfigAgent):
144151
def __init__(self, glbEnv):
145152
super(sysConfigAgentUbuntu, self).__init__(glbEnv)
@@ -175,6 +182,17 @@ def __init__(self, glbEnv):
175182
firewallConfigAgent(self),
176183
cloudAgentConfig(self)]
177184

185+
#it covers RHEL7
186+
class sysConfigRedhat7(sysConfigAgentRedhat7Base):
187+
def __init__(self, glbEnv):
188+
super(sysConfigRedhat7, self).__init__(glbEnv)
189+
self.services = [securityPolicyConfigRedhat(self),
190+
networkConfigRedhat(self),
191+
libvirtConfigRedhat(self),
192+
firewallConfigAgent(self),
193+
nfsConfig(self),
194+
cloudAgentConfig(self)]
195+
178196
class sysConfigServer(sysConfig):
179197
def check(self):
180198
if os.geteuid() != 0:

python/lib/cloudutils/utilities.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def __init__(self):
113113
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:
114114
self.distro = "RHEL6"
115115
elif version.find("Red Hat Enterprise Linux Server release 7") != -1:
116-
self.distro = "RHEL6"
116+
self.distro = "RHEL7"
117117
elif version.find("CentOS release") != -1:
118118
self.distro = "CentOS"
119119
else:
@@ -212,3 +212,39 @@ def enableService(self, servicename,forcestart=True):
212212

213213
def isKVMEnabled(self):
214214
return bash("kvm-ok").isSuccess()
215+
216+
class serviceOpsRedhat7(serviceOps):
217+
def isServiceRunning(self, servicename):
218+
try:
219+
o = bash("systemctl status " + servicename)
220+
if "running" in o.getStdout() or "start" in o.getStdout() or "Running" in o.getStdout():
221+
return True
222+
else:
223+
return False
224+
except:
225+
return False
226+
227+
def stopService(self, servicename,force=False):
228+
if self.isServiceRunning(servicename) or force:
229+
return bash("systemctl stop " + servicename).isSuccess()
230+
231+
return True
232+
def disableService(self, servicename):
233+
result = self.stopService(servicename)
234+
bash("systemctl disable " + servicename)
235+
return result
236+
237+
def startService(self, servicename,force=False):
238+
if not self.isServiceRunning(servicename) or force:
239+
return bash("systemctl start " + servicename).isSuccess()
240+
return True
241+
242+
def enableService(self, servicename,forcestart=False):
243+
bash("systemctl enable " + servicename)
244+
return self.startService(servicename,force=forcestart)
245+
246+
def isKVMEnabled(self):
247+
if os.path.exists("/dev/kvm"):
248+
return True
249+
else:
250+
return False

0 commit comments

Comments
 (0)