#! /bin/sh # Copyright (c) 1995-2003 SuSE Linux AG, Nuernberg, Germany. # All rights reserved. # # Author: Stefan Behlert , based on # proposals and templates from Marcel Holtmann # and Stefan Reinauer # Rewritten by jimc for more modularity and to handle a2dpd (2007-04-08) # # /etc/init.d/bluetooth # and its symbolic link # /(usr/)sbin/rcbluetooth # ### BEGIN INIT INFO # Provides: bluetooth # Required-Start: $syslog $network # Required-Stop: $syslog # Default-Start: 3 5 # Default-Stop: 0 1 2 6 # Short-Description: Bluetooth protocol stack services # Description: Bluetooth protocol stack services # This services is needed to use bluetooth devices ### END INIT INFO # # Check for existence of needed config file and read it BLUETOOTH_CONFIG=/etc/sysconfig/bluetooth.J test -r $BLUETOOTH_CONFIG || exit 6 . $BLUETOOTH_CONFIG if [ "${PATH##*/usr/local}" = "$PATH" ] ; then PATH=/usr/local/sbin:/usr/local/bin:$PATH fi # Bluetooth data storage area LIB_BLUE=/var/lib/bluetooth . /etc/rc.status # Reset status of this service rc_reset # Does the whole job ($1) on daemon $2 including message output. # $1 can be: start, run, stop, check. ("start" = run if not already running; # "run" = run unconditionally.) $2 can be a basename or full path. function do_daemon () { local val=0 local pgm=$2 local basename=${pgm##*/} local rctxt=$1 echo -n " $basename" pgm=`type -p $pgm` if [ -z "$pgm" -o ! -x /.$pgm ] ; then echo -n " (missing)" rc_status -s return fi local args=$(eval echo \${DAEMON_ARGS_$basename}) local cmd="$OPT_N $pgm $args > /dev/null" local user=$(eval echo \${RUN_AS_$basename}) if [ -n "$user" ] ; then cmd="su -m -c '$cmd' $user" ; fi if [ "$(type -t special_$basename 2> /dev/null)" = "function" ] ; then cmd="special_$basename \"$cmd\"" fi case $1 in start ) if checkproc $pgm ; then rctxt=running ; else eval "$cmd" ; fi ;; run ) eval "$cmd" ;; stop ) $OPT_N killproc -TERM $pgm ;; check ) rctxt=OK checkproc $pgm ;; esac val=$? rc_status if [ $val -ne 0 ] ; then rctxt="code $val" ; fi echo -n " ($rctxt)" return $val } # for the suseplugger function set_configured() { if [ ! -x /sbin/hwscan ]; then return fi hwscan --bluetooth for i in `hwscan --bluetooth --list | cut -f1 -d:` do /sbin/hwscan --cfg=yes $i; done } # Before starting the daemon (execing command line args), remove from the # default object push download area all files older than 3 days. function special_opd () { local opddir=$LIB_BLUE/opd/. if [ ! -d $opddir ] ; then mkdir -p $opddir ; fi find $opddir -type f -mtime +3 -print0 | \ xargs -0 -n 25 /bin/rm eval "$*" } # Log message before starting audio daemon. function special_a2dpd () { logger -p daemon.info -t a2dpd "starting daemon as $RUN_AS_a2dpd" eval "$*" } case "$1" in start) # When booting ("coldplug"), and if the dongle is builtin or # already plugged, udev rules will run this script even though # filesystems are mounted readonly, hiss, boo. Head off that # case. hcid=`type -p hcid` rwtest=$LIB_BLUE/_rw_test.txt if [ -n "$hcid" ] && \ ( [ -d $LIB_BLUE/. ] || mkdir -p $LIB_BLUE 2> /dev/null ) && \ echo "Test Writing Here" > $rwtest 2> /dev/null ; then rm $rwtest else rc_status -s echo -n "Skipping Bluetooth ($LIB_BLUE is still readonly) " rc_status -v rc_exit fi echo -n "Starting Bluetooth: " set_configured for daemon in $BLUE_DAEMONS ; do do_daemon start $daemon done for daemon in $BLUE_UTILS ; do do_daemon run $daemon done # Ubuntu bug 92111 #( https://bugs.launchpad.net/ubuntu/+source/linux-source-2.6.20/+bug/92111 ) # The Broadcom BCM2045 chip needs to be reset after power-on # or suspend-to-{ram,disc}, how stupid. Symptom is that # 'hcitool inq' responds "Inquiry failed.: Connection timed # out" and/or other programs get similar behavior, and no # Bluetooth connections can be established, in or out. # Solution is to reset the dongle. It's hard for this script # to tell if you have a BCM2045, so everyone gets reset. sleep 0.5 devs=`hcitool dev | awk '$1 ~ /hci/ {print $1}'` for dev in $devs ; do hciconfig $dev reset done rc_status -v ;; stop) echo -n "Stopping Bluetooth: " reverse="" for daemon in $BLUE_DAEMONS ; do reverse="$daemon $reverse" done for daemon in $reverse ; do do_daemon stop $daemon done rc_status -v ;; try-restart) $0 status >/dev/null && $0 restart rc_status ;; restart) $0 stop $0 start rc_status ;; force-reload) echo -n "Reload service BLUETOOTH " $0 stop && $0 start rc_status ;; reload) rc_failed 3 rc_status -v ;; status) echo -n "Checking Bluetooth " if [ $START_SERVICES = 'no' ] ; then echo -n "(disabled) :" fi; for daemon in $BLUE_DAEMONS ; do do_daemon check $daemon done if [ "$START_SERVICES" = 'no' ] ; then rc_failed 3 else rc_status -v fi; ;; probe) ## Optional: Probe for the necessity of a reload, print out the ## argument to this init script which is required for a reload. ## Note: probe is not (yet) part of LSB (as of 1.2) # test /etc/FOO/FOO.conf -nt /var/run/FOO.pid && echo reload ;; *) echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" exit 1 ;; esac rc_exit