Files
ctrld/cmd/cli/commands_service_status.go
Cuong Manh Le 5d87bd07ca feat: enhance logging in service commands with consistent logger usage
- 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.
2025-10-09 18:47:18 +07:00

42 lines
885 B
Go

package cli
import (
"os"
"github.com/kardianos/service"
"github.com/spf13/cobra"
)
// Status implements the logic from cmdStatus.Run
func (sc *ServiceCommand) Status(cmd *cobra.Command, args []string) error {
logger := mainLog.Load()
logger.Debug().Msg("Service status command started")
s, _, err := sc.initializeServiceManager()
if err != nil {
logger.Error().Err(err).Msg("Failed to initialize service manager")
return err
}
status, err := s.Status()
if err != nil {
logger.Error().Msg(err.Error())
os.Exit(1)
}
switch status {
case service.StatusUnknown:
logger.Notice().Msg("Unknown status")
os.Exit(2)
case service.StatusRunning:
logger.Notice().Msg("Service is running")
os.Exit(0)
case service.StatusStopped:
logger.Notice().Msg("Service is stopped")
os.Exit(1)
}
logger.Debug().Msg("Service status command completed")
return nil
}