github.com/akerouanton/docker@v1.11.0-rc3/docker/daemon_unix.go (about)

     1  // +build daemon,!windows
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"os/signal"
     9  	"syscall"
    10  
    11  	"github.com/Sirupsen/logrus"
    12  	apiserver "github.com/docker/docker/api/server"
    13  	"github.com/docker/docker/daemon"
    14  	"github.com/docker/docker/libcontainerd"
    15  	"github.com/docker/docker/pkg/mflag"
    16  	"github.com/docker/docker/pkg/system"
    17  )
    18  
    19  const defaultDaemonConfigFile = "/etc/docker/daemon.json"
    20  
    21  func setPlatformServerConfig(serverConfig *apiserver.Config, daemonCfg *daemon.Config) *apiserver.Config {
    22  	serverConfig.EnableCors = daemonCfg.EnableCors
    23  	serverConfig.CorsHeaders = daemonCfg.CorsHeaders
    24  
    25  	return serverConfig
    26  }
    27  
    28  // currentUserIsOwner checks whether the current user is the owner of the given
    29  // file.
    30  func currentUserIsOwner(f string) bool {
    31  	if fileInfo, err := system.Stat(f); err == nil && fileInfo != nil {
    32  		if int(fileInfo.UID()) == os.Getuid() {
    33  			return true
    34  		}
    35  	}
    36  	return false
    37  }
    38  
    39  // setDefaultUmask sets the umask to 0022 to avoid problems
    40  // caused by custom umask
    41  func setDefaultUmask() error {
    42  	desiredUmask := 0022
    43  	syscall.Umask(desiredUmask)
    44  	if umask := syscall.Umask(desiredUmask); umask != desiredUmask {
    45  		return fmt.Errorf("failed to set umask: expected %#o, got %#o", desiredUmask, umask)
    46  	}
    47  
    48  	return nil
    49  }
    50  
    51  func getDaemonConfDir() string {
    52  	return "/etc/docker"
    53  }
    54  
    55  // setupConfigReloadTrap configures the USR2 signal to reload the configuration.
    56  func setupConfigReloadTrap(configFile string, flags *mflag.FlagSet, reload func(*daemon.Config)) {
    57  	c := make(chan os.Signal, 1)
    58  	signal.Notify(c, syscall.SIGHUP)
    59  	go func() {
    60  		for range c {
    61  			if err := daemon.ReloadConfiguration(configFile, flags, reload); err != nil {
    62  				logrus.Error(err)
    63  			}
    64  		}
    65  	}()
    66  }
    67  
    68  func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption {
    69  	opts := []libcontainerd.RemoteOption{
    70  		libcontainerd.WithDebugLog(cli.Config.Debug),
    71  	}
    72  	if cli.Config.ContainerdAddr != "" {
    73  		opts = append(opts, libcontainerd.WithRemoteAddr(cli.Config.ContainerdAddr))
    74  	} else {
    75  		opts = append(opts, libcontainerd.WithStartDaemon(true))
    76  	}
    77  	if daemon.UsingSystemd(cli.Config) {
    78  		args := []string{"--systemd-cgroup=true"}
    79  		opts = append(opts, libcontainerd.WithRuntimeArgs(args))
    80  	}
    81  	return opts
    82  }