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
|
|
@ -46,7 +46,4 @@ func runCacheClear(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
log.INFO.Println("Cache cleared successfully")
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,7 +142,4 @@ func runCharger(cmd *cobra.Command, args []string) {
|
|||
log.INFO.Println("running heartbeat (if any) until interrupted (Ctrl-C to stop)")
|
||||
time.Sleep(time.Hour)
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,4 @@ func runChargerRamp(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
ramp(v, digits, delay)
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,4 @@ func runDevice(cmd *cobra.Command, args []string) {
|
|||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,4 @@ func runMeter(cmd *cobra.Command, args []string) {
|
|||
log.INFO.Println("running heartbeat (if any) until interrupted (Ctrl-C to stop)")
|
||||
time.Sleep(time.Hour)
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,4 @@ func runMigrate(cmd *cobra.Command, args []string) {
|
|||
// clear config table
|
||||
result := db.Instance.Delete(&config.Config{}, "true")
|
||||
log.INFO.Printf(" %d entries deleted", result.RowsAffected)
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,4 @@ func runPasswordReset(cmd *cobra.Command, args []string) {
|
|||
if confirm {
|
||||
auth.New().RemoveAdminPassword()
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,4 @@ func runPasswordSet(cmd *cobra.Command, args []string) {
|
|||
} else {
|
||||
auth.New().SetAdminPassword(password)
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,4 @@ func runSettingsSet(cmd *cobra.Command, args []string) {
|
|||
if confirmation {
|
||||
settings.SetString(args[0], args[1])
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,4 @@ func runTariff(cmd *cobra.Command, args []string) {
|
|||
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,4 @@ func runVehicle(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// wait for shutdown
|
||||
<-shutdownDoneC()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue