2013-01-19 19:07:19 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-04-10 06:24:15 -04:00
|
|
|
"fmt"
|
2016-08-03 12:20:46 -04:00
|
|
|
"os"
|
2016-10-17 14:48:51 -04:00
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
2014-02-01 06:38:39 -05:00
|
|
|
|
2015-03-26 18:22:04 -04:00
|
|
|
"github.com/Sirupsen/logrus"
|
2016-06-21 16:42:47 -04:00
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
cliflags "github.com/docker/docker/cli/flags"
|
|
|
|
"github.com/docker/docker/daemon"
|
2015-11-09 13:32:46 -05:00
|
|
|
"github.com/docker/docker/dockerversion"
|
2014-10-30 08:48:30 -04:00
|
|
|
"github.com/docker/docker/pkg/reexec"
|
2015-01-23 20:33:49 -05:00
|
|
|
"github.com/docker/docker/pkg/term"
|
2016-06-21 16:42:47 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/pflag"
|
2013-01-24 02:14:46 -05:00
|
|
|
)
|
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
type daemonOptions struct {
|
|
|
|
version bool
|
|
|
|
configFile string
|
|
|
|
daemonConfig *daemon.Config
|
|
|
|
common *cliflags.CommonOptions
|
|
|
|
flags *pflag.FlagSet
|
|
|
|
}
|
2016-02-19 17:42:51 -05:00
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
func newDaemonCommand() *cobra.Command {
|
|
|
|
opts := daemonOptions{
|
|
|
|
daemonConfig: daemon.NewConfig(),
|
|
|
|
common: cliflags.NewCommonOptions(),
|
2015-03-19 21:07:56 -04:00
|
|
|
}
|
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "dockerd [OPTIONS]",
|
|
|
|
Short: "A self-sufficient runtime for containers.",
|
|
|
|
SilenceUsage: true,
|
|
|
|
SilenceErrors: true,
|
|
|
|
Args: cli.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
opts.flags = cmd.Flags()
|
|
|
|
return runDaemon(opts)
|
|
|
|
},
|
2015-05-07 12:49:07 -04:00
|
|
|
}
|
2016-06-23 11:25:51 -04:00
|
|
|
cli.SetupRootCommand(cmd)
|
2015-05-07 12:49:07 -04:00
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
flags := cmd.Flags()
|
|
|
|
flags.BoolVarP(&opts.version, "version", "v", false, "Print version information and quit")
|
|
|
|
flags.StringVar(&opts.configFile, flagDaemonConfigFile, defaultDaemonConfigFile, "Daemon configuration file")
|
|
|
|
opts.common.InstallFlags(flags)
|
|
|
|
opts.daemonConfig.InstallFlags(flags)
|
2016-06-22 18:36:51 -04:00
|
|
|
installServiceFlags(flags)
|
2015-05-05 00:18:28 -04:00
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
return cmd
|
|
|
|
}
|
2014-06-27 09:55:20 -04:00
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
func runDaemon(opts daemonOptions) error {
|
|
|
|
if opts.version {
|
|
|
|
showVersion()
|
|
|
|
return nil
|
2014-08-01 13:34:06 -04:00
|
|
|
}
|
2016-04-22 20:16:14 -04:00
|
|
|
|
2016-08-03 12:20:46 -04:00
|
|
|
daemonCli := NewDaemonCli()
|
|
|
|
|
2016-10-17 14:48:51 -04:00
|
|
|
// On Windows, if there's no explicit pidfile set, set to under the daemon root
|
|
|
|
if runtime.GOOS == "windows" && opts.daemonConfig.Pidfile == "" {
|
|
|
|
opts.daemonConfig.Pidfile = filepath.Join(opts.daemonConfig.Root, "docker.pid")
|
|
|
|
}
|
|
|
|
|
2016-04-22 20:16:14 -04:00
|
|
|
// On Windows, this may be launching as a service or with an option to
|
|
|
|
// register the service.
|
2016-08-03 12:20:46 -04:00
|
|
|
stop, err := initService(daemonCli)
|
2016-04-22 20:16:14 -04:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
if stop {
|
|
|
|
return nil
|
2016-04-22 20:16:14 -04:00
|
|
|
}
|
2016-06-21 16:42:47 -04:00
|
|
|
|
2016-08-03 12:20:46 -04:00
|
|
|
err = daemonCli.start(opts)
|
2016-06-21 16:42:47 -04:00
|
|
|
notifyShutdown(err)
|
|
|
|
return err
|
2013-03-13 03:29:40 -04:00
|
|
|
}
|
|
|
|
|
2013-08-06 23:51:12 -04:00
|
|
|
func showVersion() {
|
2016-10-06 10:09:54 -04:00
|
|
|
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
|
2013-08-06 23:51:12 -04:00
|
|
|
}
|
2016-06-21 16:42:47 -04:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
if reexec.Init() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set terminal emulation based on platform as required.
|
|
|
|
_, stdout, stderr := term.StdStreams()
|
|
|
|
logrus.SetOutput(stderr)
|
|
|
|
|
|
|
|
cmd := newDaemonCommand()
|
|
|
|
cmd.SetOutput(stdout)
|
|
|
|
if err := cmd.Execute(); err != nil {
|
2016-08-03 12:20:46 -04:00
|
|
|
fmt.Fprintf(stderr, "%s\n", err)
|
|
|
|
os.Exit(1)
|
2016-06-21 16:42:47 -04:00
|
|
|
}
|
|
|
|
}
|