From 822f692dc156576f827685e520ed3425ccea3b94 Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Thu, 10 Oct 2024 18:44:55 -0600 Subject: [PATCH] Demonstrate how to avoid netcat dependency. This example patch demonstrates a pure-Python replacement of the netcat commands used in cloud-init's service files. --- systemd/cloud-init-local.service.tmpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/systemd/cloud-init-local.service.tmpl b/systemd/cloud-init-local.service.tmpl index e682f637a..b003a405e 100644 --- a/systemd/cloud-init-local.service.tmpl +++ b/systemd/cloud-init-local.service.tmpl @@ -44,7 +44,8 @@ ExecStartPre=/usr/bin/touch /run/cloud-init/enabled # process has completed this stage. The output from the return socket is piped # into a shell so that the process can send a completion message (defaults to # "done", otherwise includes an error message) and an exit code to systemd. -ExecStart=sh -c 'echo "start" | netcat -Uu -W1 /run/cloud-init/share/local.sock -s /run/cloud-init/share/local-return.sock | sh' +#ExecStart=sh -c 'echo "start" | netcat -Uu -W1 /run/cloud-init/share/local.sock -s /run/cloud-init/share/local-return.sock | sh' +ExecStart=python3 -c "import socket as s; import subprocess; c = s.socket(s.AF_UNIX, s.SOCK_DGRAM); c.connect('/run/cloud-init/share/local.sock'); r = s.socket(s.AF_UNIX, s.SOCK_DGRAM); r.connect('/run/cloud-init/share/local-return.sock'); c.sendall(b'start'); message = r.recv(4096); c.close(); r.close(); subprocess.run();" RemainAfterExit=yes TimeoutSec=0 -- 2.45.2