# shutdown
#
# crude hack to poweroff

description	"Shutdown"
author		"Arjan Bouter <abouter@sourcemage.org>"

start on shutdown
#stop on startup

task
console output

script 
  for running_job in $(initctl list|grep running|awk -F' ' '{print $1}'); do
    if [[ "$running_job" = 'tty1' ]]; then
      echo "leave tty1 running, just in case..."
    else
      stop $running_job
    fi
  done
  echo "signalling everything else to stop"
  initctl emit shutdown
  echo "unmounting filesystems"
  umount -a
  sync
  echo "powering off"
  poweroff -f
end script
