1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #31668 from Microsoft/jjh/nopidfileasservice

Windows: no pidfile when service
This commit is contained in:
Brian Goff 2017-03-23 17:10:35 -04:00 committed by GitHub
commit b47c50cf11
3 changed files with 20 additions and 12 deletions

View file

@ -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)
}
@ -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

View file

@ -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) {

View file

@ -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{
@ -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
}
}
@ -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 {