Prune old cgroup directories
Cgroup directories are created per Gitaly process. Old cgroups can lie around
until a box is restarted. Problem is, on some vms like GCP there are metrics
agents like cadvisor
that crawl cgroups for metrics. This can end up being
extremely wasteful. So, we want to prune these directories to clean them up.
Pruning directories is a common operation. Currently it's used for pruning Gitaly runtime directories. However, Cgroup directories are made according to the same convention as Gitaly runtime directories in the form of gitaly-. Instead of reproducing the logic, simply rename the function so it can be reused.
To do this, we also need to encapsulate the logic that constructs the name of a process directory and the logic that parses out the pid from such a directory into functions.
Once this in place, we can call the pruning function to get rid of old cgroups that have been left over from previous processes. If a processes is still running, we leave it alone.