mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-29 01:18:48 +02:00
refactor: improve ServiceManager initialization with cleaner API
- 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
This commit is contained in:
@@ -12,7 +12,11 @@ import (
|
||||
|
||||
// Reload implements the logic from cmdReload.Run
|
||||
func (sc *ServiceCommand) Reload(cmd *cobra.Command, args []string) error {
|
||||
status, err := sc.serviceManager.svc.Status()
|
||||
s, _, err := sc.initializeServiceManager()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
status, err := s.Status()
|
||||
if errors.Is(err, service.ErrNotInstalled) {
|
||||
mainLog.Load().Warn().Msg("service not installed")
|
||||
return nil
|
||||
@@ -37,7 +41,7 @@ func (sc *ServiceCommand) Reload(cmd *cobra.Command, args []string) error {
|
||||
case http.StatusCreated:
|
||||
mainLog.Load().Warn().Msg("Service was reloaded, but new config requires service restart.")
|
||||
mainLog.Load().Warn().Msg("Restarting service")
|
||||
if _, err := sc.serviceManager.svc.Status(); errors.Is(err, service.ErrNotInstalled) {
|
||||
if _, err := s.Status(); errors.Is(err, service.ErrNotInstalled) {
|
||||
mainLog.Load().Warn().Msg("Service not installed")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user