diff options
author | John Cai <jcai@gitlab.com> | 2022-07-26 22:09:36 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2022-08-18 16:43:51 +0300 |
commit | a604a87cb957c31c2a4d994c327d68c75317bdf6 (patch) | |
tree | abb7161c385d0c99819127a3448361b05ec82699 | |
parent | ca14762eea2a8a2b1eb64f218502653a2c2fb1a6 (diff) |
gitaly: Prune old cgroup directories on startupjc-cleanup-cgroups
Attempt to prune old cgroups directories on startup. On shutdown, we
attempt to clean the cgroups. However, this code is far down. Move it closer so
it's easier to follow.
-rw-r--r-- | cmd/gitaly/main.go | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/cmd/gitaly/main.go b/cmd/gitaly/main.go index 9a276607f..ce2e4d11d 100644 --- a/cmd/gitaly/main.go +++ b/cmd/gitaly/main.go @@ -117,10 +117,6 @@ func configure(configPath string) (config.Cfg, error) { glog.Configure(glog.Loggers, cfg.Logging.Format, cfg.Logging.Level) - if err := cgroups.NewManager(cfg.Cgroups, os.Getpid()).Setup(); err != nil { - return config.Cfg{}, fmt.Errorf("failed setting up cgroups: %w", err) - } - sentry.ConfigureSentry(version.GetVersion(), sentry.Config(cfg.Logging.Sentry)) cfg.Prometheus.Configure() tracing.Initialize(tracing.WithServiceName("gitaly")) @@ -155,6 +151,23 @@ func run(cfg config.Cfg) error { } cfg.RuntimeDir = runtimeDir + // When cgroups are configured, we create a directory structure each + // time a gitaly process is spawned. Look through the hierarchy root + // to find any cgroup directories that belong to old gitaly processes + // and remove them. + cgroups.PruneOldCgroups(cfg.Cgroups, log.StandardLogger()) + cgroupMgr := cgroups.NewManager(cfg.Cgroups, os.Getpid()) + + if err := cgroupMgr.Setup(); err != nil { + return fmt.Errorf("failed setting up cgroups: %w", err) + } + + defer func() { + if err := cgroupMgr.Cleanup(); err != nil { + log.WithError(err).Warn("error cleaning up cgroups") + } + }() + defer func() { if err := os.RemoveAll(cfg.RuntimeDir); err != nil { log.Warn("could not clean up runtime dir") @@ -375,12 +388,6 @@ func run(cfg config.Cfg) error { } defer shutdownWorkers() - defer func() { - if err := cgroups.NewManager(cfg.Cgroups, os.Getpid()).Cleanup(); err != nil { - log.WithError(err).Warn("error cleaning up cgroups") - } - }() - gracefulStopTicker := helper.NewTimerTicker(cfg.GracefulRestartTimeout.Duration()) defer gracefulStopTicker.Stop() |