Skip to content

Commit

Permalink
Merge pull request moby#31668 from Microsoft/jjh/nopidfileasservice
Browse files Browse the repository at this point in the history
Windows: no pidfile when service
  • Loading branch information
cpuguy83 authored Mar 23, 2017
2 parents c1d40ad + a8e144d commit b47c50c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
7 changes: 6 additions & 1 deletion cmd/dockerd/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func runDaemon(opts daemonOptions) error {

// On Windows, this may be launching as a service or with an option to
// register the service.
stop, err := initService(daemonCli)
stop, runAsService, err := initService(daemonCli)
if err != nil {
logrus.Fatal(err)
}
Expand All @@ -83,6 +83,11 @@ func runDaemon(opts daemonOptions) error {
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
Expand Down
4 changes: 2 additions & 2 deletions cmd/dockerd/service_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/spf13/pflag"
)

func initService(daemonCli *DaemonCli) (bool, error) {
return false, nil
func initService(daemonCli *DaemonCli) (bool, bool, error) {
return false, false, nil
}

func installServiceFlags(flags *pflag.FlagSet) {
Expand Down
21 changes: 12 additions & 9 deletions cmd/dockerd/service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,28 @@ func unregisterService() error {
return nil
}

func initService(daemonCli *DaemonCli) (bool, error) {
// initService is the entry point for running the daemon as a Windows
// service. It returns an indication to stop (if registering/un-registering);
// an indication of whether it is running as a service; and an error.
func initService(daemonCli *DaemonCli) (bool, bool, error) {
if *flUnregisterService {
if *flRegisterService {
return true, errors.New("--register-service and --unregister-service cannot be used together")
return true, false, errors.New("--register-service and --unregister-service cannot be used together")
}
return true, unregisterService()
return true, false, unregisterService()
}

if *flRegisterService {
return true, registerService()
return true, false, registerService()
}

if !*flRunService {
return false, nil
return false, false, nil
}

interactive, err := svc.IsAnInteractiveSession()
if err != nil {
return false, err
return false, false, err
}

h := &handler{
Expand All @@ -285,7 +288,7 @@ func initService(daemonCli *DaemonCli) (bool, error) {
if !interactive {
log, err = eventlog.Open(*flServiceName)
if err != nil {
return false, err
return false, false, err
}
}

Expand All @@ -306,9 +309,9 @@ func initService(daemonCli *DaemonCli) (bool, error) {
// Wait for the first signal from the service handler.
err = <-h.fromsvc
if err != nil {
return false, err
return false, false, err
}
return false, nil
return false, true, nil
}

func (h *handler) started() error {
Expand Down

0 comments on commit b47c50c

Please sign in to comment.