func (s *ServiceInit) Running() (interface{}, error) { cmd := util.NewCommand("service", s.service, "status") cmd.Run() if cmd.Status == 0 { return true, nil } return false, nil }
func (s *ServiceUpstart) Running() (interface{}, error) { cmd := util.NewCommand("service", s.service, "status") cmd.Run() out := cmd.Stdout.String() if cmd.Status == 0 && (strings.Contains(out, "running") || strings.Contains(out, "online")) { return true, nil } return false, nil }
func (s *ServiceInit) Running() (bool, error) { if invalidService(s.service) { return false, nil } cmd := util.NewCommand("service", s.service, "status") cmd.Run() if cmd.Status == 0 { return true, cmd.Err } return false, nil }
func (p *DebPackage) setup() { if p.loaded { return } p.loaded = true cmd := util.NewCommand("dpkg-query", "-f", "${Version}\n", "-W", p.name) if err := cmd.Run(); err != nil { return } p.installed = true p.versions = strings.Split(strings.TrimSpace(cmd.Stdout.String()), "\n") }
func (p *RpmPackage) setup() { if p.loaded { return } p.loaded = true cmd := util.NewCommand("rpm", "-q", "--nosignature", "--nohdrchk", "--nodigest", "--qf", "%{VERSION}\n", p.name) if err := cmd.Run(); err != nil { return } p.installed = true p.versions = strings.Split(strings.TrimSpace(cmd.Stdout.String()), "\n") }
func (c *Command) setup() { if c.loaded { return } c.loaded = true //cmd_array := strings.Fields(c.command) cmd := util.NewCommand("sh", "-c", c.command) cmd.Run() c.exitStatus = strconv.Itoa(cmd.Status) c.stdout = bytes.NewReader(cmd.Stdout.Bytes()) c.stderr = bytes.NewReader(cmd.Stderr.Bytes()) }
func (p *PacmanPackage) setup() { if p.loaded { return } p.loaded = true // TODO: extract versions cmd := util.NewCommand("pacman", "-Q", "--color", "never", "--noconfirm", p.name) if err := cmd.Run(); err != nil { return } p.installed = true // the output format is "pkgname version\n", so if we split the string on // whitespace, the version is the second item. p.versions = []string{strings.Fields(cmd.Stdout.String())[1]} }
func (c *DefCommand) setup() error { if c.loaded { return c.err } c.loaded = true cmd := util.NewCommand("sh", "-c", c.command) err := cmd.Run() // We don't care about ExitError since it's covered by status if _, ok := err.(*exec.ExitError); !ok { c.err = err } c.exitStatus = strconv.Itoa(cmd.Status) c.stdout = bytes.NewReader(cmd.Stdout.Bytes()) c.stderr = bytes.NewReader(cmd.Stderr.Bytes()) return c.err }
func (p *DebPackage) setup() { if p.loaded { return } p.loaded = true cmd := util.NewCommand("dpkg-query", "-f", "${Status} ${Version}\n", "-W", p.name) if err := cmd.Run(); err != nil { return } for _, l := range strings.Split(strings.TrimSpace(cmd.Stdout.String()), "\n") { if !(strings.HasPrefix(l, "install ok installed") || strings.HasPrefix(l, "hold ok installed")) { continue } ver := strings.Fields(l)[3] p.versions = append(p.versions, ver) } if len(p.versions) > 0 { p.installed = true } }
func (p *AlpinePackage) setup() { if p.loaded { return } p.loaded = true cmd := util.NewCommand("apk", "version", p.name) if err := cmd.Run(); err != nil { return } for _, l := range strings.Split(strings.TrimSpace(cmd.Stdout.String()), "\n") { if strings.HasPrefix(l, "Installed:") || strings.HasPrefix(l, "WARNING") { continue } ver := strings.TrimPrefix(strings.Fields(l)[0], p.name+"-") p.versions = append(p.versions, ver) } if len(p.versions) > 0 { p.installed = true } }