2013-01-19 19:07:19 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-04-10 06:24:15 -04:00
|
|
|
"fmt"
|
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"
|
2015-05-28 20:59:07 -04:00
|
|
|
"github.com/docker/docker/utils"
|
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-21 16:42:47 -04:00
|
|
|
// TODO: SetUsageTemplate, SetHelpTemplate, SetFlagErrorFunc
|
2015-05-07 12:49:07 -04:00
|
|
|
|
2016-06-21 16:42:47 -04:00
|
|
|
flags := cmd.Flags()
|
|
|
|
flags.BoolP("help", "h", false, "Print usage")
|
|
|
|
flags.MarkShorthandDeprecated("help", "please use --help")
|
|
|
|
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)
|
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
|
|
|
|
|
|
|
// On Windows, this may be launching as a service or with an option to
|
|
|
|
// register the service.
|
|
|
|
stop, err := initService()
|
|
|
|
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
|
|
|
|
|
|
|
err = NewDaemonCli().start(opts)
|
|
|
|
notifyShutdown(err)
|
|
|
|
return err
|
2013-03-13 03:29:40 -04:00
|
|
|
}
|
|
|
|
|
2013-08-06 23:51:12 -04:00
|
|
|
func showVersion() {
|
2015-05-28 20:59:07 -04:00
|
|
|
if utils.ExperimentalBuild() {
|
2015-11-09 13:32:46 -05:00
|
|
|
fmt.Printf("Docker version %s, build %s, experimental\n", dockerversion.Version, dockerversion.GitCommit)
|
2015-05-28 20:59:07 -04:00
|
|
|
} else {
|
2015-11-09 13:32:46 -05:00
|
|
|
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
|
2015-05-28 20:59:07 -04:00
|
|
|
}
|
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 {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|