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:
Johannes Renner 2017-08-16 16:54:41 +02:00
parent 1ee9499d28
commit f1765472dd

View file

@ -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():