// NewUpstartCommander returns upstart service commander func NewUpstartCommander() *SvcCommander { return &SvcCommander{ Start: command.NewCommand(serviceCmd, []string{"start"}...), Stop: command.NewCommand(serviceCmd, []string{"stop"}...), Status: command.NewCommand(serviceCmd, []string{"status"}...), } }
// NewBaseCommander returns basic service commander func NewBaseCommander(ctlCmd string) *Commander { return &Commander{ StartCmd: command.NewCommand(ctlCmd, []string{}...), StopCmd: command.NewCommand(ctlCmd, []string{}...), StatusCmd: command.NewCommand(ctlCmd, []string{}...), } }
// NewPipManager returns pip Manager or fails with error func NewPipManager() Manager { return &pipManager{ baseManager: baseManager{ ListPkgsCmd: command.NewCommand(pip, pipListPkgsCmdArgs...), QueryPkgCmd: command.NewCommand(pip, pipQueryPkgCmdArgs...), parser: NewPipParser(), pkgType: "pip", }, } }
// NewGemManager returns gem Manager or fails with error func NewGemManager() Manager { return &gemManager{ baseManager: baseManager{ ListPkgsCmd: command.NewCommand(gem, gemListPkgsCmdArgs...), QueryPkgCmd: command.NewCommand(gem, gemQueryPkgCmdArgs...), parser: NewGemParser(), pkgType: "gem", }, } }
// NewApkManager returns apk Manager or fails with error func NewApkManager() Manager { return &apkManager{ baseManager: baseManager{ ListPkgsCmd: command.NewCommand(apk, apkListPkgsCmdArgs...), QueryPkgCmd: command.NewCommand(apk, apkQueryPkgCmdArgs...), parser: NewApkParser(), pkgType: "apk", }, } }
// NewYumManager returns yum Manager or fails with error func NewYumManager() Manager { return &yumManager{ baseManager: baseManager{ ListPkgsCmd: command.NewCommand(rpm, rpmListPkgsCmdArgs...), QueryPkgCmd: command.NewCommand(rpm, rpmQueryPkgCmdArgs...), parser: NewYumParser(), pkgType: "yum", }, } }
// NewAptManager returns apt Manager or fails with error func NewAptManager() Manager { return &aptManager{ baseManager: baseManager{ ListPkgsCmd: command.NewCommand(dpkg, dpkgListPkgsCmdArgs...), QueryPkgCmd: command.NewCommand(dpkg, dpkgQueryPkgCmdArgs...), parser: NewAptParser(), pkgType: "apt", }, } }
func TestBuildCmd(t *testing.T) { cmd := "foo" args := []string{"bar"} actCmd := BuildCmd(cmd, args...) expCmd := command.NewCommand(cmd, args...) assert.Exactly(t, expCmd, actCmd) }
// Stop stops systemd service. It returns error if the service fails to be stopped func (sm *SystemdInit) Stop(svcName string) error { stopCmd := command.NewCommand(systemctl, []string{"stop", svcName + ".service"}...) _, err := stopCmd.RunCombined() if err != nil { return err } return nil }
// Status queries status of systemd service and returns it. // It returns error if the status of the queried service could not be determined func (sm *SystemdInit) Status(svcName string) (service.Status, error) { statusCmd := command.NewCommand(systemctl, []string{"status", svcName + ".service"}...) status, err := statusCmd.RunCombined() if err != nil { return service.Unknown, err } switch { case strings.Contains(status, "active (running)"): return service.Running, nil case strings.Contains(status, "inactive (stopped)"): return service.Stopped, nil } return service.Unknown, fmt.Errorf("Unable to determine %s status", svcName) }
// BuildCmd builds Command from cmd name and arguments func BuildCmd(cmd string, args ...string) *command.Command { return command.NewCommand(cmd, args...) }
// NewGemCommander returns gem command manager func NewGemCommander() *PkgCommander { return &PkgCommander{ ListPkgs: command.NewCommand(gem, gemListPkgsArgs...), QueryPkg: command.NewCommand(gem, gemQueryPkgArgs...), } }
// NewPipCommander returns pip command manager func NewPipCommander() *PkgCommander { return &PkgCommander{ ListPkgs: command.NewCommand(pip, pipListPkgsArgs...), QueryPkg: command.NewCommand(pip, pipQueryPkgArgs...), } }
// NewYumCommander returns yum command manager func NewYumCommander() *PkgCommander { return &PkgCommander{ ListPkgs: command.NewCommand(rpm, rpmListPkgsArgs...), QueryPkg: command.NewCommand(rpm, rpmQueryPkgArgs...), } }
// NewApkCommander returns aptitude command manager func NewApkCommander() *PkgCommander { return &PkgCommander{ ListPkgs: command.NewCommand(apk, apkListPkgsArgs...), QueryPkg: command.NewCommand(apk, apkQueryPkgArgs...), } }
// NewAptCommander returns aptitude command manager func NewAptCommander() *PkgCommander { return &PkgCommander{ ListPkgs: command.NewCommand(dpkg, dpkgListPkgsArgs...), QueryPkg: command.NewCommand(dpkg, dpkgQueryPkgArgs...), } }