description     "Start the bluetooth daemon"
author          "chromium-os-dev@chromium.org"

start on started system-services
stop on stopping system-services

limit memlock unlimited unlimited

env BLUETOOTH_LIBDIR=/var/lib/bluetooth
env BLUETOOTH_RUNDIR=/var/run/bluetooth
env BLUETOOTH_DAEMON_OPTION=""
env BLUETOOTH_WANT_FILE=/var/lib/misc/bluetooth-daemon.current

pre-start script
  mkdir -p -m 0750 ${BLUETOOTH_LIBDIR}
  chown -R bluetooth:bluetooth ${BLUETOOTH_LIBDIR}
  mkdir -p -m 0750 ${BLUETOOTH_RUNDIR}
  chown -R bluetooth:bluetooth ${BLUETOOTH_RUNDIR}

  # Make sure file exists before accessing it
  mkdir -p "$(dirname $BLUETOOTH_WANT_FILE)"
  touch "$BLUETOOTH_WANT_FILE"

  # Check if we want to start bluez. If "floss" is wanted instead, exit early
  # without starting bluez.
  want_daemon="$(cat $BLUETOOTH_WANT_FILE)"
  if [ "$want_daemon" = "floss" ]; then
    exit 1
  fi
end script

respawn

exec /usr/bin/start_bluetoothd.sh