diff --git a/http/http.go b/http/http.go index 40c2292..71b42cf 100644 --- a/http/http.go +++ b/http/http.go @@ -80,4 +80,8 @@ func Serve(cfg *config.Config, tkr *tracker.Tracker) { glog.V(0).Info("Starting on ", cfg.Addr) graceful.Run(cfg.Addr, cfg.RequestTimeout.Duration, newRouter(srv)) + err := srv.tracker.Close() + if err != nil { + glog.Errorf("Failed to shutdown tracker cleanly: %s", err.Error()) + } } diff --git a/tracker/tracker.go b/tracker/tracker.go index 0c92456..b4c4b34 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -51,6 +51,21 @@ func New(cfg *config.Config) (*Tracker, error) { }, nil } +// Close gracefully shutdowns a Tracker by closing any database connections. +func (tkr *Tracker) Close() (err error) { + err = tkr.Pool.Close() + if err != nil { + return + } + + err = tkr.backend.Close() + if err != nil { + return + } + + return +} + // Writer serializes a tracker's responses, and is implemented for each // response transport used by the tracker. //