mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Add service.is_enabled() helper
Add a simple helper to check whether a service is enabled. Signed-off-by: Mark McLoughlin <markmc@redhat.com>
This commit is contained in:
@@ -83,6 +83,8 @@ def run(args, stdin=None):
|
|||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise CalledProcessError(p.returncode, ' '.join(args))
|
raise CalledProcessError(p.returncode, ' '.join(args))
|
||||||
|
|
||||||
|
return (stdout, stderr)
|
||||||
|
|
||||||
def file_exists(filename):
|
def file_exists(filename):
|
||||||
try:
|
try:
|
||||||
mode = os.stat(filename)[stat.ST_MODE]
|
mode = os.stat(filename)[stat.ST_MODE]
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def is_running(service_name):
|
|||||||
ret = True
|
ret = True
|
||||||
try:
|
try:
|
||||||
ipautil.run(["/sbin/service", service_name, "status"])
|
ipautil.run(["/sbin/service", service_name, "status"])
|
||||||
except CalledProcessError:
|
except ipautil.CalledProcessError:
|
||||||
ret = False
|
ret = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@@ -43,6 +43,26 @@ def chkconfig_on(service_name):
|
|||||||
|
|
||||||
def chkconfig_off(service_name):
|
def chkconfig_off(service_name):
|
||||||
ipautil.run(["/sbin/chkconfig", service_name, "off"])
|
ipautil.run(["/sbin/chkconfig", service_name, "off"])
|
||||||
|
|
||||||
|
def is_enabled(service_name):
|
||||||
|
(stdout, stderr) = ipautil.run(["/sbin/chkconfig", "--list", service_name])
|
||||||
|
|
||||||
|
runlevels = {}
|
||||||
|
for runlevel in range(0, 7):
|
||||||
|
runlevels[runlevel] = False
|
||||||
|
|
||||||
|
for line in stdout.split("\n"):
|
||||||
|
parts = line.split()
|
||||||
|
if parts[0] == service_name:
|
||||||
|
for s in parts[1:]:
|
||||||
|
(runlevel, status) = s.split(":")[0:2]
|
||||||
|
try:
|
||||||
|
runlevels[int(runlevel)] = status == "on"
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
break
|
||||||
|
|
||||||
|
return (runlevels[3] and runlevels[4] and runlevels[5])
|
||||||
|
|
||||||
def print_msg(message, output_fd=sys.stdout):
|
def print_msg(message, output_fd=sys.stdout):
|
||||||
logging.debug(message)
|
logging.debug(message)
|
||||||
@@ -77,6 +97,9 @@ class Service:
|
|||||||
def chkconfig_off(self):
|
def chkconfig_off(self):
|
||||||
chkconfig_off(self.service_name)
|
chkconfig_off(self.service_name)
|
||||||
|
|
||||||
|
def is_enabled(self):
|
||||||
|
return is_enabled(self.service_name)
|
||||||
|
|
||||||
def print_msg(self, message):
|
def print_msg(self, message):
|
||||||
print_msg(message, self.output_fd)
|
print_msg(message, self.output_fd)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user