mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-27 12:52:27 +02:00
d81042089b
- Move ServiceCommand.Start to commands_service_start.go - Move ServiceCommand.Stop to commands_service_stop.go - Move ServiceCommand.Restart to commands_service_restart.go - Move ServiceCommand.Reload to commands_service_reload.go - Move ServiceCommand.Status to commands_service_status.go - Move ServiceCommand.Uninstall to commands_service_uninstall.go - Move createStartCommands to commands_service_start.go - Clean up imports in commands_service.go - Remove all method implementations from main service file This refactoring improves code organization by: - Separating concerns into focused files - Making navigation easier for developers - Reducing merge conflicts between different commands - Following consistent modular patterns - Reducing commands_service.go from ~650 lines to ~50 lines Each method is now co-located with its related functionality, making the codebase more maintainable and easier to understand.
44 lines
961 B
Go
44 lines
961 B
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 {
|
|
s := sc.serviceManager.svc
|
|
p := sc.serviceManager.prog
|
|
readConfig(false)
|
|
v.Unmarshal(&cfg)
|
|
p.cfg = &cfg
|
|
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) {
|
|
mainLog.Load().Warn().Msg("service not installed")
|
|
return nil
|
|
}
|
|
if status == service.StatusStopped {
|
|
mainLog.Load().Warn().Msg("service is already stopped")
|
|
return nil
|
|
}
|
|
|
|
if err := checkDeactivationPin(s, nil); isCheckDeactivationPinErr(err) {
|
|
os.Exit(deactivationPinInvalidExitCode)
|
|
}
|
|
if doTasks([]task{{s.Stop, true, "Stop"}}) {
|
|
mainLog.Load().Notice().Msg("Service stopped")
|
|
}
|
|
return nil
|
|
}
|