# bluez - bluetooth daemon

description     "bluetooth daemon"

start on started dbus
stop on stopping dbus

env UART_CONF=/etc/bluetooth/uart
env RFCOMM_CONF=/etc/bluetooth/rfcomm.conf

respawn

exec /usr/sbin/bluetoothd

post-start script
	[ "$VERBOSE" = no ] && redirect='>/dev/null 2>&1' || redirect=

	# start_uarts()
	if [ -x /usr/sbin/hciattach ] && [ -f $UART_CONF ];
	then
		grep -v '^#' $UART_CONF | while read i; do
		  eval "/usr/sbin/hciattach $i $redirect" || :
		done
	fi

	# start_rfcomm()
	if [ -x /usr/bin/rfcomm ] && [ -f $RFCOMM_CONF ] ;
	then
		# rfcomm must always succeed for now: users
		# may not yet have an rfcomm-enabled kernel
		eval "/usr/bin/rfcomm -f $RFCOMM_CONF bind all $redirect" || :
	fi
end script

post-stop script
	# stop_uarts()
	logger -t bluez "Stopping uarts"
	killall hciattach >/dev/null 2>&1 || :

	# stop_rfcomm()
	logger -t bluez "Stopping rfcomm"
	if [ -x /usr/bin/rfcomm ];
	then
		eval "/usr/bin/rfcomm unbind all $redirect" || :
	fi
end script
