<%
name = 'samba'

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

cmd = nil
st_cmd = nil
if File.exist?('/etc/init.d/samba')
  cmd = '/etc/init.d/samba restart'
  st_cmd = '/etc/init.d/samba status'
else
  cmd = 'systemctl restart nmbd smbd'
  st_cmd = 'systemctl status nmbd smbd'
end
-%>
PATH=/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 && <%= st_cmd %> >> $LOG 2>&1
