diff --git a/templates/common/_base/units/node-valid-hostname.service b/templates/common/_base/units/node-valid-hostname.service new file mode 100644 index 0000000000..ecef3b5792 --- /dev/null +++ b/templates/common/_base/units/node-valid-hostname.service @@ -0,0 +1,24 @@ +name: node-valid-hostname.service +enabled: true +contents: | + [Unit] + Description=Ensure hostname is not localhost + # Only run when the host has a localhost name. + ConditionHost=|localhost + ConditionHost=|localhost.localdomain + Before=network-online.target + + [Service] + Type=oneshot + RemainAfterExit=yes + ExecStartPre=/bin/echo "Node has localhost hostname. Waiting for new hostname." + # Get the short hostname. This is more reliable than a regex. + ExecStartPre=/bin/bash -c 'while [ `hostname -s` == "localhost" ]; do sleep 1; done;' + ExecStart=/bin/sh -c "echo Node changed hostname to `hostname`" + # Wait up to 5min for the node to get a real hostname. + TimeoutSec=300 + + [Install] + WantedBy=multi-user.target + # Ensure that network-online.target will not complete until the node has a real hostname. + RequiredBy=network-online.target