#!/bin/sh /etc/rc.common
# RelayWay Core proxy engine — OpenWrt procd service.
# Install: cp this to /etc/init.d/relayway && chmod +x /etc/init.d/relayway
#          put your Xray-compatible config at /etc/relayway/config.json
#          /etc/init.d/relayway enable && /etc/init.d/relayway start
START=95
STOP=10
USE_PROCD=1
PROG=/usr/bin/relayway
CONF=/etc/relayway/config.json

start_service() {
    if [ ! -f "$CONF" ]; then
        echo "relayway: config $CONF not found" >&2
        return 1
    fi
    procd_open_instance
    procd_set_param command "$PROG" -c "$CONF"
    procd_set_param respawn 3600 5 5
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_set_param limits nofile="51200 51200"
    procd_close_instance
}

reload_service() {
    restart
}