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