2013-01-20 04:07:19 +04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-04-10 14:24:15 +04:00
|
|
|
"fmt"
|
2014-02-01 15:38:39 +04:00
|
|
|
"os"
|
|
|
|
|
2015-03-27 01:22:04 +03:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-11-09 21:32:46 +03:00
|
|
|
"github.com/docker/docker/dockerversion"
|
2014-07-25 02:19:50 +04:00
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
2014-10-30 15:48:30 +03:00
|
|
|
"github.com/docker/docker/pkg/reexec"
|
2015-01-24 04:33:49 +03:00
|
|
|
"github.com/docker/docker/pkg/term"
|
2015-05-29 03:59:07 +03:00
|
|
|
"github.com/docker/docker/utils"
|
2013-01-24 11:14:46 +04:00
|
|
|
)
|
|
|
|
|
2016-02-20 01:42:51 +03:00
|
|
|
var (
|
|
|
|
daemonCli = NewDaemonCli()
|
|
|
|
flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage")
|
|
|
|
flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
|
|
|
|
)
|
|
|
|
|
2013-01-20 04:07:19 +04:00
|
|
|
func main() {
|
2015-03-20 04:07:56 +03:00
|
|
|
if reexec.Init() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-06 03:41:48 +03:00
|
|
|
// Set terminal emulation based on platform as required.
|
2016-02-20 01:42:51 +03:00
|
|
|
_, stdout, stderr := term.StdStreams()
|
2015-03-06 03:41:48 +03:00
|
|
|
|
2015-05-05 07:18:28 +03:00
|
|
|
logrus.SetOutput(stderr)
|
2015-03-06 03:41:48 +03:00
|
|
|
|
2016-02-20 01:42:51 +03:00
|
|
|
flag.Merge(flag.CommandLine, daemonCli.commonFlags.FlagSet)
|
2013-10-05 06:25:15 +04:00
|
|
|
|
2015-05-05 07:18:28 +03:00
|
|
|
flag.Usage = func() {
|
2016-07-16 02:52:59 +03:00
|
|
|
fmt.Fprint(stdout, "Usage: dockerd [OPTIONS]\n\n")
|
2015-12-30 13:24:02 +03:00
|
|
|
fmt.Fprint(stdout, "A self-sufficient runtime for containers.\n\nOptions:\n")
|
2014-10-01 17:07:24 +04:00
|
|
|
|
2015-12-30 13:24:02 +03:00
|
|
|
flag.CommandLine.SetOutput(stdout)
|
2015-05-05 07:18:28 +03:00
|
|
|
flag.PrintDefaults()
|
2016-02-20 01:42:51 +03:00
|
|
|
}
|
|
|
|
flag.CommandLine.ShortUsage = func() {
|
|
|
|
fmt.Fprint(stderr, "\nUsage:\tdockerd [OPTIONS]\n")
|
2015-05-07 19:49:07 +03:00
|
|
|
}
|
|
|
|
|
2016-02-20 01:42:51 +03:00
|
|
|
if err := flag.CommandLine.ParseFlags(os.Args[1:], false); err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2015-05-05 07:18:28 +03:00
|
|
|
|
|
|
|
if *flVersion {
|
|
|
|
showVersion()
|
2014-08-01 21:34:06 +04:00
|
|
|
return
|
2014-06-27 17:55:20 +04:00
|
|
|
}
|
|
|
|
|
2015-05-05 07:18:28 +03:00
|
|
|
if *flHelp {
|
|
|
|
// if global flag --help is present, regardless of what other options and commands there are,
|
|
|
|
// just print the usage.
|
|
|
|
flag.Usage()
|
|
|
|
return
|
2014-08-01 21:34:06 +04:00
|
|
|
}
|
2016-04-23 03:16:14 +03: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)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !stop {
|
|
|
|
err = daemonCli.start()
|
|
|
|
notifyShutdown(err)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 11:29:40 +04:00
|
|
|
}
|
|
|
|
|
2013-08-07 07:51:12 +04:00
|
|
|
func showVersion() {
|
2015-05-29 03:59:07 +03:00
|
|
|
if utils.ExperimentalBuild() {
|
2015-11-09 21:32:46 +03:00
|
|
|
fmt.Printf("Docker version %s, build %s, experimental\n", dockerversion.Version, dockerversion.GitCommit)
|
2015-05-29 03:59:07 +03:00
|
|
|
} else {
|
2015-11-09 21:32:46 +03:00
|
|
|
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
|
2015-05-29 03:59:07 +03:00
|
|
|
}
|
2013-08-07 07:51:12 +04:00
|
|
|
}
|