github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/cmd/dockerd/docker_windows.go (about)

     1  package main
     2  
     3  import (
     4  	"io"
     5  	"path/filepath"
     6  
     7  	"github.com/Microsoft/go-winio/pkg/etwlogrus"
     8  	_ "github.com/demonoid81/moby/autogen/winresources/dockerd"
     9  	"github.com/sirupsen/logrus"
    10  )
    11  
    12  func runDaemon(opts *daemonOptions) error {
    13  	daemonCli := NewDaemonCli()
    14  
    15  	// On Windows, this may be launching as a service or with an option to
    16  	// register the service.
    17  	stop, runAsService, err := initService(daemonCli)
    18  	if err != nil {
    19  		logrus.Fatal(err)
    20  	}
    21  
    22  	if stop {
    23  		return nil
    24  	}
    25  
    26  	// Windows specific settings as these are not defaulted.
    27  	if opts.configFile == "" {
    28  		opts.configFile = filepath.Join(opts.daemonConfig.Root, `config\daemon.json`)
    29  	}
    30  	if runAsService {
    31  		// If Windows SCM manages the service - no need for PID files
    32  		opts.daemonConfig.Pidfile = ""
    33  	} else if opts.daemonConfig.Pidfile == "" {
    34  		opts.daemonConfig.Pidfile = filepath.Join(opts.daemonConfig.Root, "docker.pid")
    35  	}
    36  
    37  	err = daemonCli.start(opts)
    38  	notifyShutdown(err)
    39  	return err
    40  }
    41  
    42  func initLogging(stdout, _ io.Writer) {
    43  	// Maybe there is a historic reason why on non-Windows, stderr is used
    44  	// for output. However, on Windows it makes no sense and there is no need.
    45  	logrus.SetOutput(stdout)
    46  
    47  	// Provider ID: {6996f090-c5de-5082-a81e-5841acc3a635}
    48  	// Hook isn't closed explicitly, as it will exist until process exit.
    49  	// GUID is generated based on name - see Microsoft/go-winio/tools/etw-provider-gen.
    50  	if hook, err := etwlogrus.NewHook("Moby"); err == nil {
    51  		logrus.AddHook(hook)
    52  	}
    53  	return
    54  }