#!/usr/bin/env python3
-import io
import pty
import socket
import socketserver
send_chunk(self.request, str(status).encode())
-if sys.argv[1:] == ["--daemon"]:
- try:
- os.unlink(SOCKET_PATH)
- except FileNotFoundError:
- pass
+if sys.argv[1] == "--daemon":
+ if len(sys.argv) > 2:
+ assert len(sys.argv) == 3, "invalid command line"
+ assert sys.argv[2].isdigit(), "invalid listening fd"
+ listen_socket = socket.socket(fileno=int(sys.argv[2]))
+ else:
+ listen_socket = None
+ try:
+ os.unlink(SOCKET_PATH)
+ except FileNotFoundError:
+ pass
fd = os.open("/dev/null", os.O_RDONLY)
os.dup2(fd, sys.stdin.fileno())
os.close(fd)
- with socketserver.UnixStreamServer(SOCKET_PATH, RequestHandler) as server:
- server.allow_reuse_address = True
+ with socketserver.UnixStreamServer(
+ SOCKET_PATH, RequestHandler,
+ bind_and_activate=listen_socket is None) as server:
+ if listen_socket is not None:
+ server.socket = listen_socket
server.serve_forever()
else:
assert len(sys.argv) == 4, "invalid command line"
--- /dev/null
+[Unit]
+Description=Service for Programming the FPGA
+Requires=program-fpga.socket
+
+[Service]
+Type=simple
+ExecStart=bash -ic 'exec program-fpga.py --daemon 3'
+WorkingDirectory=%S/program-fpga
+StateDirectory=program-fpga
+
+[Install]
+Also=program-fpga.socket
+WantedBy=multi-user.target
\ No newline at end of file