sing-box: restart if the specified interfaces start up

Signed-off-by: brvphoenix <brvphoenix@gmail.com>
This commit is contained in:
brvphoenix 2024-03-25 20:40:46 +08:00 committed by Tianling Shen
parent 551ff0f810
commit da03a29cda
3 changed files with 16 additions and 4 deletions

View File

@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=sing-box PKG_NAME:=sing-box
PKG_VERSION:=1.8.7 PKG_VERSION:=1.8.7
PKG_RELEASE:=1 PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/SagerNet/sing-box/tar.gz/v$(PKG_VERSION)? PKG_SOURCE_URL:=https://codeload.github.com/SagerNet/sing-box/tar.gz/v$(PKG_VERSION)?

View File

@ -4,4 +4,5 @@ config sing-box 'main'
option user 'sing-box' option user 'sing-box'
option conffile '/etc/sing-box/config.json' option conffile '/etc/sing-box/config.json'
option workdir '/usr/share/sing-box' option workdir '/usr/share/sing-box'
# list ifaces 'wan'
# list ifaces 'wan6'

View File

@ -3,18 +3,20 @@
USE_PROCD=1 USE_PROCD=1
START=99 START=99
NAME="sing-box" script=$(readlink "$initscript")
NAME="$(basename ${script:-$initscript})"
PROG="/usr/bin/sing-box" PROG="/usr/bin/sing-box"
start_service() { start_service() {
config_load "$NAME" config_load "$NAME"
local enabled user group conffile workdir local enabled user group conffile workdir ifaces
config_get_bool enabled "main" "enabled" "0" config_get_bool enabled "main" "enabled" "0"
[ "$enabled" -eq "1" ] || return 0 [ "$enabled" -eq "1" ] || return 0
config_get user "main" "user" "root" config_get user "main" "user" "root"
config_get conffile "main" "conffile" config_get conffile "main" "conffile"
config_get ifaces "main" "ifaces"
config_get workdir "main" "workdir" "/usr/share/sing-box" config_get workdir "main" "workdir" "/usr/share/sing-box"
mkdir -p "$workdir" mkdir -p "$workdir"
@ -27,6 +29,7 @@ start_service() {
# Use root user if you want to use the TUN mode. # Use root user if you want to use the TUN mode.
procd_set_param user "$user" procd_set_param user "$user"
procd_set_param file "$conffile" procd_set_param file "$conffile"
[ -z "$ifaces" ] || procd_set_param netdev $ifaces
procd_set_param stdout 1 procd_set_param stdout 1
procd_set_param stderr 1 procd_set_param stderr 1
procd_set_param respawn procd_set_param respawn
@ -35,5 +38,13 @@ start_service() {
} }
service_triggers() { 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" procd_add_reload_trigger "$NAME"
} }