mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
sysvinit service module (#34962)
* sysvinit service module Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
parent
46d35d8919
commit
cc61c86049
2 changed files with 377 additions and 2 deletions
|
@ -39,14 +39,18 @@ from ansible.module_utils.six import PY2, b
|
|||
from ansible.module_utils._text import to_bytes, to_text
|
||||
|
||||
|
||||
def sysv_is_enabled(name):
|
||||
def sysv_is_enabled(name, runlevel=None):
|
||||
'''
|
||||
This function will check if the service name supplied
|
||||
is enabled in any of the sysv runlevels
|
||||
|
||||
:arg name: name of the service to test for
|
||||
:kw runlevel: runlevel to check (default: None)
|
||||
'''
|
||||
return bool(glob.glob('/etc/rc?.d/S??%s' % name))
|
||||
if runlevel:
|
||||
return bool(glob.glob('/etc/rc%s.d/S??%s' % (runlevel, name)))
|
||||
else:
|
||||
return bool(glob.glob('/etc/rc?.d/S??%s' % name))
|
||||
|
||||
|
||||
def get_sysv_script(name):
|
||||
|
@ -74,6 +78,27 @@ def sysv_exists(name):
|
|||
return os.path.exists(get_sysv_script(name))
|
||||
|
||||
|
||||
def get_ps(module, pattern):
|
||||
'''
|
||||
Last resort to find a service by trying to match pattern to programs in memory
|
||||
'''
|
||||
found = False
|
||||
if platform.system() == 'SunOS':
|
||||
flags = '-ef'
|
||||
else:
|
||||
flags = 'auxww'
|
||||
psbin = module.get_bin_path('ps', True)
|
||||
|
||||
(rc, psout, pserr) = module.run_command([psbin, flags])
|
||||
if rc == 0:
|
||||
for line in psout.splitlines():
|
||||
if pattern in line:
|
||||
# FIXME: should add logic to prevent matching 'self', though that should be extreemly rare
|
||||
found = True
|
||||
break
|
||||
return found
|
||||
|
||||
|
||||
def fail_if_missing(module, found, service, msg=''):
|
||||
'''
|
||||
This function will return an error or exit gracefully depending on check mode status
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue