标签归档:openwrt

multi-instance udp2raw configuration for openwrt

/etc/config/udp2raw

config udp2raw foo
        option enable '1'
        option run_command '-c -l 127.0.0.1:55820 -r foo_ip:80 -k <bar_password> --raw-mode faketcp -a'

config udp2raw bar
        option enable '1'
        option run_command '-c -l 127.0.0.1:55821 -r bar_ip:80 -k <bar_password> --raw-mode faketcp -a'

/etc/init.d/udp2raw

#!/bin/sh /etc/rc.common

USE_PROCD=1

START=99
STOP=01

PROG=/usr/bin/udp2raw

_log() {
        logger -p daemon.info -t udp2raw "$@"
}

_err() {
        logger -p daemon.err -t udp2raw "$@"
}

start_service() {
    config_load "udp2raw"
    config_foreach start_instance udp2raw
}

start_instance() {
    config_get run_command "$1" 'run_command'
    _log "start instance $1 with $run_command"
    procd_open_instance "udp2raw_$1"
    procd_set_param command $PROG
    procd_append_param command $run_command
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_close_instance
}

reload_service() {
    stop
    start
}

service_triggers() {
    procd_add_reload_trigger udp2raw
}

Now, service udp2raw start