mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Split daemon service code to _windows file
This moves some of the code that was conditionally executed on Windows to a separate, windows-only file. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
4460472f4e
commit
cd3e84c6b3
5 changed files with 45 additions and 48 deletions
|
@ -104,10 +104,6 @@ func allocateDaemonPort(addr string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// notifyShutdown is called after the daemon shuts down but before the process exits.
|
|
||||||
func notifyShutdown(err error) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func wrapListeners(proto string, ls []net.Listener) []net.Listener {
|
func wrapListeners(proto string, ls []net.Listener) []net.Listener {
|
||||||
switch proto {
|
switch proto {
|
||||||
case "unix":
|
case "unix":
|
||||||
|
|
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
|
@ -25,6 +24,10 @@ func newDaemonCommand() *cobra.Command {
|
||||||
SilenceErrors: true,
|
SilenceErrors: true,
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if opts.version {
|
||||||
|
showVersion()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
opts.flags = cmd.Flags()
|
opts.flags = cmd.Flags()
|
||||||
return runDaemon(opts)
|
return runDaemon(opts)
|
||||||
},
|
},
|
||||||
|
@ -41,45 +44,6 @@ func newDaemonCommand() *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDaemon(opts *daemonOptions) error {
|
|
||||||
if opts.version {
|
|
||||||
showVersion()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
daemonCli := NewDaemonCli()
|
|
||||||
|
|
||||||
// Windows specific settings as these are not defaulted.
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
if opts.daemonConfig.Pidfile == "" {
|
|
||||||
opts.daemonConfig.Pidfile = filepath.Join(opts.daemonConfig.Root, "docker.pid")
|
|
||||||
}
|
|
||||||
if opts.configFile == "" {
|
|
||||||
opts.configFile = filepath.Join(opts.daemonConfig.Root, `config\daemon.json`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// On Windows, this may be launching as a service or with an option to
|
|
||||||
// register the service.
|
|
||||||
stop, runAsService, err := initService(daemonCli)
|
|
||||||
if err != nil {
|
|
||||||
logrus.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if stop {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// If Windows SCM manages the service - no need for PID files
|
|
||||||
if runAsService {
|
|
||||||
opts.daemonConfig.Pidfile = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
err = daemonCli.start(opts)
|
|
||||||
notifyShutdown(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func showVersion() {
|
func showVersion() {
|
||||||
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
|
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
|
||||||
}
|
}
|
||||||
|
|
8
cmd/dockerd/docker_unix.go
Normal file
8
cmd/dockerd/docker_unix.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func runDaemon(opts *daemonOptions) error {
|
||||||
|
daemonCli := NewDaemonCli()
|
||||||
|
return daemonCli.start(opts)
|
||||||
|
}
|
|
@ -1,5 +1,38 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
_ "github.com/docker/docker/autogen/winresources/dockerd"
|
_ "github.com/docker/docker/autogen/winresources/dockerd"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func runDaemon(opts *daemonOptions) error {
|
||||||
|
daemonCli := NewDaemonCli()
|
||||||
|
|
||||||
|
// On Windows, this may be launching as a service or with an option to
|
||||||
|
// register the service.
|
||||||
|
stop, runAsService, err := initService(daemonCli)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if stop {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Windows specific settings as these are not defaulted.
|
||||||
|
if opts.configFile == "" {
|
||||||
|
opts.configFile = filepath.Join(opts.daemonConfig.Root, `config\daemon.json`)
|
||||||
|
}
|
||||||
|
if runAsService {
|
||||||
|
// If Windows SCM manages the service - no need for PID files
|
||||||
|
opts.daemonConfig.Pidfile = ""
|
||||||
|
} else if opts.daemonConfig.Pidfile == "" {
|
||||||
|
opts.daemonConfig.Pidfile = filepath.Join(opts.daemonConfig.Root, "docker.pid")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = daemonCli.start(opts)
|
||||||
|
notifyShutdown(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -6,9 +6,5 @@ import (
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initService(daemonCli *DaemonCli) (bool, bool, error) {
|
|
||||||
return false, false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func installServiceFlags(flags *pflag.FlagSet) {
|
func installServiceFlags(flags *pflag.FlagSet) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue