mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
systemd_service: remove caching of 'systemctl status' to fix automatic daemon-reload for repeated invocations
This commit is contained in:
parent
90c834fa5e
commit
b43018d2bf
2 changed files with 5 additions and 28 deletions
1
changelog/66864.fixed.md
Normal file
1
changelog/66864.fixed.md
Normal file
|
@ -0,0 +1 @@
|
|||
Remove caching of 'systemctl status' in systemd_service to fix automatic daemon-reload for repeated invocations.
|
|
@ -135,12 +135,8 @@ def _check_for_unit_changes(name):
|
|||
Check for modified/updated unit files, and run a daemon-reload if any are
|
||||
found.
|
||||
"""
|
||||
contextkey = f"systemd._check_for_unit_changes.{name}"
|
||||
if contextkey not in __context__:
|
||||
if _untracked_custom_unit_found(name) or _unit_file_changed(name):
|
||||
systemctl_reload()
|
||||
# Set context key to avoid repeating this check
|
||||
__context__[contextkey] = True
|
||||
if _untracked_custom_unit_found(name) or _unit_file_changed(name):
|
||||
systemctl_reload()
|
||||
|
||||
|
||||
def _check_unmask(name, unmask, unmask_runtime, root=None):
|
||||
|
@ -154,20 +150,6 @@ def _check_unmask(name, unmask, unmask_runtime, root=None):
|
|||
unmask_(name, runtime=True, root=root)
|
||||
|
||||
|
||||
def _clear_context():
|
||||
"""
|
||||
Remove context
|
||||
"""
|
||||
# Using list() here because modifying a dictionary during iteration will
|
||||
# raise a RuntimeError.
|
||||
for key in list(__context__):
|
||||
try:
|
||||
if key.startswith("systemd._systemctl_status."):
|
||||
__context__.pop(key)
|
||||
except AttributeError:
|
||||
continue
|
||||
|
||||
|
||||
def _default_runlevel():
|
||||
"""
|
||||
Try to figure out the default runlevel. It is kept in
|
||||
|
@ -355,19 +337,14 @@ def _systemctl_cmd(action, name=None, systemd_scope=False, no_block=False, root=
|
|||
|
||||
def _systemctl_status(name):
|
||||
"""
|
||||
Helper function which leverages __context__ to keep from running 'systemctl
|
||||
status' more than once.
|
||||
Helper function to run 'systemctl status'.
|
||||
"""
|
||||
contextkey = "systemd._systemctl_status.%s" % name
|
||||
if contextkey in __context__:
|
||||
return __context__[contextkey]
|
||||
__context__[contextkey] = __salt__["cmd.run_all"](
|
||||
return __salt__["cmd.run_all"](
|
||||
_systemctl_cmd("status", name),
|
||||
python_shell=False,
|
||||
redirect_stderr=True,
|
||||
ignore_retcode=True,
|
||||
)
|
||||
return __context__[contextkey]
|
||||
|
||||
|
||||
def _sysv_enabled(name, root):
|
||||
|
@ -424,7 +401,6 @@ def systemctl_reload():
|
|||
raise CommandExecutionError(
|
||||
"Problem performing systemctl daemon-reload: %s" % out["stdout"]
|
||||
)
|
||||
_clear_context()
|
||||
return True
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue