mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Notify systemd synchronously (via NOTIFY_SOCKET)
Forking the systemd-notify command is known to be unreliable at least with older versions of the kernel and/or systemd. When systemd receives the notification the systemd-notify process may have already exited causing an error in the logs while waiting for a (90 seconds) timeout. This patch instead notifies the systemd NOTIFY_SOCKET synchronously in case the systemd.daemon python library is not available.
This commit is contained in:
parent
1ee9499d28
commit
f1765472dd
1 changed files with 12 additions and 1 deletions
|
@ -15,6 +15,7 @@ import contextlib
|
|||
import subprocess
|
||||
import multiprocessing
|
||||
import multiprocessing.util
|
||||
import socket
|
||||
|
||||
|
||||
# Import salt libs
|
||||
|
@ -55,7 +56,17 @@ def notify_systemd():
|
|||
import systemd.daemon
|
||||
except ImportError:
|
||||
if salt.utils.which('systemd-notify') and systemd_notify_call('--booted'):
|
||||
return systemd_notify_call('--ready')
|
||||
# Notify systemd synchronously
|
||||
notify_socket = os.getenv('NOTIFY_SOCKET')
|
||||
if notify_socket:
|
||||
# Handle abstract namespace socket
|
||||
if notify_socket.startswith('@'):
|
||||
notify_socket = '\0{0}'.format(notify_socket[1:])
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
sock.connect(notify_socket)
|
||||
sock.sendall('READY=1'.encode())
|
||||
sock.close()
|
||||
return True
|
||||
return False
|
||||
|
||||
if systemd.daemon.booted():
|
||||
|
|
Loading…
Add table
Reference in a new issue