#!/bin/sh /etc/rc.common
# Created By ImmortalWrt
# https://github.com/immortalwrt

USE_PROCD=1

START=99
GOST=/usr/bin/gost

start_service() {
    config_load "gost"
    config_foreach start_instance
}

service_enabled() {
    config_get_bool enabled "$1" 'enable' 0
    [ $enabled -gt 0 ]
}

start_instance() {
    if ! service_enabled "$1"; then
        return 1
    fi

    config_get run_command "$1" 'run_command'

    procd_open_instance
    procd_set_param command $GOST
    procd_append_param command $run_command
    procd_set_param file /etc/config/gost
    procd_close_instance
}

reload_service() {
    stop
    start
}

service_triggers() {
    procd_add_reload_trigger gost
}
