buildkitd: create buildkitd.lock under root

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
docker-19.03
Akihiro Suda 2019-05-07 18:25:42 +09:00
parent 97b4b9a6db
commit 5225a66020
1 changed files with 15 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"github.com/containerd/containerd/sys"
"github.com/docker/docker/pkg/reexec"
"github.com/docker/go-connections/sockets"
"github.com/gofrs/flock"
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
"github.com/moby/buildkit/cache/remotecache"
inlineremotecache "github.com/moby/buildkit/cache/remotecache/inline"
@ -217,6 +218,20 @@ func main() {
return errors.Wrapf(err, "failed to create %s", root)
}
lockPath := filepath.Join(root, "buildkitd.lock")
lock := flock.New(lockPath)
locked, err := lock.TryLock()
if err != nil {
return errors.Wrapf(err, "could not lock %s", lockPath)
}
if !locked {
return errors.Errorf("could not lock %s, another instance running?", lockPath)
}
defer func() {
lock.Unlock()
os.RemoveAll(lockPath)
}()
controller, err := newController(c, &cfg)
if err != nil {
return err