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