mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 08:31:30 +00:00
Add start and close track message
This commit is contained in:
parent
5bf177b021
commit
e1e217854e
37
box.go
37
box.go
|
@ -203,21 +203,23 @@ func (s *Box) Start() error {
|
||||||
|
|
||||||
func (s *Box) preStart() error {
|
func (s *Box) preStart() error {
|
||||||
for serviceName, service := range s.preServices {
|
for serviceName, service := range s.preServices {
|
||||||
|
s.logger.Trace("pre-start ", serviceName)
|
||||||
err := adapter.PreStart(service)
|
err := adapter.PreStart(service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return E.Cause(err, "pre-start ", serviceName)
|
return E.Cause(err, "pre-starting ", serviceName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, out := range s.outbounds {
|
for i, out := range s.outbounds {
|
||||||
|
var tag string
|
||||||
|
if out.Tag() == "" {
|
||||||
|
tag = F.ToString(i)
|
||||||
|
} else {
|
||||||
|
tag = out.Tag()
|
||||||
|
}
|
||||||
if starter, isStarter := out.(common.Starter); isStarter {
|
if starter, isStarter := out.(common.Starter); isStarter {
|
||||||
|
s.logger.Trace("initializing outbound/", out.Type(), "[", tag, "]")
|
||||||
err := starter.Start()
|
err := starter.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var tag string
|
|
||||||
if out.Tag() == "" {
|
|
||||||
tag = F.ToString(i)
|
|
||||||
} else {
|
|
||||||
tag = out.Tag()
|
|
||||||
}
|
|
||||||
return E.Cause(err, "initialize outbound/", out.Type(), "[", tag, "]")
|
return E.Cause(err, "initialize outbound/", out.Type(), "[", tag, "]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,24 +233,27 @@ func (s *Box) start() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for serviceName, service := range s.preServices {
|
for serviceName, service := range s.preServices {
|
||||||
|
s.logger.Trace("starting ", serviceName)
|
||||||
err = service.Start()
|
err = service.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return E.Cause(err, "start ", serviceName)
|
return E.Cause(err, "start ", serviceName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, in := range s.inbounds {
|
for i, in := range s.inbounds {
|
||||||
|
var tag string
|
||||||
|
if in.Tag() == "" {
|
||||||
|
tag = F.ToString(i)
|
||||||
|
} else {
|
||||||
|
tag = in.Tag()
|
||||||
|
}
|
||||||
|
s.logger.Trace("initializing inbound/", in.Type(), "[", tag, "]")
|
||||||
err = in.Start()
|
err = in.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var tag string
|
|
||||||
if in.Tag() == "" {
|
|
||||||
tag = F.ToString(i)
|
|
||||||
} else {
|
|
||||||
tag = in.Tag()
|
|
||||||
}
|
|
||||||
return E.Cause(err, "initialize inbound/", in.Type(), "[", tag, "]")
|
return E.Cause(err, "initialize inbound/", in.Type(), "[", tag, "]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for serviceName, service := range s.postServices {
|
for serviceName, service := range s.postServices {
|
||||||
|
s.logger.Trace("starting ", service)
|
||||||
err = service.Start()
|
err = service.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return E.Cause(err, "start ", serviceName)
|
return E.Cause(err, "start ", serviceName)
|
||||||
|
@ -266,30 +271,36 @@ func (s *Box) Close() error {
|
||||||
}
|
}
|
||||||
var errors error
|
var errors error
|
||||||
for serviceName, service := range s.postServices {
|
for serviceName, service := range s.postServices {
|
||||||
|
s.logger.Trace("closing ", serviceName)
|
||||||
errors = E.Append(errors, service.Close(), func(err error) error {
|
errors = E.Append(errors, service.Close(), func(err error) error {
|
||||||
return E.Cause(err, "close ", serviceName)
|
return E.Cause(err, "close ", serviceName)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for i, in := range s.inbounds {
|
for i, in := range s.inbounds {
|
||||||
|
s.logger.Trace("closing inbound/", in.Type(), "[", i, "]")
|
||||||
errors = E.Append(errors, in.Close(), func(err error) error {
|
errors = E.Append(errors, in.Close(), func(err error) error {
|
||||||
return E.Cause(err, "close inbound/", in.Type(), "[", i, "]")
|
return E.Cause(err, "close inbound/", in.Type(), "[", i, "]")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for i, out := range s.outbounds {
|
for i, out := range s.outbounds {
|
||||||
|
s.logger.Trace("closing outbound/", out.Type(), "[", i, "]")
|
||||||
errors = E.Append(errors, common.Close(out), func(err error) error {
|
errors = E.Append(errors, common.Close(out), func(err error) error {
|
||||||
return E.Cause(err, "close outbound/", out.Type(), "[", i, "]")
|
return E.Cause(err, "close outbound/", out.Type(), "[", i, "]")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
s.logger.Trace("closing router")
|
||||||
if err := common.Close(s.router); err != nil {
|
if err := common.Close(s.router); err != nil {
|
||||||
errors = E.Append(errors, err, func(err error) error {
|
errors = E.Append(errors, err, func(err error) error {
|
||||||
return E.Cause(err, "close router")
|
return E.Cause(err, "close router")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for serviceName, service := range s.preServices {
|
for serviceName, service := range s.preServices {
|
||||||
|
s.logger.Trace("closing ", serviceName)
|
||||||
errors = E.Append(errors, service.Close(), func(err error) error {
|
errors = E.Append(errors, service.Close(), func(err error) error {
|
||||||
return E.Cause(err, "close ", serviceName)
|
return E.Cause(err, "close ", serviceName)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
s.logger.Trace("closing log factory")
|
||||||
if err := common.Close(s.logFactory); err != nil {
|
if err := common.Close(s.logFactory); err != nil {
|
||||||
errors = E.Append(errors, err, func(err error) error {
|
errors = E.Append(errors, err, func(err error) error {
|
||||||
return E.Cause(err, "close log factory")
|
return E.Cause(err, "close log factory")
|
||||||
|
|
|
@ -489,31 +489,56 @@ func (r *Router) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) Close() error {
|
func (r *Router) Close() error {
|
||||||
for _, rule := range r.rules {
|
var err error
|
||||||
err := rule.Close()
|
for i, rule := range r.rules {
|
||||||
if err != nil {
|
r.logger.Trace("closing rule[", i, "]")
|
||||||
return err
|
err = E.Append(err, rule.Close(), func(err error) error {
|
||||||
}
|
return E.Cause(err, "close rule[", i, "]")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
for _, rule := range r.dnsRules {
|
for i, rule := range r.dnsRules {
|
||||||
err := rule.Close()
|
r.logger.Trace("closing dns rule[", i, "]")
|
||||||
if err != nil {
|
err = E.Append(err, rule.Close(), func(err error) error {
|
||||||
return err
|
return E.Cause(err, "close dns rule[", i, "]")
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
for _, transport := range r.transports {
|
for i, transport := range r.transports {
|
||||||
err := transport.Close()
|
r.logger.Trace("closing transport[", i, "] ")
|
||||||
if err != nil {
|
err = E.Append(err, transport.Close(), func(err error) error {
|
||||||
return err
|
return E.Cause(err, "close dns transport[", i, "]")
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
return common.Close(
|
if r.geositeReader != nil {
|
||||||
common.PtrOrNil(r.geoIPReader),
|
r.logger.Trace("closing geoip reader")
|
||||||
r.interfaceMonitor,
|
err = E.Append(err, common.Close(r.geoIPReader), func(err error) error {
|
||||||
r.networkMonitor,
|
return E.Cause(err, "close geoip reader")
|
||||||
r.packageManager,
|
})
|
||||||
r.timeService,
|
}
|
||||||
)
|
if r.interfaceMonitor != nil {
|
||||||
|
r.logger.Trace("closing interface monitor")
|
||||||
|
err = E.Append(err, r.interfaceMonitor.Close(), func(err error) error {
|
||||||
|
return E.Cause(err, "close interface monitor")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if r.networkMonitor != nil {
|
||||||
|
r.logger.Trace("closing network monitor")
|
||||||
|
err = E.Append(err, r.networkMonitor.Close(), func(err error) error {
|
||||||
|
return E.Cause(err, "close network monitor")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if r.packageManager != nil {
|
||||||
|
r.logger.Trace("closing package manager")
|
||||||
|
err = E.Append(err, r.packageManager.Close(), func(err error) error {
|
||||||
|
return E.Cause(err, "close package manager")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if r.timeService != nil {
|
||||||
|
r.logger.Trace("closing time service")
|
||||||
|
err = E.Append(err, r.timeService.Close(), func(err error) error {
|
||||||
|
return E.Cause(err, "close time service")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) GeoIPReader() *geoip.Reader {
|
func (r *Router) GeoIPReader() *geoip.Reader {
|
||||||
|
|
Loading…
Reference in a new issue