Revert "added innitial daemon-reloaded support to service module"
This reverts commit 438d87d269
.
This commit is contained in:
parent
74e40b5fe1
commit
9acc7c402f
1 changed files with 52 additions and 68 deletions
|
@ -34,13 +34,12 @@ options:
|
||||||
- Name of the service.
|
- Name of the service.
|
||||||
state:
|
state:
|
||||||
required: false
|
required: false
|
||||||
choices: [ started, stopped, restarted, reloaded, daemon_reloaded ]
|
choices: [ started, stopped, restarted, reloaded ]
|
||||||
description:
|
description:
|
||||||
- C(started)/C(stopped) are idempotent actions that will not run
|
- C(started)/C(stopped) are idempotent actions that will not run
|
||||||
commands unless necessary. C(restarted) will always bounce the
|
commands unless necessary. C(restarted) will always bounce the
|
||||||
service. C(reloaded) will always reload. B(At least one of state
|
service. C(reloaded) will always reload. B(At least one of state
|
||||||
and enabled are required.)
|
and enabled are required.)
|
||||||
- The C(daemon_reloaded) state was added in 2.0, it is exclusive for systemd.
|
|
||||||
sleep:
|
sleep:
|
||||||
required: false
|
required: false
|
||||||
version_added: "1.3"
|
version_added: "1.3"
|
||||||
|
@ -280,7 +279,7 @@ class Service(object):
|
||||||
# Find ps binary
|
# Find ps binary
|
||||||
psbin = self.module.get_bin_path('ps', True)
|
psbin = self.module.get_bin_path('ps', True)
|
||||||
|
|
||||||
(rc, psout, pserr) = execute_command('%s %s' % (psbin, psflags))
|
(rc, psout, pserr) = self.execute_command('%s %s' % (psbin, psflags))
|
||||||
# If rc is 0, set running as appropriate
|
# If rc is 0, set running as appropriate
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
self.running = False
|
self.running = False
|
||||||
|
@ -1414,7 +1413,7 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
name = dict(required=True),
|
name = dict(required=True),
|
||||||
state = dict(choices=['running', 'started', 'stopped', 'restarted', 'reloaded', 'daemon_reloaded']),
|
state = dict(choices=['running', 'started', 'stopped', 'restarted', 'reloaded']),
|
||||||
sleep = dict(required=False, type='int', default=None),
|
sleep = dict(required=False, type='int', default=None),
|
||||||
pattern = dict(required=False, default=None),
|
pattern = dict(required=False, default=None),
|
||||||
enabled = dict(type='bool'),
|
enabled = dict(type='bool'),
|
||||||
|
@ -1441,81 +1440,66 @@ def main():
|
||||||
result = {}
|
result = {}
|
||||||
result['name'] = service.name
|
result['name'] = service.name
|
||||||
|
|
||||||
# shortcut for systemd only daemon-reloaded
|
# Find service management tools
|
||||||
if module.params['state'] == 'daemon_reloaded':
|
service.get_service_tools()
|
||||||
cmd = module.get_bin_path('systemctl', True)
|
|
||||||
svc_cmd = "%s %s %s" % (cmd, service.name, 'daemon-reloaded')
|
|
||||||
rc, stdout, stderr = module.run_command(svc_cmd)
|
|
||||||
result['msg']=stdout
|
|
||||||
if rc != 0:
|
|
||||||
result['rc'] = rc
|
|
||||||
if stderr:
|
|
||||||
result['msg']=stderr
|
|
||||||
module.fail_json(**result)
|
|
||||||
|
|
||||||
result['changed']=True
|
# Enable/disable service startup at boot if requested
|
||||||
|
if service.module.params['enabled'] is not None:
|
||||||
|
# FIXME: ideally this should detect if we need to toggle the enablement state, though
|
||||||
|
# it's unlikely the changed handler would need to fire in this case so it's a minor thing.
|
||||||
|
service.service_enable()
|
||||||
|
result['enabled'] = service.enable
|
||||||
|
|
||||||
|
if module.params['state'] is None:
|
||||||
|
# Not changing the running state, so bail out now.
|
||||||
|
result['changed'] = service.changed
|
||||||
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
result['state'] = service.state
|
||||||
|
|
||||||
|
# Collect service status
|
||||||
|
if service.pattern:
|
||||||
|
service.check_ps()
|
||||||
else:
|
else:
|
||||||
# Find service management tools
|
service.get_service_status()
|
||||||
service.get_service_tools()
|
|
||||||
|
|
||||||
# Enable/disable service startup at boot if requested
|
# Calculate if request will change service state
|
||||||
if service.module.params['enabled'] is not None:
|
service.check_service_changed()
|
||||||
# FIXME: ideally this should detect if we need to toggle the enablement state, though
|
|
||||||
# it's unlikely the changed handler would need to fire in this case so it's a minor thing.
|
|
||||||
service.service_enable()
|
|
||||||
result['enabled'] = service.enable
|
|
||||||
|
|
||||||
if module.params['state'] is None:
|
# Modify service state if necessary
|
||||||
# Not changing the running state, so bail out now.
|
(rc, out, err) = service.modify_service_state()
|
||||||
result['changed'] = service.changed
|
|
||||||
module.exit_json(**result)
|
|
||||||
|
|
||||||
result['state'] = service.state
|
if rc != 0:
|
||||||
|
if err and "Job is already running" in err:
|
||||||
# Collect service status
|
# upstart got confused, one such possibility is MySQL on Ubuntu 12.04
|
||||||
if service.pattern:
|
# where status may report it has no start/stop links and we could
|
||||||
service.check_ps()
|
# not get accurate status
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
service.get_service_status()
|
if err:
|
||||||
|
module.fail_json(msg=err)
|
||||||
# Calculate if request will change service state
|
|
||||||
service.check_service_changed()
|
|
||||||
|
|
||||||
# Modify service state if necessary
|
|
||||||
(rc, out, err) = service.modify_service_state()
|
|
||||||
|
|
||||||
if rc != 0:
|
|
||||||
if err and "Job is already running" in err:
|
|
||||||
# upstart got confused, one such possibility is MySQL on Ubuntu 12.04
|
|
||||||
# where status may report it has no start/stop links and we could
|
|
||||||
# not get accurate status
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
if err:
|
module.fail_json(msg=out)
|
||||||
module.fail_json(msg=err)
|
|
||||||
else:
|
|
||||||
module.fail_json(msg=out)
|
|
||||||
|
|
||||||
result['changed'] = service.changed | service.svc_change
|
result['changed'] = service.changed | service.svc_change
|
||||||
if service.module.params['enabled'] is not None:
|
if service.module.params['enabled'] is not None:
|
||||||
result['enabled'] = service.module.params['enabled']
|
result['enabled'] = service.module.params['enabled']
|
||||||
|
|
||||||
if not service.module.params['state']:
|
if not service.module.params['state']:
|
||||||
status = service.get_service_status()
|
status = service.get_service_status()
|
||||||
if status is None:
|
if status is None:
|
||||||
result['state'] = 'absent'
|
result['state'] = 'absent'
|
||||||
elif status is False:
|
elif status is False:
|
||||||
result['state'] = 'started'
|
result['state'] = 'started'
|
||||||
else:
|
|
||||||
result['state'] = 'stopped'
|
|
||||||
else:
|
else:
|
||||||
# as we may have just bounced the service the service command may not
|
result['state'] = 'stopped'
|
||||||
# report accurate state at this moment so just show what we ran
|
else:
|
||||||
if service.module.params['state'] in ['started','restarted','running','reloaded']:
|
# as we may have just bounced the service the service command may not
|
||||||
result['state'] = 'started'
|
# report accurate state at this moment so just show what we ran
|
||||||
else:
|
if service.module.params['state'] in ['started','restarted','running','reloaded']:
|
||||||
result['state'] = 'stopped'
|
result['state'] = 'started'
|
||||||
|
else:
|
||||||
|
result['state'] = 'stopped'
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue