udpxy: rework init script and add disabled/respawn configs.
authorÁlvaro Fernández Rojas <noltari@gmail.com>
Mon, 27 Oct 2014 21:21:51 +0000 (22:21 +0100)
committerÁlvaro Fernández Rojas <noltari@gmail.com>
Mon, 27 Oct 2014 21:21:51 +0000 (22:21 +0100)
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
net/udpxy/Makefile
net/udpxy/files/udpxy.conf
net/udpxy/files/udpxy.init

index b8df5b817ab07bae4e684c0ddc25fb124e743340..8fc927645c92f999c8d12b6a81f037a375ea9728 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=udpxy
-PKG_VERSION:=2014-08-24
+PKG_VERSION:=2014-10-27
 PKG_RELEASE:=$(PKG_SOURCE_VERSION)
 
 PKG_SOURCE_PROTO:=git
index 8ef2a1e0507b9043435f7b22e360108bd3981652..9117a53e37ff8745138d5e219346de003cbc3010 100644 (file)
@@ -1,4 +1,6 @@
 config udpxy
+       option disabled '1'
+       option respawn '1'
        option verbose '0'
        option status '1'
        # option bind '0.0.0.0'
index a08f4a1348ca06981a3d7d13c7e55b3ac560f617..6f911a6fb713403bcc4cd87b68da0f3a09f33e19 100644 (file)
@@ -4,57 +4,64 @@
 START=50
 USE_PROCD=1
 
-udpxy_parse() {
+append_arg() {
        local cfg="$1"
+       local var="$2"
+       local opt="$3"
+       local def="$4"
+       local val
 
-       local cfg_verbose
-       local cfg_status
-       local cfg_mcsub_renew
-       local cfg_bind
-       local cfg_port
-       local cfg_source
-       local cfg_max_clients
-       local cfg_log_file
-       local cfg_buffer_size
-       local cfg_buffer_messages
-       local cfg_buffer_time
-       local cfg_nice_increment
-       local cfg_mcsub_renew
-
-       config_get_bool cfg_verbose $cfg 'verbose' 0
-       config_get_bool cfg_status $cfg 'status' 1
-       config_get cfg_bind $cfg 'bind'
-       config_get cfg_port $cfg 'port' '4022'
-       config_get cfg_source $cfg 'source'
-       config_get cfg_max_clients $cfg 'max_clients'
-       config_get cfg_log_file $cfg 'log_file'
-       config_get cfg_buffer_size $cfg 'buffer_size'
-       config_get cfg_buffer_messages $cfg 'buffer_messages'
-       config_get cfg_buffer_time $cfg 'buffer_time'
-       config_get cfg_nice_increment $cfg 'nice_increment'
-       config_get cfg_mcsub_renew $cfg 'mcsub_renew'
+       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 ] && procd_append_param command "$opt"
+}
+
+start_instance() {
+       local cfg="$1"
+       local aux
+
+       config_get_bool aux "$cfg" 'disabled' '0'
+       [ "$aux" = 1 ] && return 1
 
        procd_open_instance
 
        procd_set_param command /usr/bin/udpxy
-       procd_append_param command -T -p $cfg_port
-       [ "$cfg_verbose" -eq 1 ] && procd_append_param command -v
-       [ "$cfg_status" -eq 1 ] && procd_append_param command -S
-       [ ! -z "$cfg_bind" ] && procd_append_param command -a $cfg_bind
-       [ ! -z "$cfg_source" ] && procd_append_param command -m $cfg_source
-       [ ! -z "$cfg_max_clients" ] && procd_append_param command -c $cfg_max_clients
-       [ ! -z "$cfg_log_file" ] && procd_append_param command -l $cfg_log_file
-       [ ! -z "$cfg_buffer_size" ] && procd_append_param command -B $cfg_buffer_size
-       [ ! -z "$cfg_buffer_messages" ] && procd_append_param command -R $cfg_buffer_messages
-       [ ! -z "$cfg_buffer_time" ] && procd_append_param command -H $cfg_buffer_time
-       [ ! -z "$cfg_nice_increment" ] && procd_append_param command -n $cfg_nice_increment
-       [ ! -z "$cfg_mcsub_renew" ] && procd_append_param command -M $cfg_mcsub_renew
-
-       procd_set_param respawn
+       procd_append_param command "-T"
+
+       append_bool "$cfg" verbose "-V"
+       append_bool "$cfg" status "-S"
+       append_arg "$cfg" bind "-a"
+       append_arg "$cfg" port "-p"
+       append_arg "$cfg" source "-m"
+       append_arg "$cfg" max_clients "-c"
+       append_arg "$cfg" log_file "-l"
+       append_arg "$cfg" buffer_size "-B"
+       append_arg "$cfg" buffer_messages "-R"
+       append_arg "$cfg" buffer_time "-H"
+       append_arg "$cfg" nice_increment "-n"
+       append_arg "$cfg" mcsub_renew "-M"
+
+       config_get_bool aux "$cfg" 'respawn' '0'
+       [ "$aux" = 1 ] && procd_set_param respawn
+
        procd_close_instance
 }
 
+service_triggers() { 
+       procd_add_reload_trigger "udpxy" 
+}
+
 start_service() {
        config_load udpxy
-       config_foreach udpxy_parse udpxy
+       config_foreach start_instance udpxy
 }