service_action
Trigger an action on a service using the appropriate tool.
⚙️ Compatible targets: Linux
Parameters
Name | Documentation |
---|---|
name | Name of the service. This parameter is required. |
action | Action to trigger on the service (start, stop, restart, reload, ...). This parameter is required. |
Outcome conditions
You need to replace ${name}
with its actual canonified value.
- ✅ Ok:
service_action_${name}_ok
- ☑️ Already compliant:
service_action_${name}_kept
- 🟨 Repaired:
service_action_${name}_repaired
- ☑️ Already compliant:
- ❌ Error:
service_action_${name}_error
Example
method: service_action
params:
name: VALUE
action: VALUE
Documentation
The service_*
methods manage the services running on the system.
Parameters
Service name
The name of the service is the name understood by the service manager, except for the
is-active-process
action, where it is the regex to match against the running processes list.
Action
The action is the name of an action to run on the given service. The following actions can be used:
start
stop
restart
reload
(orrefresh
)is-active
(orstatus
)is-active-process
(in this case, the "service" parameter is the regex to match against process list)enable
disable
is-enabled
Other actions may also be used, depending on the selected service manager.
Implementation
These methods will detect the method to use according to the platform. You can run the methods with an info
verbosity level to see which service manager will be used for a given action.
WARNING: Due to compatibility issues when mixing calls to systemctl and service/init.d, when an init script exists, we will not use systemctl compatibility layer but directly service/init.d.
The supported service managers are:
- systemd (any unknown action will be passed directly)
- upstart
- smf (for Solaris)
- service command (for non-boot actions, any unknown action will be passed directly)
- /etc/init.d scripts (for non-boot actions, any unknown action will be passed directly)
- SRC (for AIX) (for non-boot actions)
- chkconfig (for boot actions)
- update-rc.d (for boot actions)
- chitab (for boot actions)
- links in /etc/rcX.d (for boot actions)
- Windows services
Examples
# To restart the apache2 service
service_action("apache2", "restart");
service_restart("apache2");