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