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