Documentation
  • Docs »
  • sysvinit - Manage SysV services.

sysvinit - Manage SysV services.

New in version 2.6.

Synopsis

  • Controls services on target hosts that use the SysV init system.

Requirements

The below requirements are needed on the host that executes this module.

  • That the service managed has a corresponding init script.

Parameters

Parameter Choices/Defaults Comments
arguments
Additional arguments provided on the command line that some init scripts accept.

aliases: args
daemonize
bool
    Choices:
  • no ←
  • yes
Have the module daemonize as the service itself might not do so properly.
This is useful with badly written init scripts or deamons, which commonly manifests as the task hanging as it is still holding the tty or the service dying when the task is over as the connection closes the session.
enabled
bool
    Choices:
  • no
  • yes
Whether the service should start on boot. At least one of state and enabled are required.
name
required
Name of the service.

aliases: service
pattern
A substring to look for as would be found in the output of the ps command as a stand-in for a status result.
If the string is found, the service will be assumed to be running.
This option is mainly for use with init scripts that don't support the 'status' option.
runlevels
The runlevels this script should be enabled/disabled from.
Use this to override the defaults set by the package or init script itself.
sleep Default:
1
If the service is being restarted or reloaded then sleep this many seconds between the stop and start command. This helps to workaround badly behaving services.
state
    Choices:
  • started
  • stopped
  • restarted
  • reloaded
started/stopped are idempotent actions that will not run commands unless necessary. Not all init scripts support restarted nor reloaded natively, so these will both trigger a stop and start as needed.

Notes

Note

  • One option other than name is required.

Examples

- name: make sure apache2 is started
  sysvinit:
      name: apache2
      state: started
      enabled: yes

- name: make sure apache2 is started on runlevels 3 and 5
  sysvinit:
      name: apache2
      state: started
      enabled: yes
      runlevels:
        - 3
        - 5

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
results
complex
always
results from actions taken

  attempts

  changed

  name

  status



Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Maintenance

This module is flagged as core which means that it is maintained by the Ansible Core Team. See Module Maintenance & Support for more info.

For a list of other modules that are also maintained by the Ansible Core Team, see here.

Support

For more information about Red Hat’s support of this module, please refer to this Knowledge Base article

Author

  • Ansible Core Team

Hint

If you notice any issues in this documentation you can edit this document to improve it.