<%
name = 'networking'

conf = node['platform_utils']['networking']['autopilot']
log = "#{conf['log_dir']}/#{name}-local.log"
wait_time = conf['wait_time']

cmd = nil
if File.exist?('/etc/init.d/networking')
  cmd = '/etc/init.d/networking restart'
else
  cmd = 'systemctl restart systemd-networkd'
end

unless conf['init_type'].nil?
  case conf['init_type']
  when 'init'
    cmd = '/etc/init.d/networking restart'
  when 'systemd'
    cmd = 'systemctl restart systemd-networkd'
  when 'netplan'
    cmd = 'netplan apply'
  end
end
-%>
PATH=/usr/sbin:/usr/bin:/bin:/usr/local/bin
DATE_F='+%Y-%m-%d %H:%M:%S %z'
LOG=<%= log %>

@reboot root sleep <%= wait_time %> && date "$DATE_F" > $LOG && <%= cmd %> >> $LOG 2>&1 && sleep 10s && ip addr show scope global >> $LOG 2>&1
