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