github.com/go/docker@v1.12.0-rc2/cmd/dockerd/docker.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/Sirupsen/logrus" 8 "github.com/docker/docker/dockerversion" 9 flag "github.com/docker/docker/pkg/mflag" 10 "github.com/docker/docker/pkg/reexec" 11 "github.com/docker/docker/pkg/term" 12 "github.com/docker/docker/utils" 13 ) 14 15 var ( 16 daemonCli = NewDaemonCli() 17 flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage") 18 flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit") 19 ) 20 21 func main() { 22 if reexec.Init() { 23 return 24 } 25 26 // Set terminal emulation based on platform as required. 27 _, stdout, stderr := term.StdStreams() 28 29 logrus.SetOutput(stderr) 30 31 flag.Merge(flag.CommandLine, daemonCli.commonFlags.FlagSet) 32 33 flag.Usage = func() { 34 fmt.Fprint(stdout, "Usage: dockerd [ --help | -v | --version ]\n\n") 35 fmt.Fprint(stdout, "A self-sufficient runtime for containers.\n\nOptions:\n") 36 37 flag.CommandLine.SetOutput(stdout) 38 flag.PrintDefaults() 39 } 40 flag.CommandLine.ShortUsage = func() { 41 fmt.Fprint(stderr, "\nUsage:\tdockerd [OPTIONS]\n") 42 } 43 44 if err := flag.CommandLine.ParseFlags(os.Args[1:], false); err != nil { 45 os.Exit(1) 46 } 47 48 if *flVersion { 49 showVersion() 50 return 51 } 52 53 if *flHelp { 54 // if global flag --help is present, regardless of what other options and commands there are, 55 // just print the usage. 56 flag.Usage() 57 return 58 } 59 60 // On Windows, this may be launching as a service or with an option to 61 // register the service. 62 stop, err := initService() 63 if err != nil { 64 logrus.Fatal(err) 65 } 66 67 if !stop { 68 err = daemonCli.start() 69 notifyShutdown(err) 70 if err != nil { 71 logrus.Fatal(err) 72 } 73 } 74 } 75 76 func showVersion() { 77 if utils.ExperimentalBuild() { 78 fmt.Printf("Docker version %s, build %s, experimental\n", dockerversion.Version, dockerversion.GitCommit) 79 } else { 80 fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit) 81 } 82 }