import socket from systemd import daemon, journal def say(fmt, *args, **kwargs): journal.send(('[journal] ' + fmt).format(*args, **kwargs)) print(fmt.format(*args, **kwargs)) sockets = daemon.listen_fds(True) say("received sockets {}", sockets) assert sockets == [3], sockets s = socket.socket(fileno=daemon.LISTEN_FDS_START) say("created socket: {} fd={}", s.getsockname(), s.fileno()) s.listen(5) while True: conn, info = s.accept() say("received connection {}", info) with conn.makefile() as f: input = f.read() say("connection said {!r}", input)