sing-box: restart if the specified interfaces start up
authorVan Waholtz <brvphoenix@gmail.com>
Mon, 25 Mar 2024 12:40:46 +0000 (20:40 +0800)
committerJosef Schlehofer <pepe.schlehofer@gmail.com>
Fri, 29 Mar 2024 07:07:49 +0000 (08:07 +0100)
Signed-off-by: Van Waholtz <brvphoenix@gmail.com>
(cherry picked from commit da03a29cda0898e1a3e46e242b73a7795bbef492)

net/sing-box/Makefile
net/sing-box/files/sing-box.conf
net/sing-box/files/sing-box.init

index 9f6207186b6fad9fe151d79dfd9f5dc1a8a4448d..c677b9cd7b1ca62b033647d6a59a69940aa74e10 100644 (file)
@@ -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)?
index c776790e8d13f411ff7f2ff4862d5cf2e318add9..68ff82975eaa91fb481147ceedd690544ce05198 100644 (file)
@@ -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'
index 277c9f2eef1879be1d27d2bbb546e45d27141565..113e38aeec31a3d42b1a0963453402f0921bfdb9 100755 (executable)
@@ -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"
 }