shairport: Improve init script. 116/head
authorÁlvaro Fernández Rojas <noltari@gmail.com>
Tue, 22 Jul 2014 18:51:10 +0000 (20:51 +0200)
committerÁlvaro Fernández Rojas <noltari@gmail.com>
Wed, 23 Jul 2014 15:12:41 +0000 (17:12 +0200)
- Switch to procd.
- Fix alsa options.
- Fix indentation.
- Fix white spaces not being accepted on config values.
- Workaround procd missing custom signal.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
multimedia/shairport/files/shairport.init

index 99132be121a9d0829bd889b24bff2cf3bf6fc501..6c90467fb82f221f5be5eb36c5e437fbb83bbf5d 100644 (file)
@@ -1,41 +1,39 @@
 #!/bin/sh /etc/rc.common
+# Copyright (C) 2013-2014 OpenWrt.org
 
-NAME=shairport
 START=94
-
-SERVICE_DAEMONIZE=1
-SERVICE_WRITE_PID=1
-
-AP_PIDDIR=/var/run
-AP_BIN=/usr/bin/shairport
+USE_PROCD=1
 
 append_arg() {
-        local cfg="$1"
-        local var="$2"
-        local opt="$3"
-        local def="$4"
-        local val
-
-        config_get val "$cfg" "$var"
-        [ -n "$val" -o -n "$def" ] && append AP_ARGS "$opt ${val:-$def}"
+       local cfg="$1"
+       local var="$2"
+       local opt="$3"
+       local def="$4"
+       local val
+
+       config_get val "$cfg" "$var"
+       [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
 }
 
 append_bool() {
-        local cfg="$1"
-        local var="$2"
-        local opt="$3"
-        local def="$4"
-        local val
-
-        config_get_bool val "$cfg" "$var" "$def"
-        [ "$val" = 1 ] && append AP_ARGS "$opt"
+       local cfg="$1"
+       local var="$2"
+       local opt="$3"
+       local def="$4"
+       local val
+
+       config_get_bool val "$cfg" "$var" "$def"
+       [ "$val" = 1 ] && procd_append_param command "$opt"
 }
 
 start_instance() {
-       AP_ARGS=""
        local cfg="$1"
        local ao dev
 
+       procd_open_instance
+
+       procd_set_param command /usr/bin/shairport
+
        append_arg "$cfg" bname "-a" "AirPort"
        append_arg "$cfg" log "-l"
        append_arg "$cfg" initbuf "-b" "256"
@@ -51,41 +49,30 @@ start_instance() {
 
        config_get ao "$cfg" audio_output ""
        if [ "$ao" = "alsa" ]; then
-               config_get dev "$cfg" output_device ""
+               config_get dev "$cfg" output_dev ""
                if [ -n "$dev" ]; then
-                       append AP_ARGS "--"
-                       append_arg "$cfg" output_device "-d"
-                       append_arg "$cfg" mixer_device "-m"
+                       procd_append_param command "--"
+                       append_arg "$cfg" output_dev "-d"
+                       append_arg "$cfg" mixer_dev "-m"
                        append_arg "$cfg" mixer_type "-t"
-                       append_arg "$cfg" mixer-control "-c"
-                       append_arg "$cfg" mixer-index "-i"
+                       append_arg "$cfg" mixer_control "-c"
+                       append_arg "$cfg" mixer_index "-i"
                fi
        fi
 
-       SERVICE_PID_FILE=${AP_PIDDIR}/${NAME}_${cfg}.pid
-       service_start $AP_BIN $AP_ARGS
-
-       # Check if daemon is running, if not then
-       # re-execute in foreground to display error.
-       sleep 1 && service_check $AP_BIN || \
-               $AP_BIN $AP_ARGS
+       procd_close_instance
 }
 
-stop_instance()
-{
-       local cfg="$1"
-
-       SERVICE_PID_FILE=${AP_PIDDIR}/${NAME}_${cfg}.pid
-       SERVICE_SIG_STOP="INT"
-       service_stop $AP_BIN
-}
+service_triggers() { 
+       procd_add_reload_trigger "shairport" 
+} 
 
-start() {
+start_service() {
        config_load shairport
        config_foreach start_instance shairport
 }
 
-stop() {
-       config_load shairport
-       config_foreach stop_instance shairport
+stop_service() {
+       # FIXME: workaround until procd supports custom signal
+       killall -SIGINT shairport
 }