chore: move shutdown to post hook (#27294)

This commit is contained in:
andig 2026-02-08 11:27:18 +01:00 • committed by GitHub
parent ccf30688d9
commit 3b374f7795
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 11 additions and 33 deletions

View file

@ -46,7 +46,4 @@ func runCacheClear(cmd *cobra.Command, args []string) {
} }
log.INFO.Println("Cache cleared successfully") log.INFO.Println("Cache cleared successfully")
} }
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -142,7 +142,4 @@ func runCharger(cmd *cobra.Command, args []string) {
log.INFO.Println("running heartbeat (if any) until interrupted (Ctrl-C to stop)") log.INFO.Println("running heartbeat (if any) until interrupted (Ctrl-C to stop)")
time.Sleep(time.Hour) time.Sleep(time.Hour)
} }
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -97,7 +97,4 @@ func runChargerRamp(cmd *cobra.Command, args []string) {
} }
ramp(v, digits, delay) ramp(v, digits, delay)
} }
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -50,7 +50,4 @@ func runDevice(cmd *cobra.Command, args []string) {
fmt.Println() fmt.Println()
} }
} }
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -96,7 +96,4 @@ func runMeter(cmd *cobra.Command, args []string) {
log.INFO.Println("running heartbeat (if any) until interrupted (Ctrl-C to stop)") log.INFO.Println("running heartbeat (if any) until interrupted (Ctrl-C to stop)")
time.Sleep(time.Hour) time.Sleep(time.Hour)
} }
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -80,6 +80,4 @@ func runMigrate(cmd *cobra.Command, args []string) {
// clear config table // clear config table
result := db.Instance.Delete(&config.Config{}, "true") result := db.Instance.Delete(&config.Config{}, "true")
log.INFO.Printf(" %d entries deleted", result.RowsAffected) log.INFO.Printf(" %d entries deleted", result.RowsAffected)
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -41,7 +41,4 @@ func runPasswordReset(cmd *cobra.Command, args []string) {
if confirm { if confirm {
auth.New().RemoveAdminPassword() auth.New().RemoveAdminPassword()
} }
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -43,7 +43,4 @@ func runPasswordSet(cmd *cobra.Command, args []string) {
} else { } else {
auth.New().SetAdminPassword(password) auth.New().SetAdminPassword(password)
} }
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -65,7 +65,8 @@ var rootCmd = &cobra.Command{
Version: util.FormattedVersion(), Version: util.FormattedVersion(),
Run: runRoot, Run: runRoot,
// always allow Ctrl-C in child commands // always allow Ctrl-C in child commands
PersistentPreRun: allowCtrlC, PersistentPreRun: allowCtrlC,
PersistentPostRun: awaitShutdown,
} }
func init() { 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) { func runRoot(cmd *cobra.Command, args []string) {
runAsService = true runAsService = true

View file

@ -51,7 +51,4 @@ func runSettingsSet(cmd *cobra.Command, args []string) {
if confirmation { if confirmation {
settings.SetString(args[0], args[1]) settings.SetString(args[0], args[1])
} }
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -90,7 +90,4 @@ func runTariff(cmd *cobra.Command, args []string) {
fmt.Println() fmt.Println()
} }
// wait for shutdown
<-shutdownDoneC()
} }

View file

@ -132,7 +132,4 @@ func runVehicle(cmd *cobra.Command, args []string) {
} }
} }
} }
// wait for shutdown
<-shutdownDoneC()
} }