docker.go 1.8 KB

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