[TriLUG] Debugging an init.d script
Andrew Perrin
clists at perrin.socsci.unc.edu
Mon Nov 12 19:25:31 EST 2007
Gang,
After a recent apt-get upgrade, my bluetooth isn't working right.
Specifically, /etc/init.d/bluetooth has stopped loading dund and pand,
which it used to start automatically. Nothing seems horribly wrong, but
it just starts hcid and exits. If I start dund manually, everything works
fine, so I'm sure that's the problem.
How would you go about debugging an /etc/init.d/bluetooth script?
FYI, the script is below, and the necessary binaries are there and
executable:
joehill:/etc/default# which dund
/usr/bin/dund
joehill:/etc/default# which pand
/usr/bin/pand
joehill:/etc/default# which hcid
/usr/sbin/hcid
joehill:/etc/default# ls -l /usr/bin/dund
-rwxr-xr-x 1 root root 20072 2007-08-02 12:41 /usr/bin/dund
joehill:/etc/default# ls -l /usr/bin/pand
-rwxr-xr-x 1 root root 20072 2007-08-02 12:41 /usr/bin/pand
joehill:/etc/default# ls -l /usr/sbin/hcid
-rwxr-xr-x 1 root root 199148 2007-08-02 12:41 /usr/sbin/hcid
---/etc/init.d/bluetooth---
#! /bin/sh
### BEGIN INIT INFO
# Provides: bluetooth
# Required-Start: $local_fs $syslog $remote_fs
# Required-Stop: $local_fs $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start bluetooth daemons
### END INIT INFO
#
# bluez-utils Bluetooth subsystem starting and stopping
#
# originally from bluez's scripts/bluetooth.init
#
# Edd Dumbill <ejad at debian.org>
# LSB 3.0 compilance and enhancements by Filippo Giunchedi <filippo at debian.org>
#
# startup control over dund and pand can be changed by editing
# /etc/default/bluetooth
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC=bluetooth
HCID=/usr/sbin/hcid
HCIATTACH=/usr/sbin/hciattach
HCID_NAME=hcid
HCID_OPTIONS="-x -s"
HID2HCI=/usr/sbin/hid2hci
HID2HCI_ENABLED=1
UART_CONF=/etc/bluetooth/uart
RFCOMM=/usr/bin/rfcomm
RFCOMM_NAME=rfcomm
RFCOMM_CONF=/etc/bluetooth/rfcomm.conf
SDPTOOL=/usr/bin/sdptool
DUND_DAEMON=/usr/bin/dund
DUND_NAME=dund
PAND_DAEMON=/usr/bin/pand
PAND_NAME=pand
HIDD_DAEMON=/usr/bin/hidd
HIDD_NAME=hidd
DUND_ENABLED=1
PAND_ENABLED=1
HIDD_ENABLED=1
DUND_OPTIONS=""
PAND_OPTIONS=""
HIDD_OPTIONS="--master --server"
test -f /etc/default/bluetooth && . /etc/default/bluetooth
test -f /etc/default/rcS && . /etc/default/rcS
. /lib/lsb/init-functions
# test for essential daemons
test -x $HCID || exit 0
test -x $HCIATTACH || exit 0
test -x $RFCOMM || exit 0
# disable nonessential daemons if not present
if test "$DUND_ENABLED" != "0"; then
if ! test -x $DUND_DAEMON; then
DUND_ENABLED=0
fi
fi
if test "$PAND_ENABLED" != "0"; then
if ! test -x $PAND_DAEMON; then
PAND_ENABLED=0
fi
fi
if test "$HIDD_ENABLED" != "0"; then
if ! test -x $HIDD_DAEMON; then
HIDD_ENABLED=0
fi
fi
set -e
run_sdptool()
{
test -x $SDPTOOL || return 1
if ! test -z "$SDPTOOL_OPTIONS" ; then
oldifs="$IFS"
IFS=";"
for o in $SDPTOOL_OPTIONS ; do
#echo "execing $SDPTOOL $o"
IFS=" "
if [ "$VERBOSE" != "no" ]; then
$SDPTOOL $o
else
$SDPTOOL $o &>/dev/null 2>&1
fi
done
IFS="$oldifs"
fi
}
enable_hci_input()
{
if [ "$VERBOSE" != no ]; then
log_progress_msg "hid_devices"
$HID2HCI --tohci
else
$HID2HCI --tohci >/dev/null 2>&1
fi
}
disable_hci_input()
{
if [ "$VERBOSE" != no ]; then
log_progress_msg "hid_devices"
$HID2HCI --tohid
else
$HID2HCI --tohid >/dev/null 2>&1
fi
}
start_pan()
{
if test "$DUND_ENABLED" != "0"; then
start-stop-daemon --start --quiet --exec $DUND_DAEMON -- $DUND_OPTIONS
[ "$VERBOSE" != no ] && log_progress_msg "pand"
fi
if test "$PAND_ENABLED" != "0"; then
start-stop-daemon --start --quiet --exec $PAND_DAEMON -- $PAND_OPTIONS
[ "$VERBOSE" != no ] && log_progress_msg "pand"
fi
}
stop_pan()
{
if test "$DUND_ENABLED" != "0"; then
start-stop-daemon --stop --quiet --exec $DUND_DAEMON || true
[ "$VERBOSE" != no ] && log_progress_msg "pand"
fi
if test "$PAND_ENABLED" != "0"; then
start-stop-daemon --stop --quiet --exec $PAND_DAEMON || true
[ "$VERBOSE" != no ] && log_progress_msg "pand"
fi
}
start_hid()
{
if test "$HIDD_ENABLED" != "0"; then
start-stop-daemon --start --quiet --exec $HIDD_DAEMON -- $HIDD_OPTIONS
[ "$VERBOSE" != no ] && log_progress_msg "hidd"
fi
}
stop_hid()
{
if test "$HIDD_ENABLED" != "0"; then
$HIDD_DAEMON --killall
start-stop-daemon --stop --quiet --exec $HIDD_DAEMON || true
[ "$VERBOSE" != no ] && log_progress_msg "hidd"
fi
}
start_uarts()
{
[ -f $HCIATTACH ] && [ -f $UART_CONF ] || return
grep -v '^#' $UART_CONF | while read i; do
if [ "$VERBOSE" != no ]; then
$HCIATTACH $i
else
$HCIATTACH $i >/dev/null 2>&1
fi
done
}
stop_uarts()
{
killall hciattach > /dev/null 2>&1 || true
}
start_rfcomm()
{
if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
# rfcomm must always succeed for now: users
# may not yet have an rfcomm-enabled kernel
if [ "$VERBOSE" != no ]; then
log_progress_msg "rfcomm"
$RFCOMM -f $RFCOMM_CONF bind all || true
else
$RFCOMM -f $RFCOMM_CONF bind all >/dev/null 2>&1 || true
fi
fi
}
stop_rfcomm()
{
if [ -x $RFCOMM ] ; then
if [ "$VERBOSE" != no ]; then
log_progress_msg "rfcomm"
$RFCOMM unbind all || true
else
$RFCOMM unbind all >/dev/null 2>&1 || true
fi
fi
}
restart_rfcomm()
{
if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
if [ "$VERBOSE" != no ]; then
log_progress_msg "rfcomm"
$RFCOMM unbind all || true
$RFCOMM -f $RFCOMM_CONF bind all || true
else
$RFCOMM unbind all >/dev/null 2>&1|| true
$RFCOMM -f $RFCOMM_CONF bind all >/dev/null 2>&1 || true
fi
fi
}
case "$1" in
start)
log_daemon_msg "Starting $DESC"
if test "$BLUETOOTH_ENABLED" = "0"; then
log_progress_msg "disabled. see /etc/default/bluetooth"
log_end_msg 0
exit 0
fi
start-stop-daemon --start --quiet --exec $HCID -- $HCID_OPTIONS || true
log_progress_msg "hcid"
run_sdptool || true
start_uarts || true
start_hid || true
if test "$HID2HCI_ENABLED" = "1"; then
enable_hci_input || true
fi
start_rfcomm || true
start_pan || true
log_end_msg 0
;;
stop)
log_daemon_msg "Stopping $DESC"
if test "$BLUETOOTH_ENABLED" = "0"; then
log_progress_msg "disabled."
log_end_msg 0
exit 0
fi
stop_pan || true
stop_rfcomm || true
if test "$HID2HCI_ENABLED" = "1"; then
disable_hci_input || true
fi
stop_hid || true
start-stop-daemon --stop --quiet --exec $HCID || true
log_progress_msg "hcid"
stop_uarts || true
log_end_msg 0
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC"
stop_hid || true
stop_pan || true
start-stop-daemon --stop --quiet --exec $HCID || true
sleep 1
if test "$BLUETOOTH_ENABLED" = "0"; then
log_progress_msg "disabled. see /etc/default/bluetooth"
log_end_msg 0
exit 0
fi
start-stop-daemon --start --quiet --exec $HCID -- $HCID_OPTIONS || true
log_progress_msg "hcid"
start_pan || true
start_hid || true
restart_rfcomm
log_end_msg 0
;;
*)
N=/etc/init.d/bluetooth
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
# vim:noet
----------------------------------------------------------------------
Andrew J Perrin - andrew_perrin (at) unc.edu - http://perrin.socsci.unc.edu
Associate Professor of Sociology; Book Review Editor, _Social Forces_
University of North Carolina - CB#3210, Chapel Hill, NC 27599-3210 USA
More information about the TriLUG
mailing list