From bb16c07dc2b114a2e9b0e362da4c54147b7a42a9 Mon Sep 17 00:00:00 2001 From: Kaloyan Raev Date: Fri, 22 Nov 2019 15:57:37 +0200 Subject: [PATCH] storagenode/updater: read identity location from storagenode's config.yaml (#3607) --- cmd/storagenode-updater/windows.go | 20 +++++++++++--------- installer/windows/Product.wxs | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/storagenode-updater/windows.go b/cmd/storagenode-updater/windows.go index b51ea035d..8c9520cca 100644 --- a/cmd/storagenode-updater/windows.go +++ b/cmd/storagenode-updater/windows.go @@ -16,7 +16,10 @@ import ( "os" "time" + "golang.org/x/sync/errgroup" "golang.org/x/sys/windows/svc" + + "storj.io/storj/pkg/process" ) func init() { @@ -55,12 +58,11 @@ func (m *service) Execute(args []string, r <-chan svc.ChangeRequest, changes cha changes <- svc.Status{State: svc.StartPending} - go func() { - err := rootCmd.Execute() - if err != nil { - os.Exit(1) - } - }() + var group errgroup.Group + group.Go(func() error { + process.Exec(rootCmd) + return nil + }) changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} @@ -75,10 +77,10 @@ func (m *service) Execute(args []string, r <-chan svc.ChangeRequest, changes cha case svc.Stop, svc.Shutdown: log.Println("Stop/Shutdown request received.") changes <- svc.Status{State: svc.StopPending} - + // Cancel the command's root context to cleanup resources + _, cancel := process.Ctx(runCmd) cancel() - // Sleep some time to give chance for goroutines finish cleanup after cancelling the context - time.Sleep(3 * time.Second) + _ = group.Wait() // process.Exec does not return an error // After returning the Windows Service is stopped and the process terminates return default: diff --git a/installer/windows/Product.wxs b/installer/windows/Product.wxs index 6a1c54c1f..b6e56d700 100644 --- a/installer/windows/Product.wxs +++ b/installer/windows/Product.wxs @@ -57,7 +57,7 @@ Account="[SERVICEACCOUNT]" Password="[SERVICEPASSWORD]" ErrorControl="normal" - Arguments="run --config-dir "[INSTALLFOLDER]\" --identity-dir "[IDENTITYDIR]\" --binary-location "[INSTALLFOLDER]\storagenode.exe" --log "[INSTALLFOLDER]\storagenode-updater.log""> + Arguments="run --config-dir "[INSTALLFOLDER]\" --binary-location "[INSTALLFOLDER]storagenode.exe" --log "[INSTALLFOLDER]storagenode-updater.log"">