github.com/kunnos/engine@v1.13.1/daemon/debugtrap.go (about)

     1  package daemon
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"strings"
     8  	"time"
     9  
    10  	"github.com/davecgh/go-spew/spew"
    11  	"github.com/pkg/errors"
    12  )
    13  
    14  const dataStructuresLogNameTemplate = "daemon-data-%s.log"
    15  
    16  // dumpDaemon appends the daemon datastructures into file in dir and returns full path
    17  // to that file.
    18  func (d *Daemon) dumpDaemon(dir string) (string, error) {
    19  	// Ensure we recover from a panic as we are doing this without any locking
    20  	defer func() {
    21  		recover()
    22  	}()
    23  
    24  	path := filepath.Join(dir, fmt.Sprintf(dataStructuresLogNameTemplate, strings.Replace(time.Now().Format(time.RFC3339), ":", "", -1)))
    25  	f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
    26  	if err != nil {
    27  		return "", errors.Wrap(err, "failed to open file to write the daemon datastructure dump")
    28  	}
    29  	defer f.Close()
    30  
    31  	dump := struct {
    32  		containers      interface{}
    33  		names           interface{}
    34  		links           interface{}
    35  		execs           interface{}
    36  		volumes         interface{}
    37  		images          interface{}
    38  		layers          interface{}
    39  		imageReferences interface{}
    40  		downloads       interface{}
    41  		uploads         interface{}
    42  		registry        interface{}
    43  		plugins         interface{}
    44  	}{
    45  		containers:      d.containers,
    46  		execs:           d.execCommands,
    47  		volumes:         d.volumes,
    48  		images:          d.imageStore,
    49  		layers:          d.layerStore,
    50  		imageReferences: d.referenceStore,
    51  		downloads:       d.downloadManager,
    52  		uploads:         d.uploadManager,
    53  		registry:        d.RegistryService,
    54  		plugins:         d.PluginStore,
    55  		names:           d.nameIndex,
    56  		links:           d.linkIndex,
    57  	}
    58  
    59  	spew.Fdump(f, dump) // Does not return an error
    60  	f.Sync()
    61  	return path, nil
    62  }