Skip to content

Commit 722356e

Browse files
committed
Use hot-reload for secret and limit changes instead of container restart
Secret add/remove/rotate/toggle, limit changes, batch operations, and ad-tag changes now rewrite config.toml and let the engine's built-in hot-reload pick up changes. Zero downtime, no dropped connections. Port, domain, resource, masking, and proxy protocol changes still require a full container restart.
1 parent 25302a1 commit 722356e

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

mtproxymax.sh

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,9 +1626,9 @@ secret_add() {
16261626
# Save
16271627
save_secrets
16281628

1629-
# Restart if running (run_proxy_container regenerates config)
1630-
if [ "$no_restart" != "true" ] && is_proxy_running; then
1631-
restart_proxy_container
1629+
# Hot-reload config (no restart, no dropped connections)
1630+
if [ "$no_restart" != "true" ]; then
1631+
reload_proxy_config
16321632
fi
16331633

16341634
local full_secret
@@ -1708,8 +1708,8 @@ secret_remove() {
17081708

17091709
save_secrets
17101710

1711-
if [ "$no_restart" != "true" ] && is_proxy_running; then
1712-
restart_proxy_container
1711+
if [ "$no_restart" != "true" ]; then
1712+
reload_proxy_config
17131713
fi
17141714

17151715
log_success "Secret '${label}' removed"
@@ -1737,9 +1737,9 @@ secret_add_batch() {
17371737
fi
17381738
done
17391739

1740-
# Single restart after all additions
1741-
if [ "$no_restart" != "true" ] && [ $added -gt 0 ] && is_proxy_running; then
1742-
restart_proxy_container
1740+
# Single hot-reload after all additions
1741+
if [ "$no_restart" != "true" ] && [ $added -gt 0 ]; then
1742+
reload_proxy_config
17431743
fi
17441744

17451745
echo ""
@@ -1794,9 +1794,9 @@ secret_remove_batch() {
17941794
fi
17951795
done
17961796

1797-
# Single restart after all removals
1798-
if [ "$no_restart" != "true" ] && [ $removed -gt 0 ] && is_proxy_running; then
1799-
restart_proxy_container
1797+
# Single hot-reload after all removals
1798+
if [ "$no_restart" != "true" ] && [ $removed -gt 0 ]; then
1799+
reload_proxy_config
18001800
fi
18011801

18021802
echo ""
@@ -1885,10 +1885,7 @@ secret_rotate() {
18851885
SECRETS_CREATED[$idx]="$(date +%s)"
18861886

18871887
save_secrets
1888-
1889-
if is_proxy_running; then
1890-
restart_proxy_container
1891-
fi
1888+
reload_proxy_config
18921889

18931890
local full_secret
18941891
full_secret=$(build_faketls_secret "$new_secret")
@@ -1956,10 +1953,7 @@ secret_toggle() {
19561953
fi
19571954

19581955
save_secrets
1959-
1960-
if is_proxy_running; then
1961-
restart_proxy_container
1962-
fi
1956+
reload_proxy_config
19631957

19641958
log_success "Secret '${label}' is now ${SECRETS_ENABLED[$idx]}"
19651959
}
@@ -2055,8 +2049,8 @@ secret_set_limits() {
20552049

20562050
save_secrets
20572051

2058-
if [ "$no_restart" != "true" ] && is_proxy_running; then
2059-
restart_proxy_container
2052+
if [ "$no_restart" != "true" ]; then
2053+
reload_proxy_config
20602054
fi
20612055

20622056
log_success "Limits updated for '${label}'"
@@ -2558,6 +2552,16 @@ restart_proxy_container() {
25582552
run_proxy_container
25592553
}
25602554

2555+
# Hot-reload: rewrite config.toml and let the engine pick it up (no restart, no dropped connections)
2556+
# Use this for secret/limit changes. Falls back to restart if container is not running.
2557+
reload_proxy_config() {
2558+
if ! is_proxy_running; then
2559+
return 0
2560+
fi
2561+
generate_telemt_config || { log_error "Config generation failed"; return 1; }
2562+
log_info "Config reloaded (hot-reload, no restart)"
2563+
}
2564+
25612565
# Parse ISO 8601 timestamp to epoch (portable: GNU date, busybox date, Python fallback)
25622566
_iso_to_epoch() {
25632567
local ts="$1"
@@ -4739,7 +4743,7 @@ cli_main() {
47394743
AD_TAG="$2"
47404744
save_settings
47414745
log_success "Ad-tag set"
4742-
is_proxy_running && { load_secrets; restart_proxy_container; }
4746+
load_secrets; reload_proxy_config
47434747
else
47444748
log_error "Ad-tag must be 32 hex characters"
47454749
return 1
@@ -4750,7 +4754,7 @@ cli_main() {
47504754
AD_TAG=""
47514755
save_settings
47524756
log_success "Ad-tag removed"
4753-
is_proxy_running && { load_secrets; restart_proxy_container; }
4757+
load_secrets; reload_proxy_config
47544758
;;
47554759
view|"")
47564760
if [ -n "$AD_TAG" ]; then
@@ -5591,11 +5595,7 @@ show_settings_menu() {
55915595
log_error "Invalid ad-tag (must be 32 hex characters)"
55925596
press_any_key; continue
55935597
fi
5594-
if is_proxy_running; then
5595-
echo -en " ${DIM}Restart proxy now? [Y/n]:${NC} "
5596-
local r; read -r r
5597-
[[ ! "$r" =~ ^[nN] ]] && { load_secrets; restart_proxy_container || true; }
5598-
fi
5598+
load_secrets; reload_proxy_config
55995599
press_any_key
56005600
;;
56015601
7)

0 commit comments

Comments
 (0)