mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
- Split initializeServiceManager into two methods: * initializeServiceManager(): Simple method using default configuration * initializeServiceManagerWithServiceConfig(): Advanced method for custom config - Simplify NewServiceCommand() to return *ServiceCommand without error - Update all service command methods to use appropriate initialization: * Start: Uses initializeServiceManagerWithServiceConfig() for custom args * Stop/Restart/Reload/Status/Uninstall: Use simple initializeServiceManager() - Remove direct access to sc.serviceManager.svc/prog in favor of lazy initialization - Improve separation of concerns and reduce code duplication
34 lines
707 B
Go
34 lines
707 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 {
|
|
s, _, err := sc.initializeServiceManager()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
status, err := s.Status()
|
|
if err != nil {
|
|
mainLog.Load().Error().Msg(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
switch status {
|
|
case service.StatusUnknown:
|
|
mainLog.Load().Notice().Msg("Unknown status")
|
|
os.Exit(2)
|
|
case service.StatusRunning:
|
|
mainLog.Load().Notice().Msg("Service is running")
|
|
os.Exit(0)
|
|
case service.StatusStopped:
|
|
mainLog.Load().Notice().Msg("Service is stopped")
|
|
os.Exit(1)
|
|
}
|
|
return nil
|
|
}
|