// actually do the redis cmds
162026
func (rc *Redis) do(commandName string, args ...interface{}) (reply interface{}, err error) {
	if rc.p == nil {
		rc.connectInit()
	}
	c := rc.p.Get()
	defer c.Close()

	return c.Do(commandName, args...)
}
323699
func (l *Client) Do(r *http.Request, response, data interface{}) error {
	// make the request

	res, err := l.client.Do(r)
	if err != nil {
		return err
	}
	defer res.Body.Close()

	// get the response
	b, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return err
	}

	// if we have some struct to unmarshal body into, do that and return
	if response != nil {
		err = buildRespJSON(b, response, data)
		if err != nil {
			return err
		}
		switch rt := response.(type) {
		case *ApiResp:
			// if we have an invalid response code error out
			if res.StatusCode >= 301 {
				return fmt.Errorf(rt.Message)
			}
		}
	}

	// if we have an invalid response code error out
	if res.StatusCode >= 301 {
		return fmt.Errorf("Received non-successful response: %d", res.StatusCode)
	}

	return nil
}
499339
func (s *Service) InstallCommands() ([]string, error) {
	if s.NoConf() {
		return nil, s.errorf(nil, "missing conf")
	}

	name := s.Name()
	dirname := s.DirName

	data, err := s.serialize()
	if err != nil {
		return nil, errors.Trace(err)
	}

	cmdList := []string{
		cmds.mkdirs(dirname),
	}
	if s.Script != nil {
		scriptName := renderer.Base(renderer.ScriptFilename("exec-start", ""))
		cmdList = append(cmdList, []string{
			// TODO(ericsnow) Use the renderer here.
			cmds.writeFile(scriptName, dirname, s.Script),
			cmds.chmod(scriptName, dirname, 0755),
		}...)
	}
	cmdList = append(cmdList, []string{
		cmds.writeConf(name, dirname, data),
		cmds.link(name, dirname),
		cmds.reload(),
		cmds.enableLinked(name, dirname),
	}...)
	return cmdList, nil
}
167307
func (r *cmdRun) done(err error) int {
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		if err, ok := err.(*exitCode); ok {
			return err.code
		}
		return ecOtherError
	}
	return 0
}
1140870
func cmd(dir string, arg ...string) (string, error) {
	c := exec.Command(binary, arg...)
	c.Dir = dir

	output, err := c.CombinedOutput()
	if err != nil {
		return "", fmt.Errorf("running `%s %s` failed with output: %s\nerror: %v", c.Path, strings.Join(c.Args, " "), output, err)
	}

	return string(output), nil
}
1306825
func Cmd() *cobra.Command {
	nodeCmd.AddCommand(startCmd())
	nodeCmd.AddCommand(statusCmd())

	return nodeCmd
}
1135991
func (s *Service) InstallCommands() ([]string, error) {
	cmd := fmt.Sprintf(serviceCreateCommandTemplate[1:],
		renderer.Quote(s.Service.Name),
		renderer.Quote(s.Service.Conf.Desc),
		renderer.Quote(s.Service.Conf.ExecStart),
		renderer.Quote(s.Service.Name),
		renderer.Quote(s.Service.Conf.Desc),
		renderer.Quote(s.Service.Conf.ExecStart),
		renderer.Quote(s.Service.Name),
		renderer.Quote(s.Service.Name),
	)
	return strings.Split(cmd, "\n"), nil
}
1005517
func (s *Service) StartCommands() ([]string, error) {
	cmd := fmt.Sprintf(`Start-Service %s`, renderer.Quote(s.Service.Name))
	return []string{cmd}, nil
}
1005489
func (s *Service) InstallCommands() ([]string, error) {
	conf, err := s.render()
	if err != nil {
		return nil, err
	}
	cmd := fmt.Sprintf("cat > %s << 'EOF'\n%sEOF\n", s.confPath(), conf)
	return []string{cmd}, nil
}
490595
func Redis(ctx context.Context) (*redis.Client, bool) {
	key := redisDB("default")
	db, ok := ctx.Value(key).(*redis.Client)
	return db, ok
}
62404
func NewSearchCmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "search",
		Short: "Search a RETS server",
		Run:   search,
	}
	cmd.Flags().String(searchFileFlag, "", "Search parameters file location")
	return cmd
}
793073
func (s *Service) StartCommands() ([]string, error) {
	// TODO(ericsnow) Add clarification about why transient services are not started.
	if s.Service.Conf.Transient {
		return nil, nil
	}
	return []string{"start " + s.Service.Name}, nil
}
502900
func (ix *Reindexer) Do() (*ReindexerResponse, error) {
	if ix.sourceClient == nil {
		return nil, errors.New("no source client")
	}
	if ix.sourceIndex == "" {
		return nil, errors.New("no source index")
	}
	if ix.targetClient == nil {
		ix.targetClient = ix.sourceClient
	}
	if ix.scanFields == nil {
		ix.scanFields = []string{"_source", "_parent", "_routing"}
	}
	if ix.bulkSize <= 0 {
		ix.bulkSize = 500
	}
	if ix.scroll == "" {
		ix.scroll = "5m"
	}

	// Count total to report progress (if necessary)
	var err error
	var current, total int64
	if ix.progress != nil {
		total, err = ix.count()
		if err != nil {
			return nil, err
		}
	}

	// Prepare scan and scroll to iterate through the source index
	scanner := ix.sourceClient.Scan(ix.sourceIndex).Scroll(ix.scroll).Fields(ix.scanFields...)
	if ix.query != nil {
		scanner = scanner.Query(ix.query)
	}
	if ix.size > 0 {
		scanner = scanner.Size(ix.size)
	}
	cursor, err := scanner.Do()

	bulk := ix.targetClient.Bulk()

	ret := &ReindexerResponse{
		Errors: make([]*BulkResponseItem, 0),
	}

	// Main loop iterates through the source index and bulk indexes into target.
	for {
		docs, err := cursor.Next()
		if err == EOS {
			break
		}
		if err != nil {
			return ret, err
		}

		if docs.TotalHits() > 0 {
			for _, hit := range docs.Hits.Hits {
				if ix.progress != nil {
					current++
					ix.progress(current, total)
				}

				err := ix.reindexerFunc(hit, bulk)
				if err != nil {
					return ret, err
				}

				if bulk.NumberOfActions() >= ix.bulkSize {
					bulk, err = ix.commit(bulk, ret)
					if err != nil {
						return ret, err
					}
				}
			}
		}
	}

	// Final flush
	if bulk.NumberOfActions() > 0 {
		bulk, err = ix.commit(bulk, ret)
		if err != nil {
			return ret, err
		}
		bulk = nil
	}

	return ret, nil
}
1309248
func (cniApp *cniAppInfo) processCmd() int {
	urlDict := map[string]string{cniapi.CniCmdAdd: cniApp.serverURL + cniapi.MesosNwIntfAdd,
		cniapi.CniCmdDel: cniApp.serverURL + cniapi.MesosNwIntfDel}

	jsonReq, err := json.Marshal(cniApp.cniMesosAttr)
	if err != nil {
		return cniApp.sendCniErrorResp("failed to convert Mesos attr. to JSON format :" + err.Error())
	}

	jsonBuf := bytes.NewBuffer(jsonReq)
	url := urlDict[cniApp.cniCmd]
	cniLog.Infof("process cni cmd: %s url: %s", cniApp.cniCmd, url)
	return cniApp.handleHTTP(url, jsonBuf)
}
657446
func (c *Ring) Do(args ...interface{}) *Cmd {
	cmd := NewCmd(args...)
	c.Process(cmd)
	return cmd
}
548788
func deleteCommands(dp models.DeviceProfile, w http.ResponseWriter) error {
	for _, command := range dp.CoreCommands {
		err := dbClient.DeleteCommandById(command.Id)
		if err != nil {
			http.Error(w, err.Error(), http.StatusServiceUnavailable)
			return err
		}
	}

	return nil
}
1017772
func RunCommandInDirWithEnvsAndReturnExitCode(envs []string, dir, name string, args ...string) (int, error) {
	cmd := exec.Command(name, args...)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	if dir != "" {
		cmd.Dir = dir
	}
	if len(envs) > 0 {
		cmd.Env = envs
	}

	return RunCmdAndReturnExitCode(cmd)
}