]> git.pld-linux.org Git - packages/bluez.git/blob - bluez.init
- added try-restart
[packages/bluez.git] / bluez.init
1 #!/bin/sh
2 #
3 # bluetooth     Bluetooth subsystem starting and stopping
4 #
5 # chkconfig:    345 25 90
6 #
7 # description:  Bluetooth subsystem
8 #
9 # $Id$
10
11
12 # Source function library
13 . /etc/rc.d/init.d/functions
14
15 UART_CONF="/etc/bluetooth/uart"
16 [ -f /etc/sysconfig/bluetooth ] && . /etc/sysconfig/bluetooth
17
18 if [ "$UART_CONF" != "no" -a ! -f "$UART_CONF" ]; then
19         UART_CONF="no"
20 fi
21
22 start() {
23         # Check if the service is already running?
24         if [ ! -f /var/lock/subsys/bluetooth ]; then
25                 if is_yes "${DAEMON_ENABLE}" && [ -x /usr/sbin/bluetoothd ]; then
26                         msg_starting bluetooth
27                         daemon /usr/sbin/bluetoothd
28                         RETVAL=$?
29                 fi
30
31                 if is_yes "${HID2HCI_ENABLE}" && [ -x /usr/sbin/hid2hci ]; then
32                         msg_starting hid2hci
33                         daemon /usr/sbin/hid2hci -0 -q    #be quiet
34                         RETVAL=$?
35                         /bin/sleep 1 # delay for hid's to be detected by hotplug
36                 fi
37                 
38                 if is_yes "${HCID_ENABLE}" && [ -x /usr/sbin/hcid ]; then
39                         HCID_FLAGS="-f /etc/bluetooth/hcid.conf"
40
41                         if is_yes "${SDPD_ENABLE}" ; then
42                                 HCID_FLAGS="$HCID_FLAGS -s"
43                         fi
44                         msg_starting hcid
45                         daemon /usr/sbin/hcid $HCID_FLAGS
46                         RETVAL=$?
47                 fi
48                 
49                 if is_yes "${HIDD_ENABLE}" && [ -x /usr/bin/hidd ]; then
50                         msg_starting hidd
51                         daemon /usr/bin/hidd ${HIDD_OPTIONS} --server
52                         RETVAL=$?
53                 fi
54
55                 if is_yes "${RFCOMM_ENABLE}" && [ -x /usr/bin/rfcomm ]; then
56                         msg_starting rfcomm
57                         daemon /usr/bin/rfcomm -f /etc/bluetooth/rfcomm.conf bind all
58                         RETVAL=$?
59                 fi
60         
61                 if is_yes "${DUND_ENABLE}" && [ -x /usr/bin/dund ]; then
62                         msg_starting dund
63                         daemon /usr/bin/dund ${DUND_OPTIONS}
64                         RETVAL=$?
65                 fi
66         
67                 if is_yes "${PAND_ENABLE}" && [ -x /usr/bin/pand ]; then
68                         msg_starting pand
69                         daemon /usr/bin/pand ${PAND_OPTIONS}
70                         RETVAL=$?
71                 fi
72
73                 if [ -f /usr/sbin/hciattach -a "$UART_CONF" != "no" ]; then
74                         grep -v '^#' $UART_CONF | while read i; do
75                                 /usr/sbin/hciattach $i
76                         done
77                 fi
78                 touch /var/lock/subsys/bluetooth
79         else
80                 msg_already_running bluetooth
81         fi
82 }
83
84 stop() {
85         if [ -f /var/lock/subsys/bluetooth ]; then
86                 if is_yes "${PAND_ENABLE}" && [ -x /usr/bin/pand ]; then
87                         msg_stopping pand
88                         killproc /usr/bin/pand
89                 fi
90
91                 if is_yes "${DUND_ENABLE}" && [ -x /usr/bin/dund ]; then
92                         msg_stopping dund
93                         killproc /usr/bin/dund
94                 fi
95
96                 if is_yes "${RFCOMM_ENABLE}" && [ -x /usr/bin/rfcomm ]; then
97                         msg_stopping rfcomm
98                         daemon /usr/bin/rfcomm release all
99                 fi
100
101                 if is_yes "${HIDD_ENABLE}" && [ -x  /usr/bin/hidd ]; then
102                         msg_stopping hidd
103                         killproc /usr/bin/hidd
104                 fi
105         
106                 if is_yes "${HCID_ENABLE}" && [ -x /usr/sbin/hcid ]; then
107                         msg_stopping hcid
108                         killproc /usr/sbin/hcid
109                 fi
110
111                 if is_yes "${DAEMON_ENABLE}" && [ -x /usr/sbin/bluetoothd ]; then
112                         msg_stopping bluetooth
113                         killproc /usr/sbin/bluetoothd
114                 fi
115
116                 if [ "$UART_CONF" != "no" ]; then
117                         killproc hciattach >/dev/null 2>&1
118                 fi
119                 rm -f /var/lock/subsys/bluetooth
120         else
121                 msg_not_running bluetooth
122         fi
123 }
124
125 condrestart() {
126         if [ -f /var/lock/subsys/bluetooth ]; then
127                 stop
128                 start
129         else
130                 msg_not_running bluetooth
131                 RETVAL=$1
132         fi
133 }
134
135 RETVAL=0
136 # See how we were called.
137 case "$1" in
138   start)
139         start
140         ;;
141   stop)
142         stop
143         ;;
144   restart)
145         stop
146         start
147         ;;
148   try-restart)
149         condrestart 0
150         ;;
151   reload|force-reload)
152         if [ -f /var/lock/subsys/bluetooth ]; then
153                 msg_reloading hcid
154                 killproc hcid -HUP
155                 RETVAL=$?
156         else
157                 msg_not_running bluetooth
158                 exit 7
159         fi
160         ;;
161   status)
162         is_yes "${HID2HCI_ENABLE}" && status hid2hci
163         is_yes "${HCID_ENABLE}" && status hcid
164         is_yes "${SDPD_ENABLE}" && status sdpd
165         is_yes "${HIDD_ENABLE}" && status hidd
166         is_yes "${DUND_ENABLE}" && status dund
167         if [ -f /var/lock/subsys/bluetooth ]; then
168                 exit 0
169         else
170                 exit 1
171         fi              
172         ;;
173   *)
174         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
175         exit 3
176 esac
177
178 exit $RETVAL
This page took 0.059967 seconds and 4 git commands to generate.