From da03a29cda0898e1a3e46e242b73a7795bbef492 Mon Sep 17 00:00:00 2001 From: brvphoenix Date: Mon, 25 Mar 2024 20:40:46 +0800 Subject: [PATCH] sing-box: restart if the specified interfaces start up Signed-off-by: brvphoenix --- net/sing-box/Makefile | 2 +- net/sing-box/files/sing-box.conf | 3 ++- net/sing-box/files/sing-box.init | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/net/sing-box/Makefile b/net/sing-box/Makefile index 9f6207186b..c677b9cd7b 100644 --- a/net/sing-box/Makefile +++ b/net/sing-box/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=sing-box PKG_VERSION:=1.8.7 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://codeload.github.com/SagerNet/sing-box/tar.gz/v$(PKG_VERSION)? diff --git a/net/sing-box/files/sing-box.conf b/net/sing-box/files/sing-box.conf index c776790e8d..68ff82975e 100644 --- a/net/sing-box/files/sing-box.conf +++ b/net/sing-box/files/sing-box.conf @@ -4,4 +4,5 @@ config sing-box 'main' option user 'sing-box' option conffile '/etc/sing-box/config.json' option workdir '/usr/share/sing-box' - +# list ifaces 'wan' +# list ifaces 'wan6' diff --git a/net/sing-box/files/sing-box.init b/net/sing-box/files/sing-box.init index 277c9f2eef..113e38aeec 100755 --- a/net/sing-box/files/sing-box.init +++ b/net/sing-box/files/sing-box.init @@ -3,18 +3,20 @@ 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" @@ -27,6 +29,7 @@ start_service() { # 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 @@ -35,5 +38,13 @@ start_service() { } 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" }