Revert "added innitial daemon-reloaded support to service module"

This reverts commit 438d87d269.
pull/18777/head
Brian Coca 11 years ago committed by Matt Clay
parent 3d42d8897e
commit b2dadaadf8

@ -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') # Enable/disable service startup at boot if requested
rc, stdout, stderr = module.run_command(svc_cmd) if service.module.params['enabled'] is not None:
result['msg']=stdout # FIXME: ideally this should detect if we need to toggle the enablement state, though
if rc != 0: # it's unlikely the changed handler would need to fire in this case so it's a minor thing.
result['rc'] = rc service.service_enable()
if stderr: result['enabled'] = service.enable
result['msg']=stderr
module.fail_json(**result) if module.params['state'] is None:
# Not changing the running state, so bail out now.
result['changed'] = service.changed
module.exit_json(**result)
result['changed']=True 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
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:
service.get_service_status()
# Calculate if request will change service state # Calculate if request will change service state
service.check_service_changed() service.check_service_changed()
# Modify service state if necessary # Modify service state if necessary
(rc, out, err) = service.modify_service_state() (rc, out, err) = service.modify_service_state()
if rc != 0: if rc != 0:
if err and "Job is already running" in err: if err and "Job is already running" in err:
# upstart got confused, one such possibility is MySQL on Ubuntu 12.04 # 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 # where status may report it has no start/stop links and we could
# not get accurate status # not get accurate status
pass pass
else:
if err:
module.fail_json(msg=err)
else:
module.fail_json(msg=out)
result['changed'] = service.changed | service.svc_change
if service.module.params['enabled'] is not None:
result['enabled'] = service.module.params['enabled']
if not service.module.params['state']:
status = service.get_service_status()
if status is None:
result['state'] = 'absent'
elif status is False:
result['state'] = 'started'
else:
result['state'] = 'stopped'
else: else:
# as we may have just bounced the service the service command may not if err:
# report accurate state at this moment so just show what we ran module.fail_json(msg=err)
if service.module.params['state'] in ['started','restarted','running','reloaded']:
result['state'] = 'started'
else: else:
result['state'] = 'stopped' module.fail_json(msg=out)
result['changed'] = service.changed | service.svc_change
if service.module.params['enabled'] is not None:
result['enabled'] = service.module.params['enabled']
if not service.module.params['state']:
status = service.get_service_status()
if status is None:
result['state'] = 'absent'
elif status is False:
result['state'] = 'started'
else:
result['state'] = 'stopped'
else:
# as we may have just bounced the service the service command may not
# report accurate state at this moment so just show what we ran
if service.module.params['state'] in ['started','restarted','running','reloaded']:
result['state'] = 'started'
else:
result['state'] = 'stopped'
module.exit_json(**result) module.exit_json(**result)

Loading…
Cancel
Save