|
@@ -1,41 +1,39 @@
|
1
|
1
|
#!/bin/sh /etc/rc.common
|
|
2
|
+# Copyright (C) 2013-2014 OpenWrt.org
|
2
|
3
|
|
3
|
|
-NAME=shairport
|
4
|
4
|
START=94
|
5
|
|
-
|
6
|
|
-SERVICE_DAEMONIZE=1
|
7
|
|
-SERVICE_WRITE_PID=1
|
8
|
|
-
|
9
|
|
-AP_PIDDIR=/var/run
|
10
|
|
-AP_BIN=/usr/bin/shairport
|
|
5
|
+USE_PROCD=1
|
11
|
6
|
|
12
|
7
|
append_arg() {
|
13
|
|
- local cfg="$1"
|
14
|
|
- local var="$2"
|
15
|
|
- local opt="$3"
|
16
|
|
- local def="$4"
|
17
|
|
- local val
|
18
|
|
-
|
19
|
|
- config_get val "$cfg" "$var"
|
20
|
|
- [ -n "$val" -o -n "$def" ] && append AP_ARGS "$opt ${val:-$def}"
|
|
8
|
+ local cfg="$1"
|
|
9
|
+ local var="$2"
|
|
10
|
+ local opt="$3"
|
|
11
|
+ local def="$4"
|
|
12
|
+ local val
|
|
13
|
+
|
|
14
|
+ config_get val "$cfg" "$var"
|
|
15
|
+ [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
|
21
|
16
|
}
|
22
|
17
|
|
23
|
18
|
append_bool() {
|
24
|
|
- local cfg="$1"
|
25
|
|
- local var="$2"
|
26
|
|
- local opt="$3"
|
27
|
|
- local def="$4"
|
28
|
|
- local val
|
29
|
|
-
|
30
|
|
- config_get_bool val "$cfg" "$var" "$def"
|
31
|
|
- [ "$val" = 1 ] && append AP_ARGS "$opt"
|
|
19
|
+ local cfg="$1"
|
|
20
|
+ local var="$2"
|
|
21
|
+ local opt="$3"
|
|
22
|
+ local def="$4"
|
|
23
|
+ local val
|
|
24
|
+
|
|
25
|
+ config_get_bool val "$cfg" "$var" "$def"
|
|
26
|
+ [ "$val" = 1 ] && procd_append_param command "$opt"
|
32
|
27
|
}
|
33
|
28
|
|
34
|
29
|
start_instance() {
|
35
|
|
- AP_ARGS=""
|
36
|
30
|
local cfg="$1"
|
37
|
31
|
local ao dev
|
38
|
32
|
|
|
33
|
+ procd_open_instance
|
|
34
|
+
|
|
35
|
+ procd_set_param command /usr/bin/shairport
|
|
36
|
+
|
39
|
37
|
append_arg "$cfg" bname "-a" "AirPort"
|
40
|
38
|
append_arg "$cfg" log "-l"
|
41
|
39
|
append_arg "$cfg" initbuf "-b" "256"
|
|
@@ -51,41 +49,30 @@ start_instance() {
|
51
|
49
|
|
52
|
50
|
config_get ao "$cfg" audio_output ""
|
53
|
51
|
if [ "$ao" = "alsa" ]; then
|
54
|
|
- config_get dev "$cfg" output_device ""
|
|
52
|
+ config_get dev "$cfg" output_dev ""
|
55
|
53
|
if [ -n "$dev" ]; then
|
56
|
|
- append AP_ARGS "--"
|
57
|
|
- append_arg "$cfg" output_device "-d"
|
58
|
|
- append_arg "$cfg" mixer_device "-m"
|
|
54
|
+ procd_append_param command "--"
|
|
55
|
+ append_arg "$cfg" output_dev "-d"
|
|
56
|
+ append_arg "$cfg" mixer_dev "-m"
|
59
|
57
|
append_arg "$cfg" mixer_type "-t"
|
60
|
|
- append_arg "$cfg" mixer-control "-c"
|
61
|
|
- append_arg "$cfg" mixer-index "-i"
|
|
58
|
+ append_arg "$cfg" mixer_control "-c"
|
|
59
|
+ append_arg "$cfg" mixer_index "-i"
|
62
|
60
|
fi
|
63
|
61
|
fi
|
64
|
62
|
|
65
|
|
- SERVICE_PID_FILE=${AP_PIDDIR}/${NAME}_${cfg}.pid
|
66
|
|
- service_start $AP_BIN $AP_ARGS
|
67
|
|
-
|
68
|
|
- # Check if daemon is running, if not then
|
69
|
|
- # re-execute in foreground to display error.
|
70
|
|
- sleep 1 && service_check $AP_BIN || \
|
71
|
|
- $AP_BIN $AP_ARGS
|
|
63
|
+ procd_close_instance
|
72
|
64
|
}
|
73
|
65
|
|
74
|
|
-stop_instance()
|
75
|
|
-{
|
76
|
|
- local cfg="$1"
|
77
|
|
-
|
78
|
|
- SERVICE_PID_FILE=${AP_PIDDIR}/${NAME}_${cfg}.pid
|
79
|
|
- SERVICE_SIG_STOP="INT"
|
80
|
|
- service_stop $AP_BIN
|
81
|
|
-}
|
|
66
|
+service_triggers() {
|
|
67
|
+ procd_add_reload_trigger "shairport"
|
|
68
|
+}
|
82
|
69
|
|
83
|
|
-start() {
|
|
70
|
+start_service() {
|
84
|
71
|
config_load shairport
|
85
|
72
|
config_foreach start_instance shairport
|
86
|
73
|
}
|
87
|
74
|
|
88
|
|
-stop() {
|
89
|
|
- config_load shairport
|
90
|
|
- config_foreach stop_instance shairport
|
|
75
|
+stop_service() {
|
|
76
|
+ # FIXME: workaround until procd supports custom signal
|
|
77
|
+ killall -SIGINT shairport
|
91
|
78
|
}
|