salt.modules.service

service is a virtual module that is fulfilled by one of the following modules:

Execution Module Used for
debian_service Debian Wheezy and earlier
freebsdservice FreeBSD-based OSes using service(8)
gentoo_service Gentoo Linux using sysvinit and rc-update(8)
launchctl Mac OS hosts using launchctl(1)
netbsdservice NetBSD-based OSes
openbsdservice OpenBSD-based OSes
rh_service RedHat-based distros and derivatives using service(8) and chkconfig(8). Supports both pure sysvinit and mixed sysvinit/upstart systems.
service Fallback which simply wraps sysvinit scripts
smf Solaris-based OSes which use SMF
systemd Linux distros which use systemd
upstart Ubuntu-based distros using upstart
win_service Windows

If Salt's OS detection does not identify a different virtual service module, the minion will fall back to using this basic module, which simply wraps sysvinit scripts.

salt.modules.service.available(name)

Returns True if the specified service is available, otherwise returns False.

CLI Example:

salt '*' service.available sshd
salt.modules.service.get_all()

Return a list of all available services

CLI Example:

salt '*' service.get_all
salt.modules.service.missing(name)

The inverse of service.available. Returns True if the specified service is not available, otherwise returns False.

CLI Example:

salt '*' service.missing sshd
salt.modules.service.reload(name)

Refreshes config files by calling service reload. Does not perform a full restart.

CLI Example:

salt '*' service.reload <service name>
salt.modules.service.restart(name)

Restart the specified service

CLI Example:

salt '*' service.restart <service name>
salt.modules.service.run(name, action)

Run the specified service with an action.

New in version 2015.8.1.

name
Service name.
action
Action name (like start, stop, reload, restart).

CLI Example:

salt '*' service.run apache2 reload
salt '*' service.run postgresql initdb
salt.modules.service.start(name)

Start the specified service

CLI Example:

salt '*' service.start <service name>
salt.modules.service.status(name, sig=None)

Return the status for a service. If the name contains globbing, a dict mapping service name to PID or empty string is returned.

Changed in version Oxygen: The service name can now be a glob (e.g. salt*)

Parameters:
  • name (str) -- The name of the service to check
  • sig (str) -- Signature to use to find the service via ps
Returns:

PID if running, empty otherwise dict: Maps service name to PID if running, empty string otherwise

Return type:

string

CLI Example:

salt '*' service.status <service name> [service signature]
salt.modules.service.stop(name)

Stop the specified service

CLI Example:

salt '*' service.stop <service name>