name: node-valid-hostname.service
enabled: true
contents: |
  [Unit]
  Description=Ensure the node hostname is valid for the cluster
  Before=network-online.target

  [Service]
  Type=oneshot
  RemainAfterExit=yes
  User=root

  # SystemD prevents direct execution of the script in /usr/local/sbin,
  # so it is sourced. See the script for functionality.
  ExecStart=/bin/bash -c "source /usr/local/sbin/set-valid-hostname.sh; wait_localhost; set_valid_hostname `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

