mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-15 17:45:03 +03:00
fix(update): keep Xray-core running until update downloads finish (#7002)
UpdateXray stopped the core before downloading, which also stopped the Panel Traffic Outbound bridge the download needed on servers that reach GitHub only through it, leaving every client offline. The new core is now downloaded, staged and checked with run -test against the current config while the old one serves; only the rename and restart swap it (Windows still stops first). update.sh gets the bridge as XUI_UPDATE_PROXY, installs x-ui.sh from the release archive, and fetches Alpine's x-ui.rc before stopping x-ui.
This commit is contained in:
committed by
GitHub
parent
4d583cebf3
commit
6d9e836d61
@@ -595,6 +595,43 @@ func (p *process) refreshAPIPort() {
|
||||
p.mu.Unlock()
|
||||
}
|
||||
|
||||
// xrayCheckTimeout bounds `run -test`, which loads the config and its geo files but opens
|
||||
// no listeners, so it can run while the live core holds the ports.
|
||||
const xrayCheckTimeout = 30 * time.Second
|
||||
|
||||
// CheckConfig runs the core at binaryPath in test mode against cfg. Updates call it first,
|
||||
// so a core that rejects cfg never replaces the running one.
|
||||
func CheckConfig(binaryPath string, cfg *Config) error {
|
||||
// The test run builds every outbound. A kernel-TUN WireGuard one would add a second wg
|
||||
// device and IPv6 policy rules to the host, and the run exits without removing the rules.
|
||||
checked := *cfg
|
||||
checked.OutboundConfigs, _ = ForceUserspaceWireGuardTun(cfg.OutboundConfigs)
|
||||
data, err := json.Marshal(&checked)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// CreateTemp creates the file as 0600; the config holds client credentials.
|
||||
file, err := os.CreateTemp(filepath.Dir(binaryPath), ".config-check-*.json")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
_, err = file.Write(data)
|
||||
if closeErr := file.Close(); err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), xrayCheckTimeout)
|
||||
defer cancel()
|
||||
out, err := exec.CommandContext(ctx, binaryPath, "run", "-test", "-c", file.Name()).CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", err, bytes.TrimSpace(out))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// refreshVersion updates the version string by running the Xray binary with -version.
|
||||
func (p *process) refreshVersion() {
|
||||
version := "Unknown"
|
||||
|
||||
Reference in New Issue
Block a user