MCPcopy
hub / github.com/saltstack/salt / enabled

Function enabled

salt/modules/systemd_service.py:1297–1356  ·  view source on GitHub ↗

Return if the named service is enabled to start on boot root Enable/disable/mask unit files in the specified root directory CLI Example: .. code-block:: bash salt '*' service.enabled

(name, root=None, **kwargs)

Source from the content-addressed store, hash-verified

1295# The unused kwargs argument is required to maintain consistency with the API
1296# established by Salt's service management states.
1297def enabled(name, root=None, **kwargs): # pylint: disable=unused-argument
1298 """
1299 Return if the named service is enabled to start on boot
1300
1301 root
1302 Enable/disable/mask unit files in the specified root directory
1303
1304 CLI Example:
1305
1306 .. code-block:: bash
1307
1308 salt '*' service.enabled <service name>
1309 """
1310 # Try 'systemctl is-enabled' first, then look for a symlink created by
1311 # systemctl (older systemd releases did not support using is-enabled to
1312 # check templated services), and lastly check for a sysvinit service.
1313 cmd_result = __salt__["cmd.run_all"](
1314 _systemctl_cmd("is-enabled", name, root=root),
1315 python_shell=False,
1316 ignore_retcode=True,
1317 )
1318 if cmd_result["retcode"] == 0 and cmd_result["stdout"] != "alias":
1319 return True
1320 elif cmd_result["stdout"] == "alias":
1321 # check the service behind the alias
1322 aliased_name = __salt__["cmd.run_stdout"](
1323 _systemctl_cmd("show", name, root=root, extra_args=["-P", "Id"]),
1324 python_shell=False,
1325 )
1326 if (
1327 __salt__["cmd.retcode"](
1328 _systemctl_cmd("is-enabled", aliased_name, root=root),
1329 python_shell=False,
1330 ignore_retcode=True,
1331 )
1332 ) == 0:
1333 return True
1334 elif "@" in name:
1335 # On older systemd releases, templated services could not be checked
1336 # with ``systemctl is-enabled``. As a fallback, look for the symlinks
1337 # created by systemctl when enabling templated services.
1338 local_config_path = _root(LOCAL_CONFIG_PATH, "/")
1339 cmd = [
1340 "find",
1341 local_config_path,
1342 "-name",
1343 name,
1344 "-type",
1345 "l",
1346 "-print",
1347 "-quit",
1348 ]
1349 # If the find command returns any matches, there will be output and the
1350 # string will be non-empty.
1351 if bool(__salt__["cmd.run"](cmd, python_shell=False)):
1352 return True
1353 elif name in _get_sysv_services(root):
1354 return _sysv_enabled(name, root)

Callers 1

disabledFunction · 0.70

Calls 4

_systemctl_cmdFunction · 0.85
_rootFunction · 0.85
_get_sysv_servicesFunction · 0.85
_sysv_enabledFunction · 0.85

Tested by

no test coverage detected