From 3b374f779537865103ab37ae2d525fd79d5efaa4 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 8 Feb 2026 11:27:18 +0100 Subject: [PATCH] chore: move shutdown to post hook (#27294) --- cmd/cache-clear.go | 3 --- cmd/charger.go | 3 --- cmd/charger_ramp.go | 3 --- cmd/device.go | 3 --- cmd/meter.go | 3 --- cmd/migrate.go | 2 -- cmd/password_reset.go | 3 --- cmd/password_set.go | 3 --- cmd/root.go | 12 +++++++++++- cmd/settings-set.go | 3 --- cmd/tariff.go | 3 --- cmd/vehicle.go | 3 --- 12 files changed, 11 insertions(+), 33 deletions(-) diff --git a/cmd/cache-clear.go b/cmd/cache-clear.go index 84aedd22a..83bd228e7 100644 --- a/cmd/cache-clear.go +++ b/cmd/cache-clear.go @@ -46,7 +46,4 @@ func runCacheClear(cmd *cobra.Command, args []string) { } log.INFO.Println("Cache cleared successfully") } - - // wait for shutdown - <-shutdownDoneC() } diff --git a/cmd/charger.go b/cmd/charger.go index d70b78c5d..a6daf6abd 100644 --- a/cmd/charger.go +++ b/cmd/charger.go @@ -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() } diff --git a/cmd/charger_ramp.go b/cmd/charger_ramp.go index 61d3e7d36..1852964b6 100644 --- a/cmd/charger_ramp.go +++ b/cmd/charger_ramp.go @@ -97,7 +97,4 @@ func runChargerRamp(cmd *cobra.Command, args []string) { } ramp(v, digits, delay) } - - // wait for shutdown - <-shutdownDoneC() } diff --git a/cmd/device.go b/cmd/device.go index 4142de8b2..1f972b52d 100644 --- a/cmd/device.go +++ b/cmd/device.go @@ -50,7 +50,4 @@ func runDevice(cmd *cobra.Command, args []string) { fmt.Println() } } - - // wait for shutdown - <-shutdownDoneC() } diff --git a/cmd/meter.go b/cmd/meter.go index 6d7a133f5..5376b1388 100644 --- a/cmd/meter.go +++ b/cmd/meter.go @@ -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() } diff --git a/cmd/migrate.go b/cmd/migrate.go index ee3b1ede3..ba93873f7 100644 --- a/cmd/migrate.go +++ b/cmd/migrate.go @@ -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() } diff --git a/cmd/password_reset.go b/cmd/password_reset.go index 5493bd956..9073509ed 100644 --- a/cmd/password_reset.go +++ b/cmd/password_reset.go @@ -41,7 +41,4 @@ func runPasswordReset(cmd *cobra.Command, args []string) { if confirm { auth.New().RemoveAdminPassword() } - - // wait for shutdown - <-shutdownDoneC() } diff --git a/cmd/password_set.go b/cmd/password_set.go index 7148934b1..ca327b86d 100644 --- a/cmd/password_set.go +++ b/cmd/password_set.go @@ -43,7 +43,4 @@ func runPasswordSet(cmd *cobra.Command, args []string) { } else { auth.New().SetAdminPassword(password) } - - // wait for shutdown - <-shutdownDoneC() } diff --git a/cmd/root.go b/cmd/root.go index 2f48615e0..e376bd5bd 100644 --- a/cmd/root.go +++ b/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 diff --git a/cmd/settings-set.go b/cmd/settings-set.go index ea2d0420d..c24814279 100644 --- a/cmd/settings-set.go +++ b/cmd/settings-set.go @@ -51,7 +51,4 @@ func runSettingsSet(cmd *cobra.Command, args []string) { if confirmation { settings.SetString(args[0], args[1]) } - - // wait for shutdown - <-shutdownDoneC() } diff --git a/cmd/tariff.go b/cmd/tariff.go index 80e30cc6f..4a65e7eaf 100644 --- a/cmd/tariff.go +++ b/cmd/tariff.go @@ -90,7 +90,4 @@ func runTariff(cmd *cobra.Command, args []string) { fmt.Println() } - - // wait for shutdown - <-shutdownDoneC() } diff --git a/cmd/vehicle.go b/cmd/vehicle.go index 709bcf4e2..eca75a1fc 100644 --- a/cmd/vehicle.go +++ b/cmd/vehicle.go @@ -132,7 +132,4 @@ func runVehicle(cmd *cobra.Command, args []string) { } } } - - // wait for shutdown - <-shutdownDoneC() }