USE_PROCD=1
START=99
-NAME="sing-box"
+script=$(readlink "$initscript")
+NAME="$(basename ${script:-$initscript})"
PROG="/usr/bin/sing-box"
start_service() {
config_load "$NAME"
- local enabled user group conffile workdir
+ local enabled user group conffile workdir ifaces
config_get_bool enabled "main" "enabled" "0"
[ "$enabled" -eq "1" ] || return 0
config_get user "main" "user" "root"
config_get conffile "main" "conffile"
+ config_get ifaces "main" "ifaces"
config_get workdir "main" "workdir" "/usr/share/sing-box"
mkdir -p "$workdir"
# Use root user if you want to use the TUN mode.
procd_set_param user "$user"
procd_set_param file "$conffile"
+ [ -z "$ifaces" ] || procd_set_param netdev $ifaces
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param respawn
}
service_triggers() {
+ local ifaces
+ config_load "$NAME"
+ config_get ifaces "main" "ifaces"
+ procd_open_trigger
+ for iface in $ifaces; do
+ procd_add_interface_trigger "interface.*.up" $iface /etc/init.d/$NAME restart
+ done
+ procd_close_trigger
procd_add_reload_trigger "$NAME"
}