fix: sub updater restart sing-box only if smth updated
This commit is contained in:
3 files changed
+21
-2
No files matched your search
@@ -43,7 +43,10 @@ let
|
||||
${lib.concatMapStrings mkSubscriptionFetchBlock proxyCfg.subscriptions}
|
||||
${runtimeSubscriptionsFetchBlock}
|
||||
|
||||
if [ "$FAILED" -eq 0 ]; then
|
||||
# Only a changed cache: the timer runs this 5 minutes after every switch and daily, and
|
||||
# a restart drops every connection through the proxy, the inbounds' users' included. A
|
||||
# failed subscription keeps its old cache, so the others' changes still apply.
|
||||
if [ "$SUB_CACHE_CHANGED" -eq 1 ]; then
|
||||
${restartActiveConfigConsumersBlock}
|
||||
fi
|
||||
exit "$FAILED"
|
||||
|
||||
@@ -46,10 +46,19 @@ let
|
||||
} "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Set when a fetch leaves a cache different from before, so the update unit restarts the
|
||||
# proxy only for a change: a restart cuts every connection through it.
|
||||
SUB_CACHE_CHANGED=0
|
||||
|
||||
_proxy_suite_commit_subscription_cache() {
|
||||
local tmp="$1" target="$2" tag="$3"
|
||||
if _proxy_suite_valid_subscription_cache "$tmp"; then
|
||||
mv "$tmp" "$target"
|
||||
if [ -f "$target" ] && ${pkgs.diffutils}/bin/cmp -s "$tmp" "$target"; then
|
||||
rm -f "$tmp"
|
||||
else
|
||||
mv "$tmp" "$target"
|
||||
SUB_CACHE_CHANGED=1
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
|
||||
@@ -160,6 +160,13 @@ in
|
||||
assert !(pkgs.lib.hasInfix "SOCKS_WAS_ACTIVE" subscriptionOnlyUpdateScript);
|
||||
true
|
||||
)
|
||||
# ...and only when a cache changed: the timer fires after every switch, and an unchanged
|
||||
# refresh must not cut the proxy's connections.
|
||||
(
|
||||
assert pkgs.lib.hasInfix ''if [ "$SUB_CACHE_CHANGED" -eq 1 ]; then'' subscriptionOnlyUpdateScript;
|
||||
assert pkgs.lib.hasInfix "/bin/cmp -s" subscriptionOnlyUpdateScript;
|
||||
true
|
||||
)
|
||||
(
|
||||
assert pkgs.lib.hasInfix "is-active --quiet proxy-suite-per-app-tun"
|
||||
subscriptionPerAppTunUpdateScript;
|
||||
|
||||
Reference in new issue
Block a user