chore: move shutdown to post hook (#27294)
This commit is contained in:
parent
ccf30688d9
commit
3b374f7795
12 changed files with 11 additions and 33 deletions
12
cmd/root.go
12
cmd/root.go
|
|
@ -65,7 +65,8 @@ var rootCmd = &cobra.Command{
|
|||
Version: util.FormattedVersion(),
|
||||
Run: runRoot,
|
||||
// always allow Ctrl-C in child commands
|
||||
PersistentPreRun: allowCtrlC,
|
||||
PersistentPreRun: allowCtrlC,
|
||||
PersistentPostRun: awaitShutdown,
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
@ -151,6 +152,15 @@ func allowCtrlC(cmd *cobra.Command, args []string) {
|
|||
}()
|
||||
}
|
||||
|
||||
func awaitShutdown(cmd *cobra.Command, args []string) {
|
||||
if cmd.Name() == rootName {
|
||||
return
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
||||
func runRoot(cmd *cobra.Command, args []string) {
|
||||
runAsService = true
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue