56dbe7738d
Commit 3cf89633e9
is changed how the cobra subcommands are created for storagenode (with prefering local variables instead of package level variables).
However, there is a bug which makes it impossible to restart Storagenode services on Windows: the refactored code creates the rootCmd/runCmd twice: therefore the ctx of the running process is not exactly the same as the ctx which supposed to be stopped / cancelled.
This patch fixes this problem with re-using exising, initialized command instead of creating a new one for cancellation.
Fixes: https://github.com/storj/storj/issues/5845
Change-Id: Ib8a4b80d4574e448f65c8558e927c0908c9c5eed
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
// Copyright (C) 2020 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"storj.io/private/process"
|
|
_ "storj.io/storj/private/version" // This attaches version information during release builds.
|
|
"storj.io/storj/storagenode/pieces/lazyfilewalker"
|
|
)
|
|
|
|
func main() {
|
|
process.SetHardcodedApplicationName("storagenode")
|
|
|
|
allowDefaults := !isFilewalkerCommand()
|
|
rootCmd, _ := newRootCmd(allowDefaults)
|
|
|
|
if startAsService(rootCmd) {
|
|
return
|
|
}
|
|
|
|
loggerFunc := func(logger *zap.Logger) *zap.Logger {
|
|
return logger.With(zap.String("process", rootCmd.Use))
|
|
}
|
|
|
|
process.ExecWithCustomOptions(rootCmd, process.ExecOptions{
|
|
InitDefaultDebugServer: allowDefaults,
|
|
InitTracing: allowDefaults,
|
|
InitProfiler: allowDefaults,
|
|
LoggerFactory: loggerFunc,
|
|
LoadConfig: process.LoadConfig,
|
|
})
|
|
}
|
|
|
|
func isFilewalkerCommand() bool {
|
|
return len(os.Args) > 1 && (os.Args[1] == lazyfilewalker.UsedSpaceFilewalkerCmdName || os.Args[1] == lazyfilewalker.GCFilewalkerCmdName)
|
|
}
|