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:
Sebastiaan van Stijn 2018-03-21 12:57:53 +01:00
parent 4460472f4e
commit cd3e84c6b3
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
5 changed files with 45 additions and 48 deletions

View file

@ -104,10 +104,6 @@ func allocateDaemonPort(addr string) error {
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 {
switch proto {
case "unix":

View file

@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"github.com/docker/docker/cli"
@ -25,6 +24,10 @@ func newDaemonCommand() *cobra.Command {
SilenceErrors: true,
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if opts.version {
showVersion()
return nil
}
opts.flags = cmd.Flags()
return runDaemon(opts)
},
@ -41,45 +44,6 @@ func newDaemonCommand() *cobra.Command {
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() {
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
}

View file

@ -0,0 +1,8 @@
// +build !windows
package main
func runDaemon(opts *daemonOptions) error {
daemonCli := NewDaemonCli()
return daemonCli.start(opts)
}

View file

@ -1,5 +1,38 @@
package main
import (
"path/filepath"
_ "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
}

View file

@ -6,9 +6,5 @@ import (
"github.com/spf13/pflag"
)
func initService(daemonCli *DaemonCli) (bool, bool, error) {
return false, false, nil
}
func installServiceFlags(flags *pflag.FlagSet) {
}