description "Start kbdd daemon."
author "Ralf Dragon"

start on started bluetoothd
stop on stopping bluetoothd
#console none
service
respawn
nice -10

# unluckily upstart 0.3 prevents this so we can only have one instance
#instance $CONFIG_FILE

# upstart 0.3 does not allow passing variables so we fix the filename
#exec /usr/bin/kbdd -c $CONFIG_FILE

# upstart 0.3 does not allow worker services, thus we do everything in one file

pre-start script
	modprobe uinput

	/usr/bin/rfcomm bind all
	# this creates /dev/rfcomm* devices from /etc/bluetooth/rfcomm.conf    
	# it may take some seconds until the device is created
	# we wait 10s max or untile the device file exists

	i=1
	while [ '(' '!' -e /dev/rfcomm1 ')' -a '(' $i -le 10 ')' ]
	do 
	   sleep 1
	   i=$((i+1))
	done

end script

exec /usr/bin/kbdd -c /etc/bluetooth/kbdd/kbdd.conf

post-stop exec rfcomm release all
