mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-02 07:24:48 +03:00
783e0c5438
At the default log level an operator could see the Xray child PID change many times a day without learning which of those changes the panel caused, or why. Write one xray_lifecycle line for every real start, stop, restart, hot apply, rejected config and unexpected child exit. It carries the old and new PID, the path that asked (manual, watchdog, client depletion, pending restart and its first trigger, ...), a fixed reason, the force flag, the duration, the hot-apply outcome and the previous child's exit code or signal. An unchanged config still emits nothing and restart policy is unchanged. A hot apply the core refuses also logs the core's own error once, with the inbound tag or client it concerned, so a restart labelled hot_apply_failed can be traced to its cause. Fixes #7260
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// XrayOrigin identifies the panel path that initiated a lifecycle operation.
|
|
type XrayOrigin string
|
|
|
|
const (
|
|
XrayOriginManual XrayOrigin = "manual"
|
|
XrayOriginConfigChange XrayOrigin = "config_change"
|
|
XrayOriginPendingRestart XrayOrigin = "pending_restart"
|
|
XrayOriginPanelStartup XrayOrigin = "panel_startup"
|
|
XrayOriginPanelShutdown XrayOrigin = "panel_shutdown"
|
|
XrayOriginWatchdog XrayOrigin = "watchdog"
|
|
XrayOriginClientDepletion XrayOrigin = "client_depletion"
|
|
XrayOriginTrafficAccounting XrayOrigin = "traffic_accounting"
|
|
XrayOriginNodeTrafficSync XrayOrigin = "node_traffic_sync"
|
|
XrayOriginTunnelHealth XrayOrigin = "tunnel_health"
|
|
XrayOriginSignal XrayOrigin = "signal"
|
|
XrayOriginBinaryUpdate XrayOrigin = "binary_update"
|
|
XrayOriginDatabaseRestore XrayOrigin = "database_restore"
|
|
XrayOriginGeodataUpdate XrayOrigin = "geodata_update"
|
|
)
|
|
|
|
type hotApplyOutcome string
|
|
|
|
const (
|
|
hotApplied hotApplyOutcome = "applied"
|
|
hotUnsupported hotApplyOutcome = "unsupported_config"
|
|
hotClientsRemoved hotApplyOutcome = "clients_removed"
|
|
hotAPIUnavailable hotApplyOutcome = "api_unavailable"
|
|
hotFailed hotApplyOutcome = "failed"
|
|
)
|
|
|
|
type hotApplyFailure struct {
|
|
step string
|
|
subject string
|
|
err error
|
|
}
|
|
|
|
// code keeps the lifecycle entry to fixed fields; cause carries the core's own words.
|
|
func (f hotApplyFailure) code() string {
|
|
return status.Code(f.err).String()
|
|
}
|
|
|
|
func (f hotApplyFailure) cause() string {
|
|
if f.subject == "" {
|
|
return fmt.Sprintf("hot apply: %s failed: %v", f.step, f.err)
|
|
}
|
|
return fmt.Sprintf("hot apply: %s %s failed: %v", f.step, f.subject, f.err)
|
|
}
|