Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service module changed to terminate early if only enabled specified #2571

Merged
merged 2 commits into from
Apr 5, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 23 additions & 9 deletions library/service
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ options:
description:
- C(started)/C(stopped) are idempotent actions that will not run
commands unless necessary. C(restarted) will always bounce the
service. C(reloaded) will always reload.
service. C(reloaded) will always reload. At least one of state
and enabled are required.
pattern:
required: false
version_added: "0.7"
Expand All @@ -50,7 +51,9 @@ options:
required: false
choices: [ "yes", "no" ]
description:
- Whether the service should start on boot.
- Whether the service should start on boot. At least one of state and
enabled are required.

arguments:
description:
- Additional arguments provided on the command line
Expand All @@ -64,6 +67,8 @@ examples:
code: "service: name=httpd state=restarted"
- description: Example action to reload service httpd, in all cases
code: "service: name=httpd state=reloaded"
- description: Example action to enable service httpd, and not touch the running state
code: "service: name=httpd enabled=yes"
- description: Example action to start service foo, based on running process /usr/bin/foo
code: "service: name=foo pattern=/usr/bin/foo state=started"
- description: Example action to restart network service for interface eth0
Expand Down Expand Up @@ -738,7 +743,7 @@ class SunOSService(Service):
self.module.fail_json(msg='unable to find svcs binary')

self.svcadm_cmd = self.module.get_bin_path('svcadm', True)

if not self.svcadm_cmd:
self.module.fail_json(msg='unable to find svcadm binary')

Expand Down Expand Up @@ -789,9 +794,9 @@ class SunOSService(Service):
enabled = True
if line.find("temporary") != -1:
temporary = True

startup_enabled = (enabled and not temporary) or (not enabled and temporary)

if self.enable and startup_enabled:
return
elif (not self.enable) and (not startup_enabled):
Expand All @@ -813,8 +818,8 @@ class SunOSService(Service):
self.module.fail_json(msg=stdout)

self.changed = True


def service_control(self):
status = self.get_sunos_svcs_status()

Expand All @@ -838,7 +843,7 @@ class SunOSService(Service):
subcmd = "restart"
elif self.action == 'restart' and status != 'online':
subcmd = "enable -rst"

return self.execute_command("%s %s %s" % (self.svcadm_cmd, subcmd, self.name))


Expand All @@ -856,6 +861,8 @@ def main():
),
supports_check_mode=True
)
if module.params['state'] is None and module.params['enabled'] is None:
module.fail_json(msg="Neither 'state' nor 'enabled' set")

service = Service(module)

Expand All @@ -870,7 +877,6 @@ def main():
err = ''
result = {}
result['name'] = service.name
result['state'] = service.state

# Find service management tools
service.get_service_tools()
Expand All @@ -880,6 +886,14 @@ def main():
# 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:
Expand Down