2015-05-15 19:34:26 -04:00
|
|
|
// +build daemon,!windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-06-15 09:36:19 -04:00
|
|
|
"fmt"
|
2015-05-15 19:34:26 -04:00
|
|
|
"os"
|
2015-12-10 18:35:10 -05:00
|
|
|
"os/signal"
|
2015-06-15 09:36:19 -04:00
|
|
|
"syscall"
|
2015-05-15 19:34:26 -04:00
|
|
|
|
2016-02-18 16:55:03 -05:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-05-15 19:34:26 -04:00
|
|
|
apiserver "github.com/docker/docker/api/server"
|
|
|
|
"github.com/docker/docker/daemon"
|
2016-03-18 14:50:19 -04:00
|
|
|
"github.com/docker/docker/libcontainerd"
|
2015-12-10 18:35:10 -05:00
|
|
|
"github.com/docker/docker/pkg/mflag"
|
2015-05-15 19:34:26 -04:00
|
|
|
"github.com/docker/docker/pkg/system"
|
|
|
|
)
|
|
|
|
|
2015-12-10 18:35:10 -05:00
|
|
|
const defaultDaemonConfigFile = "/etc/docker/daemon.json"
|
|
|
|
|
2015-07-21 01:15:44 -04:00
|
|
|
func setPlatformServerConfig(serverConfig *apiserver.Config, daemonCfg *daemon.Config) *apiserver.Config {
|
2015-07-16 17:14:58 -04:00
|
|
|
serverConfig.EnableCors = daemonCfg.EnableCors
|
|
|
|
serverConfig.CorsHeaders = daemonCfg.CorsHeaders
|
|
|
|
|
2015-05-15 19:34:26 -04:00
|
|
|
return serverConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// currentUserIsOwner checks whether the current user is the owner of the given
|
|
|
|
// file.
|
|
|
|
func currentUserIsOwner(f string) bool {
|
|
|
|
if fileInfo, err := system.Stat(f); err == nil && fileInfo != nil {
|
2015-07-28 12:13:12 -04:00
|
|
|
if int(fileInfo.UID()) == os.Getuid() {
|
2015-05-15 19:34:26 -04:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2015-06-15 09:36:19 -04:00
|
|
|
|
|
|
|
// setDefaultUmask sets the umask to 0022 to avoid problems
|
|
|
|
// caused by custom umask
|
|
|
|
func setDefaultUmask() error {
|
|
|
|
desiredUmask := 0022
|
|
|
|
syscall.Umask(desiredUmask)
|
|
|
|
if umask := syscall.Umask(desiredUmask); umask != desiredUmask {
|
|
|
|
return fmt.Errorf("failed to set umask: expected %#o, got %#o", desiredUmask, umask)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2015-07-30 15:39:19 -04:00
|
|
|
|
|
|
|
func getDaemonConfDir() string {
|
|
|
|
return "/etc/docker"
|
|
|
|
}
|
2015-12-10 18:35:10 -05:00
|
|
|
|
|
|
|
// setupConfigReloadTrap configures the USR2 signal to reload the configuration.
|
|
|
|
func setupConfigReloadTrap(configFile string, flags *mflag.FlagSet, reload func(*daemon.Config)) {
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, syscall.SIGHUP)
|
|
|
|
go func() {
|
|
|
|
for range c {
|
2016-02-18 16:55:03 -05:00
|
|
|
if err := daemon.ReloadConfiguration(configFile, flags, reload); err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
}
|
2015-12-10 18:35:10 -05:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption {
|
|
|
|
opts := []libcontainerd.RemoteOption{
|
|
|
|
libcontainerd.WithDebugLog(cli.Config.Debug),
|
|
|
|
}
|
|
|
|
if cli.Config.ContainerdAddr != "" {
|
|
|
|
opts = append(opts, libcontainerd.WithRemoteAddr(cli.Config.ContainerdAddr))
|
|
|
|
} else {
|
|
|
|
opts = append(opts, libcontainerd.WithStartDaemon(true))
|
|
|
|
}
|
|
|
|
return opts
|
|
|
|
}
|