mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
- Add entry/exit logging to all ServiceCommand methods (start, stop, status, reload, restart, uninstall) - Replace mainLog.Load() calls with consistent logger variable usage throughout - Capitalize all logging messages for better readability - Add error context logging for service manager initialization failures - Add debug logging for key operations (restart sequence, cleanup, validation) - Improve error handling with proper error context in all service commands - Add completion logging to track command execution flow This improves debugging capabilities and provides better operational visibility for service management operations while maintaining clean user-facing messages.
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
|
|
"github.com/kardianos/service"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// Stop implements the logic from cmdStop.Run
|
|
func (sc *ServiceCommand) Stop(cmd *cobra.Command, args []string) error {
|
|
logger := mainLog.Load()
|
|
logger.Debug().Msg("Service stop command started")
|
|
|
|
readConfig(false)
|
|
v.Unmarshal(&cfg)
|
|
|
|
s, p, err := sc.initializeServiceManager()
|
|
if err != nil {
|
|
logger.Error().Err(err).Msg("Failed to initialize service manager")
|
|
return err
|
|
}
|
|
|
|
p.cfg = &cfg
|
|
if iface == "" {
|
|
iface = "auto"
|
|
}
|
|
p.preRun()
|
|
if ir := runningIface(s); ir != nil {
|
|
p.runningIface = ir.Name
|
|
p.requiredMultiNICsConfig = ir.All
|
|
}
|
|
|
|
initInteractiveLogging()
|
|
|
|
status, err := s.Status()
|
|
if errors.Is(err, service.ErrNotInstalled) {
|
|
logger.Warn().Msg("Service not installed")
|
|
return nil
|
|
}
|
|
if status == service.StatusStopped {
|
|
logger.Warn().Msg("Service is already stopped")
|
|
return nil
|
|
}
|
|
|
|
if err := checkDeactivationPin(s, nil); isCheckDeactivationPinErr(err) {
|
|
logger.Error().Msg("Deactivation pin check failed")
|
|
os.Exit(deactivationPinInvalidExitCode)
|
|
}
|
|
|
|
logger.Debug().Msg("Stopping service")
|
|
if doTasks([]task{{s.Stop, true, "Stop"}}) {
|
|
logger.Notice().Msg("Service stopped")
|
|
} else {
|
|
logger.Error().Msg("Service stop failed")
|
|
}
|
|
|
|
logger.Debug().Msg("Service stop command completed")
|
|
return nil
|
|
}
|